List of usage examples for java.io PipedInputStream close
public void close() throws IOException
From source file:org.waarp.openr66.context.task.ExecOutputTask.java
private void finalizeFromError(PipedOutputStream outputStream, PumpStreamHandler pumpStreamHandler, PipedInputStream inputStream, AllLineReader allLineReader, Thread thread, int status, CommandLine commandLine) {/*from w w w.j a va2 s . c om*/ try { Thread.sleep(Configuration.RETRYINMS); } catch (InterruptedException e) { } try { outputStream.flush(); } catch (IOException e2) { } try { Thread.sleep(Configuration.RETRYINMS); } catch (InterruptedException e) { } try { outputStream.close(); } catch (IOException e1) { } thread.interrupt(); try { inputStream.close(); } catch (IOException e1) { } try { Thread.sleep(Configuration.RETRYINMS); } catch (InterruptedException e) { } try { pumpStreamHandler.stop(); } catch (IOException e2) { } try { Thread.sleep(Configuration.RETRYINMS); } catch (InterruptedException e) { } String result = allLineReader.getLastLine().toString(); logger.error("Status: " + status + " Exec in error with " + commandLine + " returns " + result); OpenR66RunnerErrorException exc = new OpenR66RunnerErrorException( "<STATUS>" + status + "</STATUS><ERROR>" + result + "</ERROR>"); futureCompletion.setFailure(exc); }
From source file:org.whitesource.agent.utils.ZipUtils.java
private static void consumeDataDecompressStream(PipedInputStream pipedInputStream, OutputStream outputStream) { try (GZIPInputStream chunkZipper = new GZIPInputStream(pipedInputStream); InputStream in = new BufferedInputStream(chunkZipper);) { byte[] buffer = new byte[BYTES_BUFFER_SIZE]; int len;//from w ww .j a v a 2 s . c o m while ((len = in.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } pipedInputStream.close(); } catch (IOException e) { // logger.error("Failed to decompress : ", e); } }
From source file:org.whitesource.agent.utils.ZipUtils.java
private static void consumeDecompressData(PipedInputStream pipedInputStream, StringBuilder stringBuilder) { try (GZIPInputStream chunkZipper = new GZIPInputStream(pipedInputStream); InputStream in = new BufferedInputStream(chunkZipper);) { byte[] buffer = new byte[BYTES_BUFFER_SIZE]; int len;//from w ww . ja v a2 s .c o m while ((len = in.read(buffer)) > 0) { if (len < buffer.length) { byte[] writtenBytes = new byte[len]; getBytes(buffer, 0, len, writtenBytes, 0); stringBuilder.append(new String(writtenBytes, StandardCharsets.UTF_8)); } else { stringBuilder.append(new String(buffer, StandardCharsets.UTF_8)); } } pipedInputStream.close(); } catch (IOException e) { // logger.error("Failed to decompress : ", e); } }
From source file:org.wso2.carbon.dataservices.sql.driver.TDriverUtil.java
/** * Method to write excel data to registry or file output streams. * * @param workbook//from w w w. jav a 2s. co m * @param filePath * @throws SQLException */ public static void writeRecords(Workbook workbook, String filePath) throws SQLException { OutputStream out = null; PipedInputStream pin = null; try { if (isRegistryPath(filePath)) { try { RegistryService registryService = SQLDriverDSComponent.getRegistryService(); if (registryService == null) { throw new SQLException( "DBUtils.getInputStreamFromPath(): Registry service is not available"); } Registry registry; if (filePath.startsWith(CONF_REGISTRY_PATH_PREFIX)) { if (filePath.length() > CONF_REGISTRY_PATH_PREFIX.length()) { filePath = filePath.substring(CONF_REGISTRY_PATH_PREFIX.length()); registry = registryService.getConfigSystemRegistry(getCurrentTenantId()); } else { throw new SQLException("Empty configuration registry path given"); } } else { if (filePath.length() > GOV_REGISTRY_PATH_PREFIX.length()) { filePath = filePath.substring(GOV_REGISTRY_PATH_PREFIX.length()); registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId()); } else { throw new SQLException("Empty governance registry path given"); } } if (registry.resourceExists(filePath)) { pin = new PipedInputStream(); out = new PipedOutputStream(pin); new WorkBookOutputWriter(workbook, out).start(); Resource serviceResource = registry.get(filePath); serviceResource.setContentStream(pin); registry.put(filePath, serviceResource); } else { throw new SQLException("The given XSLT resource path at '" + filePath + "' does not exist"); } } catch (RegistryException e) { throw new SQLException(e); } } else { File file = new File(filePath); if (filePath.startsWith("." + File.separator) || filePath.startsWith(".." + File.separator)) { /* this is a relative path */ filePath = file.getAbsolutePath(); } out = new FileOutputStream(filePath); workbook.write(out); } } catch (FileNotFoundException e) { throw new SQLException("Error occurred while locating the EXCEL datasource", e); } catch (IOException e) { throw new SQLException("Error occurred while writing the records to the EXCEL " + "data source", e); } finally { if (pin != null) { try { pin.close(); } catch (IOException ignore) { } } if (out != null) { try { out.close(); } catch (IOException ignore) { } } } }
From source file:ubicrypt.core.Utils.java
public static InputStream convert(final Observable<byte[]> source) { final PipedOutputStream pos = new PipedOutputStream(); try {//from w w w . j a v a2 s . c o m final PipedInputStream pis = new PipedInputStream(pos); source.subscribe(bytes -> { try { pos.write(bytes); pos.flush(); } catch (final IOException e) { Throwables.propagate(e); } }, err -> { log.error(err.getMessage(), err); try { pis.close(); } catch (final IOException e) { } }); return pis; } catch (final IOException e) { Throwables.propagate(e); } return null; }