use of org.apache.commons.io.output.ByteArrayOutputStream in project hudson-2.x by hudson.
the class AnnotatedLargeText method writeHtmlTo.
public long writeHtmlTo(long start, Writer w) throws IOException {
ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, createAnnotator(Stapler.getCurrentRequest()), context, charset);
long r = super.writeLogTo(start, caw);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Cipher sym = Secret.getCipher("AES");
sym.init(Cipher.ENCRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
// send timestamp to prevent a replay attack
oos.writeLong(System.currentTimeMillis());
oos.writeObject(caw.getConsoleAnnotator());
oos.close();
StaplerResponse rsp = Stapler.getCurrentResponse();
if (rsp != null)
rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
} catch (GeneralSecurityException e) {
throw new IOException2(e);
}
return r;
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hudson-2.x by hudson.
the class WindowsServiceLifecycle method restart.
@Override
public void restart() throws IOException, InterruptedException {
File me = getHudsonWar();
File home = me.getParentFile();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener task = new StreamTaskListener(baos);
task.getLogger().println("Restarting a service");
int r = new LocalLauncher(task).launch().cmds(new File(home, "hudson.exe"), "restart").stdout(task).pwd(home).join();
if (r != 0)
throw new IOException(baos.toString());
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project hudson-2.x by hudson.
the class WindowsSlaveInstaller method actionPerformed.
/**
* Called when the install menu is selected
*/
public void actionPerformed(ActionEvent e) {
try {
int r = JOptionPane.showConfirmDialog(dialog, Messages.WindowsSlaveInstaller_ConfirmInstallation(), Messages.WindowsInstallerLink_DisplayName(), OK_CANCEL_OPTION);
if (r != JOptionPane.OK_OPTION)
return;
if (!DotNet.isInstalled(2, 0)) {
JOptionPane.showMessageDialog(dialog, Messages.WindowsSlaveInstaller_DotNetRequired(), Messages.WindowsInstallerLink_DisplayName(), ERROR_MESSAGE);
return;
}
final File dir = new File(rootDir);
if (!dir.exists()) {
JOptionPane.showMessageDialog(dialog, Messages.WindowsSlaveInstaller_RootFsDoesntExist(rootDir), Messages.WindowsInstallerLink_DisplayName(), ERROR_MESSAGE);
return;
}
final File slaveExe = new File(dir, "hudson-slave.exe");
FileUtils.copyURLToFile(getClass().getResource("/windows-service/hudson.exe"), slaveExe);
// write out the descriptor
URL jnlp = new URL(engine.getHudsonUrl(), "computer/" + Util.rawEncode(engine.slaveName) + "/slave-agent.jnlp");
String xml = generateSlaveXml(generateServiceId(rootDir), System.getProperty("java.home") + "\\bin\\java.exe", "-jnlpUrl " + jnlp.toExternalForm());
FileUtils.writeStringToFile(new File(dir, "hudson-slave.xml"), xml, "UTF-8");
// copy slave.jar
URL slaveJar = new URL(engine.getHudsonUrl(), "jnlpJars/remoting.jar");
File dstSlaveJar = new File(dir, "slave.jar").getCanonicalFile();
if (// perhaps slave.jar is already there?
!dstSlaveJar.exists())
FileUtils.copyURLToFile(slaveJar, dstSlaveJar);
// install as a service
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener task = new StreamTaskListener(baos);
r = runElevated(slaveExe, "install", task, dir);
if (r != 0) {
JOptionPane.showMessageDialog(dialog, baos.toString(), "Error", ERROR_MESSAGE);
return;
}
r = JOptionPane.showConfirmDialog(dialog, Messages.WindowsSlaveInstaller_InstallationSuccessful(), Messages.WindowsInstallerLink_DisplayName(), OK_CANCEL_OPTION);
if (r != JOptionPane.OK_OPTION)
return;
// let the service start after we close our connection, to avoid conflicts
Runtime.getRuntime().addShutdownHook(new Thread("service starter") {
public void run() {
try {
StreamTaskListener task = StreamTaskListener.fromStdout();
int r = runElevated(slaveExe, "start", task, dir);
task.getLogger().println(r == 0 ? "Successfully started" : "start service failed. Exit code=" + r);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
System.exit(0);
} catch (Exception t) {
// this runs as a JNLP app, so if we let an exeption go, we'll never find out why it failed
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
JOptionPane.showMessageDialog(dialog, sw.toString(), "Error", ERROR_MESSAGE);
}
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project flink by apache.
the class NFATest method testNFASerialization.
@Test
public void testNFASerialization() throws IOException, ClassNotFoundException {
NFA<Event> nfa = new NFA<>(Event.createTypeSerializer(), 0, false);
State<Event> startingState = new State<>("", State.StateType.Start);
State<Event> startState = new State<>("start", State.StateType.Normal);
State<Event> endState = new State<>("end", State.StateType.Final);
StateTransition<Event> starting2Start = new StateTransition<>(StateTransitionAction.TAKE, startState, new NameFilter("start"));
StateTransition<Event> start2End = new StateTransition<>(StateTransitionAction.TAKE, endState, new NameFilter("end"));
StateTransition<Event> start2Start = new StateTransition<>(StateTransitionAction.IGNORE, startState, null);
startingState.addStateTransition(starting2Start);
startState.addStateTransition(start2End);
startState.addStateTransition(start2Start);
nfa.addState(startingState);
nfa.addState(startState);
nfa.addState(endState);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(nfa);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
@SuppressWarnings("unchecked") NFA<Event> copy = (NFA<Event>) ois.readObject();
assertEquals(nfa, copy);
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project cassandra by apache.
the class MultiResultLoggerTest method delegatesPrintfToAdditionalPrintStreams.
@Test
public void delegatesPrintfToAdditionalPrintStreams() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PrintStream additionalPrintStream = new PrintStream(output, true);
MultiResultLogger underTest = new MultiResultLogger(new PrintStream(NOOP));
underTest.addStream(additionalPrintStream);
underTest.printf("%s %s %s", "one", "two", "three");
assertEquals("one two three", output.toString());
}
Aggregations