List of usage examples for java.io PipedOutputStream PipedOutputStream
public PipedOutputStream(PipedInputStream snk) throws IOException
From source file:mx.ipn.escom.supernaut.nile.logic.CommonBean.java
protected InputStream streamedMarshall() throws IOException { PipedInputStream in = new PipedInputStream(); OutputStream out = new PipedOutputStream(in); JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); gson.toJson(model, modelType, writer); return in;/*from w w w .j a v a 2 s . co m*/ }
From source file:org.apache.axis2.transport.nhttp.util.PipeImpl.java
public PipeImpl() throws IOException { if (useNative) { Pipe pipe = Pipe.open(); source = pipe.source();/*from w w w . j ava2s.com*/ sink = pipe.sink(); } else { PipedInputStream pipedIn = new PipedInputStream(); try { pipedOut = new PipedOutputStream(pipedIn); } catch (IOException e) { e.printStackTrace(); } source = Channels.newChannel(pipedIn); sink = Channels.newChannel(pipedOut); } }
From source file:ee.ioc.cs.vsle.util.Console.java
private Console() { // create all components and add them frame = new JFrame("Java Console"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = new Dimension((screenSize.width / 2), (screenSize.height / 2)); int x = (frameSize.width / 2); int y = (frameSize.height / 2); frame.setBounds(x, y, frameSize.width, frameSize.height); textArea = new JTextArea(); textArea.setEditable(false);//from w w w .j a v a 2 s . c om JButton button = new JButton("clear"); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); frame.getContentPane().add(button, BorderLayout.SOUTH); frame.setVisible(true); frame.addWindowListener(this); button.addActionListener(this); final PipedInputStream pin = new PipedInputStream(); try { PipedOutputStream pout = new PipedOutputStream(pin); System.setOut(new PrintStream(new TeeOutputStream(systemOut, pout), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage()); } final PipedInputStream pin2 = new PipedInputStream(); try { PipedOutputStream pout2 = new PipedOutputStream(pin2); System.setErr(new PrintStream(new TeeOutputStream(systemErr, pout2), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDERR to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDERR to this console\n" + se.getMessage()); } quit = false; // signals the Threads that they should exit sysOutFollower = new StreamFollower(pin, StreamRestorer.SYS_OUT, "Console_out"); sysOutFollower.start(); // sysErrFollower = new StreamFollower(pin2, StreamRestorer.SYS_ERR, "Console_err"); sysErrFollower.start(); }
From source file:com.mycollab.vaadin.resources.StreamDownloadResourceSupportExtDrive.java
@Override public InputStream getStream() { if (resources.size() == 1) { Resource res = resources.iterator().next(); if (!(res instanceof Folder)) { if (res.isExternalResource()) { ExternalResourceService service = ResourceUtils .getExternalResourceService(ResourceUtils.getType(res)); return service.download(ResourceUtils.getExternalDrive(res), res.getPath()); } else { return resourceService.getContentStream(res.getPath()); }//from w w w . java 2 s . co m } } final PipedInputStream inStream = new PipedInputStream(); final PipedOutputStream outStream; try { outStream = new PipedOutputStream(inStream); } catch (IOException ex) { LOG.error("Can not create outstream file", ex); return null; } Thread threadExport = new MyCollabThread(new Runnable() { @Override public void run() { try { ZipOutputStream zipOutStream = new ZipOutputStream(outStream); zipResource(zipOutStream, resources); zipOutStream.close(); outStream.close(); } catch (Exception e) { LOG.error("Error while saving content stream", e); } } }); threadExport.start(); return inStream; }
From source file:de.resol.vbus.LiveInputStreamTest.java
@Test public void testReadHeader() throws Exception { byte[] refPacketBuffer1 = Hex.decodeHex( "aa362335331034430d2a0004080c00671014181c00272024282c00673034383c00274044484c00675054585c00276064686c00677074787c00270004080c0f581014181c0f182024282c0f583034383c0f184044484c0f58" .toCharArray());/*from w w w .ja v a 2s .c o m*/ byte[] refDgramBuffer1 = Hex.decodeHex("aa362335332034433353300332630851".toCharArray()); byte[] refTgramBuffer1 = Hex .decodeHex("aa2211443330772e000c1824303c48000354606c7804101c70472834404c5864707f6c".toCharArray()); byte[] refZeroBuffer1 = Hex.decodeHex("00000000000000000000000000000000".toCharArray()); byte[] refMsbBuffer1 = Hex.decodeHex("80808080808080808080808080808080".toCharArray()); String refPacketId1 = "13_2336_3335_10_4334"; String refDgramId1 = "13_2336_3335_20_4334_0000"; String refTgramId1 = "13_1122_3344_30_77"; PipedInputStream refIs1 = new PipedInputStream(2048); PipedOutputStream refOs1 = new PipedOutputStream(refIs1); int refChannel1 = 0x13; LiveInputStream testIs = new LiveInputStream(refIs1, refChannel1); refOs1.write(refPacketBuffer1); assertEquals(refPacketId1, testIs.readHeader().getId()); refOs1.write(refDgramBuffer1); refOs1.write(refTgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); assertEquals(refTgramId1, testIs.readHeader().getId()); // write a partial header (before protocol version) refOs1.write(refTgramBuffer1); refOs1.write(refDgramBuffer1, 0, 5); assertEquals(refTgramId1, testIs.readHeader().getId()); refOs1.write(refDgramBuffer1, 5, 11); assertEquals(refDgramId1, testIs.readHeader().getId()); // write a broken header (without sync byte) refOs1.write(refDgramBuffer1, 1, 15); refOs1.write(refTgramBuffer1); assertEquals(refTgramId1, testIs.readHeader().getId()); // write unknown version refOs1.write(refDgramBuffer1, 0, 5); refOs1.write(0x05); refOs1.write(refTgramBuffer1); assertEquals(refTgramId1, testIs.readHeader().getId()); // write partial packet (incomplete header) refOs1.write(refDgramBuffer1); refOs1.write(refPacketBuffer1, 0, 9); assertEquals(refDgramId1, testIs.readHeader().getId()); refOs1.write(refPacketBuffer1, 9, refPacketBuffer1.length - 9); assertEquals(refPacketId1, testIs.readHeader().getId()); // write defect packet (header msb) refOs1.write(refPacketBuffer1, 0, 9); refOs1.write(refMsbBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // write defect packet (header checksum) refOs1.write(refPacketBuffer1, 0, 9); refOs1.write(refZeroBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // write partial packet (incomplete frame data) refOs1.write(refDgramBuffer1); refOs1.write(refPacketBuffer1, 0, 15); assertEquals(refDgramId1, testIs.readHeader().getId()); refOs1.write(refPacketBuffer1, 15, refPacketBuffer1.length - 15); assertEquals(refPacketId1, testIs.readHeader().getId()); // write defect packet (frame data msb) refOs1.write(refPacketBuffer1, 0, refPacketBuffer1.length - 1); refOs1.write(refMsbBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // write partial datagram refOs1.write(refTgramBuffer1); refOs1.write(refDgramBuffer1, 0, 15); assertEquals(refTgramId1, testIs.readHeader().getId()); refOs1.write(refDgramBuffer1, 15, refDgramBuffer1.length - 15); assertEquals(refDgramId1, testIs.readHeader().getId()); // write defect datagram refOs1.write(refDgramBuffer1, 0, 15); refOs1.write(refMsbBuffer1, 0, 1); refOs1.write(refTgramBuffer1); assertEquals(refTgramId1, testIs.readHeader().getId()); // write partial telegram (incomplete header) refOs1.write(refDgramBuffer1); refOs1.write(refTgramBuffer1, 0, 7); assertEquals(refDgramId1, testIs.readHeader().getId()); refOs1.write(refTgramBuffer1, 7, refTgramBuffer1.length - 7); assertEquals(refTgramId1, testIs.readHeader().getId()); // write defect telegram (header msb) refOs1.write(refTgramBuffer1, 0, 7); refOs1.write(refMsbBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // write defect telegram (header checksum) refOs1.write(refTgramBuffer1, 0, 7); refOs1.write(refZeroBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // write partial telegram (incomplete frame data) refOs1.write(refDgramBuffer1); refOs1.write(refTgramBuffer1, 0, 15); assertEquals(refDgramId1, testIs.readHeader().getId()); refOs1.write(refTgramBuffer1, 15, refTgramBuffer1.length - 15); assertEquals(refTgramId1, testIs.readHeader().getId()); // write defect telegram (frame data msb) refOs1.write(refTgramBuffer1, 0, refTgramBuffer1.length - 1); refOs1.write(refMsbBuffer1, 0, 1); refOs1.write(refDgramBuffer1); assertEquals(refDgramId1, testIs.readHeader().getId()); // close pipe refOs1.close(); assertEquals(null, testIs.readHeader()); }
From source file:com.esofthead.mycollab.vaadin.resources.StreamDownloadResourceSupportExtDrive.java
@Override public InputStream getStream() { if (resources.size() == 1) { Resource res = resources.iterator().next(); if (res.isExternalResource()) { ExternalResourceService service = ResourceUtils .getExternalResourceService(ResourceUtils.getType(res)); return service.download(ResourceUtils.getExternalDrive(res), res.getPath()); } else {/*w ww .j a va 2 s. co m*/ return resourceService.getContentStream(res.getPath()); } } final PipedInputStream inStream = new PipedInputStream(); final PipedOutputStream outStream; try { outStream = new PipedOutputStream(inStream); } catch (IOException ex) { LOG.error("Can not create outstream file", ex); return null; } Thread threadExport = new MyCollabThread(new Runnable() { @Override public void run() { try { ZipOutputStream zipOutStream = new ZipOutputStream(outStream); zipResource(zipOutStream, resources); zipOutStream.close(); outStream.close(); } catch (Exception e) { LOG.error("Error while saving content stream", e); } } }); threadExport.start(); return inStream; }
From source file:fitnesse.FitNesseExpediterTest.java
private FitNesseExpediter preparePipedFitNesseExpediter() throws Exception { PipedInputStream socketInput = new PipedInputStream(); clientOutput = new PipedOutputStream(socketInput); clientInput = new PipedInputStream(); PipedOutputStream socketOutput = new PipedOutputStream(clientInput); return new FitNesseExpediter(injector, socketInput, socketOutput, 200); }
From source file:org.taverna.server.master.soap.WrappedWorkflow.java
@Override public InputStream getInputStream() throws IOException { PipedInputStream is = new PipedInputStream(); final OutputStream os = new PipedOutputStream(is); new Worker() { @Override/*from www .j a va2 s. c o m*/ public void doWork() throws WriterException, IOException { io.writeBundle(wf.getScufl2Workflow(), os, wf.getPreferredContentType().getContentType()); } @Override public void doneWork() { closeQuietly(os); } }; return is; }
From source file:com.emc.ecs.sync.CasMigrationTest.java
private String pipeAndGetMd5(byte[] source) throws Exception { PipedInputStream pin = new PipedInputStream(BUFFER_SIZE); PipedOutputStream pout = new PipedOutputStream(pin); Producer producer = new Producer(source, pout); // produce in parallel Thread producerThread = new Thread(producer); producerThread.start();//from www . j av a2s .c om // consume inside this thread byte[] dest = new byte[source.length]; try { int read = 0; while (read < dest.length && read != -1) { read += pin.read(dest, read, dest.length - read); } } finally { try { pin.close(); } catch (Throwable t) { // ignore } } // synchronize producerThread.join(); return Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(dest)); }
From source file:org.bimserver.ifcengine.JvmIfcEngine.java
private void startLocal() { try {// www . j a va 2s . c o m PipedInputStream pipedInputStream = new PipedInputStream(); PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream); IfcEngineServer ifcEngineServer = new IfcEngineServer(schemaFile.getAbsolutePath(), pipedInputStream, pipedOutputStream, null); in = new DataInputStream(new BufferedInputStream(pipedInputStream)); out = new DataOutputStream(new BufferedOutputStream(pipedOutputStream)); ifcEngineServer.start(); } catch (IOException e) { LOGGER.error("", e); } }