/** * Copy input stream to output stream without closing streams. Flushes output stream when done. * * @param is input stream * @param os output stream * * @throws IOException for any error */ public static void copyStream(InputStream is, OutputStream os) throws IOException { copyStream(is, os, DEFAULT_BUFFER_SIZE); }
/** * Copy input stream to output stream without closing streams. Flushes output stream when done. * * @param is input stream * @param os output stream * * @throws IOException for any error */ public static void copyStream(InputStream is, OutputStream os) throws IOException { copyStream(is, os, DEFAULT_BUFFER_SIZE); }
private static void addFileToZip(File file, String parent, ZipOutputStream zos) throws IOException { try (final FileInputStream is = new FileInputStream(file)){ final String entryName = parent == null ? file.getName() : parent + "/" + file.getName(); zos.putNextEntry(new ZipEntry(entryName)); try (final BufferedInputStream bis = new BufferedInputStream(is)){ copyStream(bis, zos); } zos.closeEntry(); } }
private static void addFileToZip(File file, String parent, ZipOutputStream zos) throws IOException { try (final FileInputStream is = new FileInputStream(file)){ final String entryName = parent == null ? file.getName() : parent + "/" + file.getName(); zos.putNextEntry(new ZipEntry(entryName)); try (final BufferedInputStream bis = new BufferedInputStream(is)){ copyStream(bis, zos); } zos.closeEntry(); } }
public static byte[] copyAndGetHash(final InputStream is, final OutputStream os) throws IOException { byte[] sha1Bytes; synchronized (DIGEST) { DIGEST.reset(); try (BufferedInputStream bis = new BufferedInputStream(is); DigestOutputStream dos = new DigestOutputStream(os, DIGEST)) { IoUtils.copyStream(bis, dos); } sha1Bytes = DIGEST.digest(); } return sha1Bytes; }
public static byte[] copyAndGetHash(final InputStream is, final OutputStream os) throws IOException { byte[] sha1Bytes; synchronized (DIGEST) { DIGEST.reset(); try (BufferedInputStream bis = new BufferedInputStream(is); DigestOutputStream dos = new DigestOutputStream(os, DIGEST)) { IoUtils.copyStream(bis, dos); } sha1Bytes = DIGEST.digest(); } return sha1Bytes; }
/** * Copy input stream to output stream and close them both * * @param is input stream * @param os output stream * * @throws IOException for any error */ public static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException { try { copyStream(is, os, DEFAULT_BUFFER_SIZE); // throw an exception if the close fails since some data might be lost is.close(); os.close(); } finally { // ...but still guarantee that they're both closed safeClose(is); safeClose(os); } }
/** * Copy input stream to output stream and close them both * * @param is input stream * @param os output stream * * @throws IOException for any error */ public static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException { try { copyStream(is, os, DEFAULT_BUFFER_SIZE); // throw an exception if the close fails since some data might be lost is.close(); os.close(); } finally { // ...but still guarantee that they're both closed safeClose(is); safeClose(os); } }
static void process(final File targetRoot, final File distributionRoot, final Patch patch) throws IOException, XMLStreamException { try { targetRoot.mkdirs(); final InputStream is = PatchContentWriter.class.getClassLoader().getResourceAsStream(README); try { final File readme = new File(targetRoot, README); final OutputStream os = new FileOutputStream(readme); try { IoUtils.copyStream(is, os); } finally { IoUtils.safeClose(os); } } finally { IoUtils.safeClose(is); } // Write the patch xml final File patchXml = new File(targetRoot, PatchXml.PATCH_XML); final FileOutputStream os = new FileOutputStream(patchXml); try { PatchXml.marshal(os, patch); } finally { IoUtils.safeClose(os); } // Copy internalProcess(targetRoot, distributionRoot, patch); } finally { } }