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.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 va 2s . c o 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: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:de.resol.vbus.LiveOutputStreamTest.java
@Test public void testWriteHeader() throws Exception { Datagram refDgram1 = new Datagram(0, 0, 0x2336, 0x3335, 0x4334, 0x5333, 0x63328330); PipedInputStream refIs1 = new PipedInputStream(2048); PipedOutputStream refOs1 = new PipedOutputStream(refIs1); LiveOutputStream testOs1 = new LiveOutputStream(refOs1); testOs1.writeHeader(refDgram1);// ww w .j a v a2 s .c o m byte[] testBuffer1 = new byte[32]; int testLength1 = refIs1.read(testBuffer1); assertEquals(16, testLength1); assertEquals("aa362335332034433353300332630851", Hex.encodeHexString(testBuffer1).substring(0, 32)); }
From source file:wf.frk.tilde.sblauncher.SauerbratenExecutor.java
public void startThread(String executable, String[] params, String working_dir) throws ExecuteException, IOException { setDaemon(true);/*from www .j a v a2 s .co 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();/* w w w . java 2 s.c o m*/ } out = new PipedOutputStream(); in = new PipedInputStream(out); new Thread(this, "TFTP Client").start(); return in; }
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 . ja v a 2 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: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 w ww . j av a 2 s . c o m*/ 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/* ww w . ja va2 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.duracloud.audit.reader.impl.AuditLogReaderImpl.java
@Override public InputStream getAuditLog(final String account, final String storeId, final String spaceId) throws AuditLogReaderException { checkEnabled();/* w w w . java 2 s .c o m*/ this.storageProvider = getStorageProvider(); final String auditBucket = auditConfig.getAuditLogSpaceId(); String prefix = MessageFormat.format("{0}/{1}/{2}/", account, storeId, spaceId); final PipedInputStream is = new PipedInputStream(10 * 1024); final PipedOutputStream os; try { os = new PipedOutputStream(is); } catch (IOException e) { throw new AuditLogReaderException(e); } try { final Iterator<String> it = this.storageProvider.getSpaceContents(auditBucket, prefix); if (!it.hasNext()) { os.write((AuditLogUtil.getHeader() + "\n").getBytes()); os.close(); } new Thread(new Runnable() { @Override public void run() { try { int count = 0; while (it.hasNext()) { String contentId = it.next(); writeToOutputStream(auditBucket, storageProvider, os, count, contentId); count++; } os.close(); } catch (ContentStoreException | IOException ex) { log.error(MessageFormat.format("failed to complete audit log read routine " + "for space: storeId={0}, spaceId={1}", storeId, spaceId), ex); } } }).start(); } catch (StorageException | IOException e) { throw new AuditLogReaderException(e); } return is; }
From source file:org.duracloud.manifest.impl.ManifestGeneratorImpl.java
@Override public InputStream getManifest(String account, String storeId, String spaceId, ManifestFormat format) throws ManifestArgumentException, ManifestNotFoundException { log.info("retrieving manifest for account:{}, storeId:{}, spaceId:{}, format:{}", account, storeId, spaceId, format);/*w w w .j a v a2 s . c om*/ try { storeId = validateStoreId(storeId); validateSpaceId(storeId, spaceId); PipedInputStream is = new PipedInputStream(10 * 1024); final PipedOutputStream os = new PipedOutputStream(is); final Iterator<ManifestItem> it = this.manifestStore.getItems(account, storeId, spaceId); final ManifestFormatter formatter = getFormatter(format); if (!it.hasNext()) { formatter.writeManifestItemToOutput(null, os); os.close(); return is; } else { new Thread(new Runnable() { @Override public void run() { try { while (it.hasNext()) { formatter.writeManifestItemToOutput(it.next(), os); } try { os.close(); } catch (IOException e) { log.error("failed to close piped output stream : " + e.getMessage(), e); } } catch (Exception e) { log.error("error writing to piped output stream : " + e.getMessage(), e); } } }).start(); } return is; } catch (IOException | RuntimeException ex) { log.error("failed to retrieve manifest: " + ex.getMessage(), ex); throw new ManifestGeneratorException(ex.getMessage()); } }