/** * Copies the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes. * * @param input the InputStream to copy * @param output the target Stream * @return the amount of bytes written * @throws IOException if an error occurs */ public static long copy(final InputStream input, final OutputStream output) throws IOException { return copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Copies the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes. * * @param input the InputStream to copy * @param output the target Stream * @return the amount of bytes written * @throws IOException if an error occurs */ public static long copy(final InputStream input, final OutputStream output) throws IOException { return copy(input, output, DEFAULT_BUFFER_SIZE); }
/** * Copies the content of an InputStream into a destination File. * * @param source the InputStream to copy * @param destination the target File * @throws IOException if an error occurs */ public static void copy(InputStream source, File destination) throws IOException { OutputStream output = null; try { output = new FileOutputStream(destination); copy(source, output); } finally { closeQuietly(output); } }
/** * Copies the content of an InputStream into a destination File. * * @param source the InputStream to copy * @param destination the target File * @throws IOException if an error occurs */ public static void copy(InputStream source, File destination) throws IOException { OutputStream output = null; try { output = new FileOutputStream(destination); copy(source, output); } finally { closeQuietly(output); } }
private void extract(ArchiveInputStream input, File destination) throws IOException { ArchiveEntry entry; while ((entry = input.getNextEntry()) != null) { File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); IOUtils.copy(input, file); } FileModeMapper.map(entry, file); } }
private void extract(ArchiveInputStream input, File destination) throws IOException { ArchiveEntry entry; while ((entry = input.getNextEntry()) != null) { File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); IOUtils.copy(input, file); } FileModeMapper.map(entry, file); } }
@Override public File extract(File destination) throws IOException, IllegalStateException, IllegalArgumentException { assertState(); IOUtils.requireDirectory(destination); File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); IOUtils.copy(stream, file); } FileModeMapper.map(entry, file); return file; }
@Override public File extract(File destination) throws IOException, IllegalStateException, IllegalArgumentException { assertState(); IOUtils.requireDirectory(destination); File file = new File(destination, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); IOUtils.copy(stream, file); } FileModeMapper.map(entry, file); return file; }
@Override public void compress(File source, File destination) throws IllegalArgumentException, IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getCompressedFilename(source)); } CompressorOutputStream compressed = null; BufferedInputStream input = null; try { input = new BufferedInputStream(new FileInputStream(source)); compressed = createCompressorOutputStream(this, destination); IOUtils.copy(input, compressed); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(input); } }
@Override public void compress(File source, File destination) throws IllegalArgumentException, IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getCompressedFilename(source)); } CompressorOutputStream compressed = null; BufferedInputStream input = null; try { input = new BufferedInputStream(new FileInputStream(source)); compressed = createCompressorOutputStream(this, destination); IOUtils.copy(input, compressed); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(input); } }
@Override public void decompress(File source, File destination) throws IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getDecompressedFilename(source)); } CompressorInputStream compressed = null; FileOutputStream output = null; try { compressed = createCompressorInputStream(getCompressionType(), source); output = new FileOutputStream(destination); IOUtils.copy(compressed, output); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(output); } }
@Override public void decompress(File source, File destination) throws IOException { assertSource(source); assertDestination(destination); if (destination.isDirectory()) { destination = new File(destination, getDecompressedFilename(source)); } CompressorInputStream compressed = null; FileOutputStream output = null; try { compressed = createCompressorInputStream(getCompressionType(), source); output = new FileOutputStream(destination); IOUtils.copy(compressed, output); } catch (CompressorException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(compressed); IOUtils.closeQuietly(output); } }
/** * Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File} * into the new entry. * * @param file the file to add to the archive * @param entryName the name of the archive entry * @param archive the archive to write to * @throws IOException when an I/O error occurs during FileInputStream creation or during copying */ protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException { ArchiveEntry entry = archive.createArchiveEntry(file, entryName); // TODO #23: read permission from file, write it to the ArchiveEntry archive.putArchiveEntry(entry); if (!entry.isDirectory()) { FileInputStream input = null; try { input = new FileInputStream(file); IOUtils.copy(input, archive); } finally { IOUtils.closeQuietly(input); } } archive.closeArchiveEntry(); } }
/** * Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File} * into the new entry. * * @param file the file to add to the archive * @param entryName the name of the archive entry * @param archive the archive to write to * @throws IOException when an I/O error occurs during FileInputStream creation or during copying */ protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException { ArchiveEntry entry = archive.createArchiveEntry(file, entryName); // TODO #23: read permission from file, write it to the ArchiveEntry archive.putArchiveEntry(entry); if (!entry.isDirectory()) { FileInputStream input = null; try { input = new FileInputStream(file); IOUtils.copy(input, archive); } finally { IOUtils.closeQuietly(input); } } archive.closeArchiveEntry(); } }