List of usage examples for java.io PipedOutputStream PipedOutputStream
public PipedOutputStream()
From source file:pt.ua.tm.neji.util.ZipGenerator.java
/** * Builds a zip file generator that stores in it the specified root folder and its sub-folders and sub-files. * To avoid having to copy data from other paths into the root in order to add it to the resulting * zip file, the user can specify extra files to be added into the root on generation. The user must specify * a final name for each extra file object. *//*from ww w . j ava2s. com*/ public ZipGenerator(final File rootFolder, final Pair<String, File>... extraFilesToAddIntoRoot) throws IOException { this.rootFolder = rootFolder; this.otherFiles = extraFilesToAddIntoRoot; // writing in the PipedOutputStream will pass the data // into the PipedInputStream when completed pos = new PipedOutputStream(); pis = new PipedInputStream(pos); zip = new ZipOutputStream(pos); out = new BufferedOutputStream(zip); }
From source file:org.openxdata.server.service.impl.FormDownloadServiceTest.java
@Test @Ignore("throws too many exceptions") public void testSubmitForms_noSerializer() throws Exception { // create the stream final PipedOutputStream pout = new PipedOutputStream(); DataInputStream in = new DataInputStream(new PipedInputStream(pout)); Thread thread = new Thread(new Runnable() { @Override// w ww.ja v a2 s. c o m public void run() { DataOutput output = new DataOutputStream(pout); try { output.writeByte(1); output.writeUTF(XFormsFixture.getSampleFormModelData()); } catch (IOException e) { e.printStackTrace(); } } }); thread.start(); DataOutputStream out = new DataOutputStream(new ByteArrayOutputStream()); // run test formDownloadService.submitForms(in, out, null); // do checks afterwards List<FormDataHeader> formData = studyManagerService.getFormData(12, null, null, null); Assert.assertEquals("after submit there is 1 form data", 1, formData.size()); }
From source file:org.pircbotx.CAPTest.java
public void runTest(String cap, final OutputParser callback) throws Exception { final MutableObject<Exception> connectionException = new MutableObject<Exception>(); botInWrite = new PipedOutputStream(); botIn = new BufferedInputStream(new PipedInputStream(botInWrite)); botOut = new ByteArrayOutputStream() { @Override//from www . j ava2 s . c o m public synchronized void write(byte[] bytes, int i, int i1) { super.write(bytes, i, i1); String outputText = new String(bytes, i, i1).trim(); try { try { String callbackText = callback.handleOutput(outputText); if (callbackText == null) //Will close bots input loop botInWrite.close(); else if (!callbackText.equals("")) { botInWrite.write((callbackText + "\r\n").getBytes()); botInWrite.flush(); } } catch (Exception ex) { log.error("Recieved error, closing bot and escelating", ex); connectionException.setValue(ex); botInWrite.close(); } } catch (IOException ex) { log.error("Recieved IO error, closing bot and escelating", ex); connectionException.setValue(ex); try { botInWrite.close(); } catch (Exception e) { throw new RuntimeException("Can't close botInWrite", e); } } } }; Socket socket = mock(Socket.class); when(socket.isConnected()).thenReturn(true); when(socket.getInputStream()).thenReturn(botIn); when(socket.getOutputStream()).thenReturn(botOut); Configuration.Builder configurationBuilder = TestUtils.generateConfigurationBuilder(); SocketFactory socketFactory = mock(SocketFactory.class); when(socketFactory.createSocket( InetAddress.getByName(configurationBuilder.getServers().get(0).getHostname()), 6667, null, 0)) .thenReturn(socket); configurationBuilder.getCapHandlers().clear(); configurationBuilder.getCapHandlers().addAll(capHandlers); bot = new PircBotX( configurationBuilder.setSocketFactory(socketFactory).setAutoReconnect(false).buildConfiguration()); botInWrite.write((":ircd.test CAP * LS :" + cap + "\r\n").getBytes()); bot.connect(); if (connectionException.getValue() != null) throw connectionException.getValue(); }
From source file:com.msopentech.odatajclient.engine.communication.request.ODataStreamManager.java
/** * Constructor.//from w w w .jav a 2 s. c om * * @param futureWrap wrapper of the Future object of the HttpResponse. */ public ODataStreamManager(final Wrapper<Future<HttpResponse>> futureWrap) { this(futureWrap, new PipedOutputStream()); }
From source file:edu.lternet.pasta.dml.download.DocumentHandler.java
public DocumentHandler() { //initialize the streams for reading the document from server outputStream = new PipedOutputStream(); inputStream = new PipedInputStream(); try {//from www .j a va 2 s . c o m outputStream.connect(inputStream); } catch (IOException e1) { log.error("could not connect piped streams! " + e1.getMessage()); e1.printStackTrace(); } }
From source file:org.apache.olingo.client.core.communication.request.AbstractODataStreamManager.java
/** * Constructor./* w w w . jav a2 s . c om*/ * * @param futureWrap wrapper of the Future object of the HttpResponse. */ public AbstractODataStreamManager(final Wrapper<Future<HttpResponse>> futureWrap) { this(futureWrap, new PipedOutputStream()); }
From source file:edu.lternet.pasta.dml.util.DocumentDownloadUtil.java
private void init() { //initialize the streams for reading the document from server outputStream = new PipedOutputStream(); inputStream = new PipedInputStream(); try {//from ww w . j a v a 2s. c o m outputStream.connect(inputStream); } catch (IOException e1) { log.error("could not connect piped streams! " + e1.getMessage()); e1.printStackTrace(); } }
From source file:org.apache.xmlgraphics.util.io.Base64Test.java
private void innerBase64Test(final String action, final URL inputIn, final URL inputRef) throws IOException { URL ref = inputRef;/*from ww w . ja v a 2s.c o m*/ final URL in = inputIn; InputStream inIS = in.openStream(); if (action.equals("ROUND")) { ref = in; } else if (!action.equals("ENCODE") && !action.equals("DECODE")) { fail("Bad action string"); } try (final InputStream refIS = ref.openStream()) { if (action.equals("ENCODE") || action.equals("ROUND")) { // We need to encode the incomming data try (final PipedOutputStream pos = new PipedOutputStream()) { try (final OutputStream os = new Base64EncodeStream(pos)) { // Copy the input to the Base64 Encoder (in a seperate // thread). final Thread t = new StreamCopier(inIS, os); // Read that from the piped output stream. inIS = new PipedInputStream(pos); t.start(); } if (action.equals("DECODE") || action.equals("ROUND")) { inIS = new Base64DecodeStream(inIS); } final boolean mismatch = compareStreams(inIS, refIS, action.equals("ENCODE")); if (!mismatch) { fail("Wrong result"); } } } } finally { IOUtils.closeQuietly(inIS); } }
From source file:ee.ria.xroad.proxy.testsuite.testcases.AttachmentBig.java
@Override protected Pair<String, InputStream> getRequestInput(boolean addUtf8Bom) throws Exception { PipedOutputStream os = new PipedOutputStream(); PipedInputStream is = new PipedInputStream(os); MultiPartOutputStream mpos = new MultiPartOutputStream(os); if (addUtf8Bom) { mpos.write(ByteOrderMark.UTF_8.getBytes()); }/*from ww w .j a v a 2s. c o m*/ new Thread(new MpWriter(mpos)).start(); return Pair.of("multipart/related; charset=UTF-8; " + "boundary=" + mpos.getBoundary(), (InputStream) is); }
From source file:ro.kuberam.libs.java.crypto.CryptoModuleTests.java
@Ignore @Test// w ww. jav a 2s. com public void pipedStreams2Test() throws Exception { try (final InputStream document = getClass().getResourceAsStream("../doc-1.xml"); final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { int next = document.read(); while (next > -1) { bos.write(next); next = document.read(); } bos.flush(); final byte[] result = bos.toByteArray(); try (final PipedOutputStream poStream = new PipedOutputStream(); final PipedInputStream piStream = new PipedInputStream()) { // piped input stream connect to the piped output stream piStream.connect(poStream); // Writes specified byte array. poStream.write(result); // Reads the next byte of data from this piped input stream. for (int i = 0; i < result.length; i++) { System.out.println(piStream.read()); } } } }