public static void maybeInstall(final StreamSet set) { maybeInstall(); register(set); }
private static void ensureRegistered() { ensureInstalled(); if (!isRegistered()) { throw new IllegalStateException(MessageFormat.format("Not registered: {0}", Thread.currentThread())); } }
/** * Get the current stream registration. */ private static StreamRegistration registration(final boolean required) { if (required) { ensureRegistered(); } return registrations.get(); }
public static synchronized void maybeInstall() { if (!isInstalled()) { install(); } }
final IO io = shell.getIo(); StreamJack.maybeInstall(io.streams); StreamJack.deregister(); ShellHolder.set(lastShell); Thread.currentThread().setContextClassLoader(cl);
private synchronized void open() throws Exception { log.debug("Opening"); StreamJack.maybeInstall(); // Customize the shell branding.customize(this); opened = true; log.debug("Opened"); // Do this after we are marked as opened loadProfileScripts(); }
/** * Register streams for the current thread. */ public static void register(final InputStream in, final PrintStream out, final PrintStream err) { ensureInstalled(); if (log.isTraceEnabled()) { log.trace("Registering: {} -> {}, {}, {}", new Object[] { Thread.currentThread(), in, out, err }); } StreamRegistration prev = registration(false); StreamSet set = new StreamSet(in, out, err); StreamRegistration next = new StreamRegistration(set, prev); registrations.set(next); }
/** * Check if there are streams registered for the current thread. */ public static boolean isRegistered() { return registration(false) != null; }
/** * Register streams for the current thread. */ public static void register(final StreamSet set) { assert set != null; register(set.in, set.out, set.err); }
private PrintStream get() { return current().getOutput(type); }
private static void ensureInstalled() { if (!isInstalled()) { throw new IllegalStateException("Not installed"); } }
/** * Uninstall the hijacker. */ public static synchronized void uninstall() { ensureInstalled(); System.setIn(previous.in); System.setOut(previous.out); System.setErr(previous.err); previous = null; installed = false; log.debug("Uninstalled"); }
StreamJack.maybeInstall(io.streams);
/** * Returns the currently registered streams. */ public static StreamSet current() { StreamRegistration reg = registration(false); if (reg == null) { return previous; } return reg.streams; }
/** * Register combined streams for the current thread. */ public static void register(final InputStream in, final PrintStream out) { register(in, out, out); }
private InputStream get() { return current().getInput(); }
/** * Re-register streams for the current thread, and restore the previous if any. */ public static void deregister() { StreamRegistration cur = registration(true); registrations.set(cur.previous); if (log.isTraceEnabled()) { log.trace("De-registered: {}, using streams: {}", Thread.currentThread(), cur.previous == null ? "null" : cur.previous.streams); } }