List of usage examples for java.io OutputStream OutputStream
OutputStream
From source file:au.org.ala.delta.translation.PrintFile.java
public PrintFile(final StringBuilder buffer) { _output = new PrintStream(new OutputStream() { @Override/*from w ww.jav a 2s .c o m*/ public void write(int b) throws IOException { buffer.append((char) b); } }); initialise(); }
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Will duplicate the output-streams to the specified Files. * This will catch everything that is sent to sout and serr (even stuff not logged via SimpleLog). * * @param std/*www . j a v a 2s.c o m*/ * The file to use for System.out logging, or null to not LOG System.out to a file * @param err * The file to use for System.err logging, or null to not LOG System.err to a file * @throws java.io.IOException * If an IO error is encountered while dealing with the file. Most likely * to be caused by a lack of permissions when creating the log folders or files. */ @SuppressWarnings("ResultOfMethodCallIgnored") public static void addFileLogs(File std, File err) throws IOException { if (std != null) { if (origStd == null) origStd = System.out; if (!std.getAbsoluteFile().getParentFile().exists()) { std.getAbsoluteFile().getParentFile().mkdirs(); } if (!std.exists()) { std.createNewFile(); } FileOutputStream fOut = new FileOutputStream(std, true); System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origStd.write(b); fOut.write(b); } })); if (stdOut != null) stdOut.close(); stdOut = fOut; } else if (origStd != null) { System.setOut(origStd); stdOut.close(); origStd = null; } if (err != null) { if (origErr == null) origErr = System.err; if (!err.getAbsoluteFile().getParentFile().exists()) { err.getAbsoluteFile().getParentFile().mkdirs(); } if (!err.exists()) { err.createNewFile(); } FileOutputStream fOut = new FileOutputStream(err, true); System.setErr(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origErr.write(b); fOut.write(b); } })); if (errOut != null) errOut.close(); errOut = fOut; } else if (origErr != null) { System.setErr(origErr); errOut.close(); origErr = null; } }
From source file:org.jenkinsci.plugins.dockerprovisioner.TeeSpongeTaskListener.java
public TeeSpongeTaskListener(TaskListener delegate, File deferredFile) { this.delegate = delegate; this.deferredFile = deferredFile; final OutputStream base = delegate.getLogger(); unclaimed = newLog();/*from www. j a v a 2 s . c om*/ side = unclaimed; final OutputStream tee = new OutputStream() { public void write(int b) throws IOException { base.write(b); synchronized (lock()) { side.write(b); } } public void write(byte b[], int off, int len) throws IOException { base.write(b, off, len); synchronized (lock()) { side.write(b, off, len); } } public void flush() throws IOException { base.flush(); synchronized (lock()) { side.flush(); } } public void close() throws IOException { base.close(); synchronized (lock()) { side.close(); } } }; logger = new PrintStream(tee); }
From source file:com.github.jessemull.microflexinteger.stat.GeometricMeanTest.java
/** * Generates random objects and numbers for testing. *//* ww w. j a va 2 s . c o m*/ @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } for (int j = 0; j < array.length; j++) { Plate plate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate1-" + j); array[j] = plate; } for (int j = 0; j < arrayIndices.length; j++) { Plate plateIndices = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, lengthIndices, "Plate1-" + j); arrayIndices[j] = plateIndices; } }
From source file:com.github.jessemull.microflexdouble.stat.GeometricMeanTest.java
/** * Generates random objects and numbers for testing. *///from w w w . j av a 2 s. c o m @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } for (int j = 0; j < array.length; j++) { Plate plate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate1-" + j); array[j] = plate; } for (int j = 0; j < arrayIndices.length; j++) { Plate plateIndices = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, lengthIndices, "Plate1-" + j); arrayIndices[j] = plateIndices; } }
From source file:org.jboss.as.test.integration.security.loginmodules.usersroles.UsersRolesLoginModuleTestCase1.java
/** * Base method to create a {@link org.jboss.shrinkwrap.api.spec.WebArchive} * * @param name Name of the war file * @param servletClass a class that is the servlet * @param webxml {@link java.net.URL} to the web.xml. This can be null * @return//from w ww. ja v a 2s .c o m */ public static WebArchive create(String name, Class<?> servletClass, URL webxml) { WebArchive war = ShrinkWrap.create(WebArchive.class, name); war.addClass(servletClass); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); war.addAsWebInfResource(tccl.getResource("users-roles-login-module.war/jboss-web.xml"), "jboss-web.xml"); war.addClass(UsersRolesLoginModule.class); war.addClass(UnsecuredEJB.class); war.addClass(UnsecuredEJBImpl.class); if (webxml != null) { war.setWebXML(webxml); } OutputStream os = new OutputStream() { StringBuilder builder = new StringBuilder(); @Override public void write(int b) throws IOException { builder.append((char) b); } public String toString() { return builder.toString(); } }; war.writeTo(os, Formatters.VERBOSE); return war; }
From source file:com.github.jessemull.microflex.stat.statdouble.GeometricMeanDoubleTest.java
/** * Generates random objects and numbers for testing. *///from ww w . j a v a2 s . c o m @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } for (int j = 0; j < array.length; j++) { PlateDouble plate = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, length, "Plate1-" + j); array[j] = plate; } for (int j = 0; j < arrayIndices.length; j++) { PlateDouble plateIndices = RandomUtil.randomPlateDouble(rows, columns, minValue, maxValue, lengthIndices, "Plate1-" + j); arrayIndices[j] = plateIndices; } }
From source file:com.github.jessemull.microflex.stat.statinteger.GeometricMeanIntegerTest.java
/** * Generates random objects and numbers for testing. *//*from w ww. j a v a 2s .c om*/ @BeforeClass public static void setUp() { if (error) { System.setErr(new PrintStream(new OutputStream() { public void write(int x) { } })); } for (int j = 0; j < array.length; j++) { PlateInteger plate = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, length, "Plate1-" + j); array[j] = plate; } for (int j = 0; j < arrayIndices.length; j++) { PlateInteger plateIndices = RandomUtil.randomPlateInteger(rows, columns, minValue, maxValue, lengthIndices, "Plate1-" + j); arrayIndices[j] = plateIndices; } }
From source file:org.openqa.selenium.server.browserlaunchers.AsyncExecute.java
/** * Copied from spawn, but actually returns the Process, instead of void * @return the spawned process handle//from w w w . jav a 2 s . com */ public Process asyncSpawn() throws IOException { if (!environmentBuilder.isEmpty()) { setActualExecuteEnvironment(); } if (workingDirectory != null && !workingDirectory.exists()) { throw new BuildException(workingDirectory + " doesn't exist."); } final Process process = launch(project, getCommandline(), getEnvironment(), workingDirectory, useVMLauncher); if (Os.isFamily("windows")) { AsyncExecute.sleepTight(1000); } OutputStream dummyOut = new OutputStream() { public void write(int b) throws IOException { } }; ExecuteStreamHandler streamHandler = new PumpStreamHandler(dummyOut); streamHandler.setProcessErrorStream(process.getErrorStream()); streamHandler.setProcessOutputStream(process.getInputStream()); streamHandler.start(); project.log("spawned process " + process.toString(), Project.MSG_VERBOSE); return process; }
From source file:hudson.gridmaven.SplittableBuildListener.java
public SplittableBuildListener(BuildListener core) { this.core = core; final OutputStream base = core.getLogger(); final OutputStream tee = new OutputStream() { public void write(int b) throws IOException { base.write(b);/*from www . jav a2 s . c o m*/ synchronized (lock()) { side.write(b); } } public void write(byte b[], int off, int len) throws IOException { base.write(b, off, len); synchronized (lock()) { side.write(b, off, len); } } public void flush() throws IOException { base.flush(); synchronized (lock()) { side.flush(); } } public void close() throws IOException { base.close(); synchronized (lock()) { side.close(); } } }; logger = new PrintStream(new MarkFindingOutputStream(tee) { @Override protected void onMarkFound() { synchronized (markCountLock) { markCount++; markCountLock.notifyAll(); } } }); }