List of usage examples for java.io PipedOutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this piped output stream. From source file:Main.java
public static void main(String[] args) throws Exception { byte[] b = { 'h', 'e', 'l', 'l', 'o' }; PipedOutputStream out = new PipedOutputStream(); Main in = new Main(); out.connect(in);/*w w w. j a v a2 s.c om*/ // write something out.write(b, 0, 3); // flush the stream out.flush(); // print what we wrote for (int i = 0; i < 3; i++) { System.out.print((char) in.read()); } out.close(); }
From source file:custom.SevenZFileExt.java
public InputStream getInputStream(final int bufferSize) { final PipedInputStream in = new PipedInputStream(bufferSize); try {//w ww . ja va 2s . c o m final PipedOutputStream out = new PipedOutputStream(in); Thread thread = new Thread(() -> { try { byte[] buffer = new byte[bufferSize]; int len = read(buffer); while (len > 0) { try { out.write(buffer, 0, len); len = read(buffer); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } } out.flush(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } finally { if (out != null) { try { out.close(); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } } } }); thread.setName("GenerateInputStreamSeven7File"); thread.start(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return in; }
From source file:com.edgenius.wiki.service.impl.SitemapServiceImpl.java
public boolean removePage(String pageUuid) throws IOException { boolean removed = false; String sitemapIndex = metadata.getSitemapIndex(pageUuid); if (sitemapIndex == null) { log.warn("Page {} does not exist in sitemap", pageUuid); return removed; }/*from w w w . ja v a 2 s .c o m*/ String sitemapZip = SITEMAP_NAME_PREFIX + sitemapIndex + ".xml.gz"; File sizemapZipFile = new File(mapResourcesRoot.getFile(), sitemapZip); if (!sizemapZipFile.exists()) { throw new IOException("Remove pageUuid " + pageUuid + " from sitemap failed becuase sitemap not found"); } PipedInputStream bis = new PipedInputStream(); PipedOutputStream bos = new PipedOutputStream(bis); InputStream zipfile = new FileInputStream(sizemapZipFile); GZIPInputStream gzipstream = new GZIPInputStream(zipfile); byte[] bytes = new byte[1024 * 1000]; int len = 0; while ((len = gzipstream.read(bytes)) > 0) { bos.write(bytes, 0, len); } IOUtils.closeQuietly(zipfile); IOUtils.closeQuietly(gzipstream); String pageUrl = metadata.getPageUrl(pageUuid); String body = IOUtils.toString(bis); int loc = body.indexOf("<loc>" + pageUrl + "</loc>"); if (loc != -1) { int start = StringUtils.lastIndexOf(body, "<url>", loc); int end = StringUtils.indexOf(body, "</url>", loc); if (start != -1 && end != -1) { //remove this URL body = StringUtils.substring(body, start, end + 6); zipToFile(sizemapZipFile, body.getBytes()); removed = true; } } metadata.removePageMap(pageUuid); return removed; }
From source file:org.whitesource.agent.utils.ZipUtils.java
private static void produceCompressDataFromStream(InputStream inputStream, PipedOutputStream pipedOutputStream) { try (BufferedInputStream in = new BufferedInputStream(inputStream)) { byte[] buffer = new byte[BYTES_BUFFER_SIZE]; int len;/* ww w . j a v a 2s . c o m*/ while ((len = in.read(buffer)) > 0) { pipedOutputStream.write(buffer, 0, len); } pipedOutputStream.close(); } catch (IOException e) { // logger.error("Failed to produce data to compress : ", e); } }