List of usage examples for java.io PipedInputStream PipedInputStream
public PipedInputStream(int pipeSize)
PipedInputStream
so that it is not yet #connect(java.io.PipedOutputStream) connected and uses the specified pipe size for the pipe's buffer. From source file:org.pentaho.webpackage.deployer.archive.impl.WebPackageURLConnection.java
@Override public InputStream getInputStream() throws IOException { try {/* w w w. j a v a 2 s. c o m*/ final PipedOutputStream pipedOutputStream = new PipedOutputStream(); PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream); // making this here allows to fail with invalid URLs final java.net.URLConnection urlConnection = this.url.openConnection(); urlConnection.connect(); final InputStream originalInputStream = urlConnection.getInputStream(); this.transform_thread = EXECUTOR .submit(new WebPackageTransformer(this.url, originalInputStream, pipedOutputStream)); return pipedInputStream; } catch (Exception e) { this.logger.error(getURL().toString() + ": Error opening url"); throw new IOException("Error opening url", e); } }
From source file:com.sonar.scanner.api.it.tools.CommandExecutor.java
private ExecuteStreamHandler createStreamHandler() throws IOException { logs = new ByteArrayOutputStream(); PipedOutputStream outPiped = new PipedOutputStream(); InputStream inPiped = new PipedInputStream(outPiped); in = outPiped;// ww w . j av a 2s .co m TeeOutputStream teeOut = new TeeOutputStream(logs, System.out); TeeOutputStream teeErr = new TeeOutputStream(logs, System.err); return new PumpStreamHandler(teeOut, teeErr, inPiped); }
From source file:org.guvnor.ala.build.maven.executor.MavenCliOutputTest.java
@Test public void buildAppAndWaitForMavenOutputTest() throws IOException { final GitHub gitHub = new GitHub(); gitHub.getRepository("salaboy/drools-workshop", new HashMap<String, String>() { {//w w w . j av a 2 s . c o m put("out-dir", tempPath.getAbsolutePath()); } }); final Optional<Source> _source = new GitConfigExecutor(new InMemorySourceRegistry()) .apply(new GitConfigImpl(tempPath.getAbsolutePath(), "master", "https://github.com/salaboy/drools-workshop", "drools-workshop", "true")); assertTrue(_source.isPresent()); final Source source = _source.get(); boolean buildProcessReady = false; Throwable error = null; PipedOutputStream baosOut = new PipedOutputStream(); PipedOutputStream baosErr = new PipedOutputStream(); final PrintStream out = new PrintStream(baosOut, true); final PrintStream err = new PrintStream(baosErr, true); //Build the project in a different thread new Thread(() -> { buildMavenProject(source, out, err); }).start(); // Use the PipeOutputStream to read the execution output and validate that the application was built. StringBuilder sb = new StringBuilder(); BufferedReader bufferedReader; bufferedReader = new BufferedReader(new InputStreamReader(new PipedInputStream(baosOut))); String line; while (!(buildProcessReady || error != null)) { if ((line = bufferedReader.readLine()) != null) { sb.append(line).append("\n"); if (line.contains("Building war:")) { buildProcessReady = true; out.close(); err.close(); baosOut.close(); baosErr.close(); } } } assertTrue(sb.toString().contains("Building war:")); assertTrue(buildProcessReady); assertTrue(error == null); }
From source file:it.sonarlint.cli.tools.CommandExecutor.java
private ExecuteStreamHandler createStreamHandler() throws IOException { out = new ByteArrayOutputStream(); err = new ByteArrayOutputStream(); PipedOutputStream outPiped = new PipedOutputStream(); InputStream inPiped = new PipedInputStream(outPiped); in = outPiped;/*from ww w . java 2s .c o m*/ TeeOutputStream teeOut = new TeeOutputStream(out, System.out); TeeOutputStream teeErr = new TeeOutputStream(err, System.err); return new PumpStreamHandler(teeOut, teeErr, inPiped); }
From source file:vlove.virt.VirtBuilder.java
/** * Returns the exit value of the process. * /*from w w w. j av a 2s . co m*/ * @param out * @param err * @return * @throws VirtException */ public int createVirtualMachine(NewVmWizardModel newVm, StreamConsumer out, StreamConsumer err) throws VirtException { List<String> command = createVirtMachineCommand(newVm); if (command == null || command.size() < 1) { throw new VirtException("Command needs to be provided."); } try { Commandline cs = new Commandline(); cs.setExecutable(command.get(0)); if (command.size() > 1) { cs.addArguments(command.subList(1, command.size()).toArray(new String[] {})); } PipedOutputStream pOut = new PipedOutputStream(); PipedInputStream pIs = new PipedInputStream(pOut); List<ConsumerListener> listeners = new ArrayList<>(); listeners.add(new ConsumerListener(pOut, Pattern.compile("\\[sudo\\] password for \\w+:"), "password")); NestedStreamConsumer nOut = new NestedStreamConsumer(listeners, out); return CommandLineUtils.executeCommandLine(cs, pIs, nOut, err); } catch (CommandLineException ce) { throw new VirtException("Could not execute command.", ce); } catch (IOException ie) { throw new VirtException("Could not execute command.", ie); } }
From source file:org.opennms.systemreport.SystemReportResourceLocator.java
@Override public String slurpOutput(final String commandString, final boolean ignoreExitCode) { final CommandLine command = CommandLine.parse(commandString); LOG.debug("running: {}", commandString); final Map<String, String> environment = new HashMap<String, String>(System.getenv()); environment.put("COLUMNS", "2000"); DataInputStream input = null; PipedInputStream pis = null;/*from w w w . j a v a 2 s .c o m*/ OutputSuckingParser parser = null; String outputText = null; final DefaultExecutor executor = new DefaultExecutor(); final PipedOutputStream output = new PipedOutputStream(); final PumpStreamHandler streamHandler = new PumpStreamHandler(output, output); executor.setWatchdog(new ExecuteWatchdog(m_maxProcessWait)); executor.setStreamHandler(streamHandler); if (ignoreExitCode) { executor.setExitValues(null); } try { LOG.trace("executing '{}'", commandString); pis = new PipedInputStream(output); input = new DataInputStream(pis); parser = new OutputSuckingParser(input); parser.start(); final int exitValue = executor.execute(command, environment); IOUtils.closeQuietly(output); parser.join(m_maxProcessWait); if (!ignoreExitCode && exitValue != 0) { LOG.debug("error running '{}': exit value was {}", commandString, exitValue); } else { outputText = parser.getOutput(); } LOG.trace("finished '{}'", commandString); } catch (final Exception e) { LOG.debug("Failed to run '{}'", commandString, e); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); IOUtils.closeQuietly(pis); } return outputText; }
From source file:org.jclouds.logging.internal.Wire.java
public InputStream tapAsynch(final String header, InputStream instream) { PipedOutputStream out = new PipedOutputStream(); InputStream toReturn = new TeeInputStream(instream, out, true); final InputStream line; try {//from w w w . ja va2s . com line = new PipedInputStream(out); exec.submit(new Runnable() { public void run() { try { wire(header, line); } finally { IOUtils.closeQuietly(line); } } }); } catch (IOException e) { logger.error(e, "Error tapping line"); } return toReturn; }
From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java
/** * Constructs a new exporting input stream with the default buffer size of 64KB. * //from w w w. ja v a 2s .c o m * @param synchronizers the synchronizers to invoke when producing the export file * @param messagesPerExporter a reference to a map of messages that the exporters will use to produce additional info about the export * @param size the size in bytes of the intermediate buffer * @param zip whether to zip the export data * @throws IOException on failure */ public ExportingInputStream(Set<Synchronizer<?, ?>> synchronizers, Map<String, ExporterMessages> messagesPerExporter, int size, boolean zip) throws IOException { this.synchronizers = synchronizers; this.messagesPerExporter = messagesPerExporter; inputStream = new PipedInputStream(size); exportOutput = new PipedOutputStream(inputStream); zipOutput = zip; try { JAXBContext context = JAXBContext.newInstance(DefaultImportConfigurationDescriptor.class); configurationMarshaller = context.createMarshaller(); configurationMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); configurationMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); configurationMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); } catch (JAXBException e) { throw new IOException(e); } }
From source file:net.i2cat.netconf.transport.VirtualTransport.java
public void connect(SessionContext sessionContext) throws TransportException { // let the transportId instance be GC'ed after connect(); // this.transportId = transportId; log.info("Virtual transport"); this.sessionContext = sessionContext; // TODO CHECK IF IT WORKS user = sessionContext.getUser();//from w ww . jav a2 s .c o m password = sessionContext.getPass(); host = sessionContext.getHost(); port = sessionContext.getPort(); if (port < 0) port = 22; subsystem = sessionContext.getSubsystem(); log.debug("user: " + user); log.debug("pass: " + (password != null ? "yes" : "no")); log.debug("hostname: " + host + ":" + port); log.debug("subsystem: " + subsystem); simHelper = new DummySimulatorHelper(); // Check the type of responses simHelper.setResponseError(subsystem.equals("errorServer")); // this will fake the two endpoints of a tcp connection try { outStream = new PipedOutputStream(); inStream = new PipedInputStream(outStream); } catch (IOException e) { throw new TransportException(e.getMessage()); } closed = false; // notify handlers for (TransportListener handler : listeners) handler.transportOpened(); startParsing(); }
From source file:org.pentaho.osgi.platform.webjars.WebjarsURLConnection.java
@Override public InputStream getInputStream() throws IOException { try {/*from w w w . j av a 2s. com*/ final PipedOutputStream pipedOutputStream = new PipedOutputStream(); PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream); // making this here allows to fail with invalid URLs final URLConnection urlConnection = url.openConnection(); urlConnection.connect(); final InputStream originalInputStream = urlConnection.getInputStream(); transform_thread = EXECUTOR.submit( new WebjarsTransformer(url, originalInputStream, pipedOutputStream, this.minificationEnabled)); return pipedInputStream; } catch (Exception e) { logger.error(getURL().toString() + ": Error opening url"); throw new IOException("Error opening url", e); } }