Example usage for java.io PipedOutputStream PipedOutputStream

List of usage examples for java.io PipedOutputStream PipedOutputStream

Introduction

In this page you can find the example usage for java.io PipedOutputStream PipedOutputStream.

Prototype

public PipedOutputStream() 

Source Link

Document

Creates a piped output stream that is not yet connected to a piped input stream.

Usage

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

public static ImageDescriptor bufferedToDescriptorOptimized(final BufferedImage image) throws IOException {
    final PipedOutputStream output = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream();
    output.connect(pipedInputStream);/*from   w ww.  ja v a  2 s.c o m*/

    try {
        new Thread() {

            @Override
            public void run() {
                try {
                    ChartUtilities.writeBufferedImageAsPNG(output, image, false, 0);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }.start();
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
    }

    ImageData img = new ImageData(pipedInputStream);
    ImageDescriptor descriptor = ImageDescriptor.createFromImageData(img);
    return descriptor;
}

From source file:org.wso2.carbon.mediation.connector.message.util.AS4Utils.java

/**
 * Create {@link OMNode} object from {@link Messaging} object
 * @param marshaller {@link Marshaller} instance for {@link Messaging} class
 * @param messaging {@link Messaging} object to be converted to {@link OMNode}
 * @return OMNode object created from {@link Messaging} object
 * @throws IOException/*www .  j  a v a 2 s  . co  m*/
 * @throws XMLStreamException
 * @throws PropertyException
 */
public static OMNode getOMNode(final Marshaller marshaller, final Messaging messaging)
        throws IOException, XMLStreamException, PropertyException {

    final PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream();
    in.connect(out);
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    new Thread(new Runnable() {
        public void run() {
            try {
                // write the original OutputStream to the PipedOutputStream
                marshaller.marshal(messaging, out);
            } catch (JAXBException e) {
                log.error(e);
            }
        }
    }).start();

    //Create a new builder with the StAX reader
    StAXOMBuilder builder = new StAXOMBuilder(in);
    OMNode node = builder.getDocumentElement();
    node.close(true);
    return node;
}

From source file:de.resol.vbus.LiveOutputStreamTest.java

@Test
public void testConstructor() throws Exception {
    PipedOutputStream refOs1 = new PipedOutputStream();

    LiveOutputStream testOs1 = new LiveOutputStream(refOs1);

    assertEquals(refOs1, testOs1.os);/*from w w  w  .j  a  v  a 2  s.  co  m*/
}

From source file:net.minecraft.client.MineExec.java

@Override
protected Integer doInBackground() throws IOException, InterruptedException {
    Executor exe = new DefaultExecutor();
    CommandLine mineExec = CommandLine.parse(mineCmd);

    PipedOutputStream stdout = new PipedOutputStream();
    PipedOutputStream stderr = new PipedOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(stdout, stderr);
    exe.setStreamHandler(streamHandler);
    MinecraftApplet configCrusher = new MinecraftApplet();
    try {//from  w ww .java2 s  .  c o  m
        File target = new File(VersionInfo.getTechnicFolder());
        BufferedInputStream biserr = new BufferedInputStream(new PipedInputStream(stderr));
        ExecuteResultHandler rh = new DefaultExecuteResultHandler();
        exe.execute(mineExec, rh);
        BufferedReader reader = new BufferedReader(new InputStreamReader(biserr));
        configCrusher.minecraftLoaded();
        String line = reader.readLine();
        logWindow.append(line + "\n");
        int dupLen = 0;
        int dupMax = 25;
        while (line != null) {
            String line2 = reader.readLine();
            if ((line2.contains("Aether") || line2.contains("aether") && watchCfg
                    && new File(target + File.separator + VersionInfo.getModpackName(), "MenuAPI.properties")
                            .exists())) {
                configCrusher.prepareConfigs();
            }
            if ((Boolean) nbDebug[2]) {
                if (!line.equals(line2) || dupLen >= dupMax) {
                    if (dupLen > 0) {
                        logWindow.append(line + "(" + dupLen + ")\n");
                    } else {
                        if (!line.equals(line2)) {
                            logWindow.append(line2 + "\n");
                        }
                    }
                    dupLen = 0;
                } else {
                    dupLen++;
                }
                line = line2;
            } else {
                logWindow.append(line2 + "\n");
                line = line2;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    if ((Integer) (nbDebug[1]) <= 1) {
        configCrusher.remExtras();
        configCrusher.minecraftClosed(password);
    }
    return 1;
}

From source file:org.gradle.launcher.daemon.server.exec.ForwardClientInput.java

public void execute(final DaemonCommandExecution execution) {
    final PipedOutputStream inputSource = new PipedOutputStream();
    final PipedInputStream replacementStdin;
    try {//from   w  w w . j  a va2  s .co  m
        replacementStdin = new PipedInputStream(inputSource);
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }

    execution.getConnection().onStdin(new StdinHandler() {
        public void onInput(ForwardInput input) {
            LOGGER.debug("Writing forwarded input on daemon's stdin.");
            try {
                inputSource.write(input.getBytes());
            } catch (IOException e) {
                LOGGER.warn("Received exception trying to forward client input.", e);
            }
        }

        public void onEndOfInput() {
            LOGGER.info("Closing daemon's stdin at end of input.");
            try {
                inputSource.close();
            } catch (IOException e) {
                LOGGER.warn("Problem closing output stream connected to replacement stdin", e);
            } finally {
                LOGGER.info("The daemon will no longer process any standard input.");
            }
        }
    });

    try {
        try {
            new StdinSwapper().swap(replacementStdin, new Callable<Void>() {
                public Void call() {
                    execution.proceed();
                    return null;
                }
            });
        } finally {
            execution.getConnection().onStdin(null);
            IOUtils.closeQuietly(replacementStdin);
            IOUtils.closeQuietly(inputSource);
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}

From source file:annis.visualizers.component.AbstractDotVisualizer.java

@Override
public ImagePanel createComponent(final VisualizerInput visInput, VisualizationToggle visToggle) {
    try {/*  w  w  w  . j  a v  a  2s  . c o m*/

        final PipedOutputStream out = new PipedOutputStream();
        final PipedInputStream in = new PipedInputStream(out);

        new Thread(new Runnable() {
            @Override
            public void run() {
                writeOutput(visInput, out);
            }
        }).start();

        String fileName = "dotvis_" + new Random().nextInt(Integer.MAX_VALUE) + ".png";
        StreamResource resource = new StreamResource(new StreamResource.StreamSource() {

            @Override
            public InputStream getStream() {
                return in;
            }
        }, fileName);

        Embedded emb = new Embedded("", resource);
        emb.setMimeType("image/png");
        emb.setSizeFull();
        emb.setStandby("loading image");
        emb.setAlternateText("DOT graph visualization");
        return new ImagePanel(emb);

    } catch (IOException ex) {
        log.error(null, ex);
    }
    return new ImagePanel(new Embedded());
}

From source file:com.orange.clara.cloud.servicedbdumper.filer.AbstractGzipGenericFiler.java

@Override
public InputStream retrieveWithStream(String filename) throws IOException {
    PipedOutputStream outputPipe = new PipedOutputStream();
    PipedInputStream inputPipe = new PipedInputStream(outputPipe);

    InputStream inputStream = this.originalFiler.retrieveWithStream(filename);
    gzipCompressing.gunziptIt(outputPipe, inputStream);
    logger.debug("Gunziping file ...");
    return inputPipe;
}

From source file:wf.frk.tilde.sblauncher.SauerbratenExecutor.java

public void startThread(String executable, String[] params, String working_dir)
        throws ExecuteException, IOException {

    setDaemon(true);/*w ww .  j  a  v a 2  s.c  o m*/
    startThread();

    CommandLine cmdLine = CommandLine.parse(executable);
    for (String p : params) {
        System.out.println(p);

        cmdLine.addArgument(p);
    }

    DefaultExecutor executor = new DefaultExecutor();

    PipedOutputStream output = new PipedOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(output, System.err);
    SAUER_OUTPUT = new Scanner(new PipedInputStream(output));

    executor.setStreamHandler(streamHandler);
    executor.setWorkingDirectory(new File(working_dir));
    executor.execute(cmdLine);

}

From source file:jsaf.protocol.tftp.TftpURLConnection.java

public InputStream getInputStream() throws IOException {
    if (!connected) {
        connect();/*from   w  w  w.j  a v  a 2 s  .  c o  m*/
    }
    out = new PipedOutputStream();
    in = new PipedInputStream(out);
    new Thread(this, "TFTP Client").start();
    return in;
}

From source file:com.nts.alphamale.shell.AdbShellExecutor.java

/**
 * @param cmd adb //from www  .  j a va2 s.c o  m
 * @param synch   ? ? true: synchronous, false: asynchronous
 * @param  (ms)
 * @return Executor Standard Output? Map
 */
public Map<String, Object> execute(CommandLine cmd, boolean synch, long timeoutMilliseconds) {
    Map<String, Object> executorMap = new HashMap<String, Object>();
    DefaultExecutor executor = new DefaultExecutor();
    PipedOutputStream pos = new PipedOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(pos, System.err);
    streamHandler.setStopTimeout(timeoutMilliseconds);
    DataInputStream dis = null;
    try {
        dis = new DataInputStream(new PipedInputStream(pos));
    } catch (IOException e) {
        //log.error(e.getCause() + " : " + e.getMessage());
    }
    executor.setStreamHandler(streamHandler);
    ExecuteWatchdog watchDog = new ExecuteWatchdog(timeoutMilliseconds);
    executor.setWatchdog(watchDog);
    try {
        if (synch)
            executor.execute(cmd);
        else
            executor.execute(cmd, new DefaultExecuteResultHandler());

        log.debug(cmd.toString());
        LineIterator li = IOUtils.lineIterator(dis, "UTF-8");
        if (li != null) {
            executorMap.put("executor", executor);
            executorMap.put("stdOut", li);
        }
    } catch (Exception e) {
        log.error(e.getCause() + ":" + e.getMessage() + "[" + cmd + "]");
    }
    return executorMap;
}