List of usage examples for java.io OutputStream OutputStream
OutputStream
From source file:sapience.features.streams.kml.TestEasy.java
public void writeEasy() throws IOException { OutputStream os = new OutputStream() { StringBuffer sb = new StringBuffer(); @Override// ww w . j ava 2 s .c o m public void write(int b) throws IOException { sb.append((char) b); } public String toString() { return sb.toString(); } }; streams.write(res, os); String expected = IOUtils.toString(this.getClass().getResourceAsStream(out)); String actual = os.toString(); System.out.println(expected.trim()); System.out.println(actual.trim()); }
From source file:com.trsst.client.MultiPartRequestEntity.java
public MultiPartRequestEntity(Base base, byte[][] content, String[] contentId, String[] contentType) { this.base = base; this.content = content; this.contentId = contentId; this.contentType = contentType; this.boundary = boundary != null ? boundary : String.valueOf(System.currentTimeMillis()); try {/*from w ww.j av a 2 s. c o m*/ // dummy output stream to count the content length contentLength = 0; writeRequest(new OutputStream() { @Override public void write(int b) { contentLength++; } @Override public void write(byte[] b, int off, int len) { contentLength += len; } }); } catch (IOException e) { this.contentLength = -1; log.error("Unexpected error while determining content length"); } log.debug("MultiPartRequestEntity: contentLength: " + contentLength); }
From source file:ch.cyberduck.core.http.DelayedHttpEntity.java
public void writeTo(final OutputStream out) throws IOException { try {/*from www . j a v a 2s . c o m*/ stream = new OutputStream() { @Override public void write(final byte[] b, final int off, final int len) throws IOException { out.write(b, off, len); } @Override public void write(final int b) throws IOException { out.write(b); } @Override public void write(final byte[] b) throws IOException { out.write(b); } @Override public void close() throws IOException { try { super.close(); } finally { // Signal finished writing to stream exit.countDown(); } } }; } finally { entry.countDown(); } // Wait for signal when content has been written to the pipe try { exit.await(); } catch (InterruptedException e) { log.error(String.format("Error waiting for exit signal %s", e.getMessage())); throw new IOException(e); } // Entity written to server consumed = true; }
From source file:org.drugis.addis.gui.GUIFactory.java
public static void suppressErrors(boolean suppress) { if (suppress) { System.setErr(new PrintStream(new OutputStream() { // suppress system.err output public void write(int b) { }//from w w w. ja v a 2 s . co m })); } else { System.setErr(s_errorStream); // reset system.err output } }
From source file:eu.planets_project.pp.plato.services.characterisation.jhove.JHoveExecutor.java
public static OutputStream newOutputStream(final StringBuffer buf) { return new OutputStream() { public synchronized void write(int b) throws IOException { buf.append((byte) b); }/*from w ww .jav a 2 s . co m*/ }; }
From source file:org.datacleaner.cli.MainTest.java
private void useAsSystemOut(StringWriter stringWriter) { OutputStream out = new OutputStream() { @Override//from ww w .ja va 2 s.com public void write(int b) throws IOException { _stringWriter.write(b); } }; System.setOut(new PrintStream(out)); }
From source file:com.telefonica.euro_iaas.sdc.util.HttpsClientTest.java
@Before public void setup() throws KeyManagementException, NoSuchAlgorithmException, IOException { httpsURLConnection = mock(HttpsURLConnection.class); connectionSetup = mock(ConnectionSetup.class); headers.put(HttpsClient.HEADER_AUTH, ""); headers.put(HttpsClient.HEADER_TENNANT, ""); when(connectionSetup.createConnection((URL) anyObject())).thenReturn(httpsURLConnection); String source = "test"; InputStream in = IOUtils.toInputStream(source, "UTF-8"); when(httpsURLConnection.getInputStream()).thenReturn(in); OutputStream os = new OutputStream() { @Override//ww w .j av a 2 s . c om public void write(int b) throws IOException { } }; when(httpsURLConnection.getOutputStream()).thenReturn(os); httpsClient = new HttpsClient(); httpsClient.setConnectionSetup(connectionSetup); }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
/** * Fully disable any output via <tt>System.out</tt>. * Can be useful to disable possible output of third-party libraries. *///w w w.j ava 2 s . co m public static void disableStandardOutput() { System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { // no operations } })); }
From source file:com.filelocker.gui.Events.java
public void make() { // PrintStream oldOut = System.out; PrintStream printStream = new PrintStream(new OutputStream() { @Override//from www . j a v a2 s. c om public void write(byte[] buffer, int offset, int length) throws IOException { final String text = new String(buffer, offset, length); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { vNotificationArea.append(text); } }); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }, 0, 1); } }); System.setOut(printStream); vPasswordField.setEchoChar('#'); vPasswordLabel.setFont(bigFont); vBrowseLabel.setFont(bigFont); vNotificationArea.setVisible(false); vNotificationArea.setEditable(false); vScroller.setVisible(false); vScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); vScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); vPanel = new JPanel(); vPanel.add(vLockButton); vPanel.add(vCloseButton); vFrame.getContentPane().add(BorderLayout.SOUTH, vPanel); vPanel = new JPanel(); vPanel.add(vPasswordLabel); vPanel.add(vPasswordField); vPanel.add(vBrowseLabel); vPanel.add(vBrowseField); vPanel.add(vBrowseButton); vPanel.add(vScroller); // vPanel.setLayout (new BoxLayout (vPanel, BoxLayout.Y_AXIS)); vFrame.getContentPane().add(BorderLayout.CENTER, vPanel); vLockButton.addActionListener(new vLockButton_Click()); vCloseButton.addActionListener(new vCloseButton_Click()); vBrowseButton.addActionListener(new vBrowseButton_Click()); }
From source file:org.apache.oodt.cas.filemgr.cli.action.DumpMetadataCliAction.java
@Override public void execute(final ActionMessagePrinter printer) throws CmdLineActionException { try {/*from w w w .j ava2s.c o m*/ Validate.notNull(productId, "Must specify productId"); Product product = getClient().getProductById(productId); if (product == null) { throw new Exception("FileManager returned null product"); } Metadata metadata = getClient().getMetadata(product); if (metadata == null) { throw new Exception("FileManager returned null metadata"); } if (outputDir != null) { if (outputDir.exists()) { XMLUtils.writeXmlFile(new SerializableMetadata(metadata).toXML(), new File(outputDir.getAbsoluteFile(), generateFilename(metadata)).getAbsolutePath()); } else { throw new Exception("Output dir '" + outputDir + "' does not exist"); } } else { OutputStream os = new OutputStream() { private StringBuffer sb = new StringBuffer(""); @Override public void write(int character) throws IOException { sb.append((char) character); } @Override public void close() throws IOException { super.close(); printer.println(sb.toString()); } }; XMLUtils.writeXmlToStream(new SerializableMetadata(metadata).toXML(), os); os.close(); } } catch (Exception e) { throw new CmdLineActionException( "Failed to get metadata for product '" + productId + "' : " + e.getMessage(), e); } }