/** * 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); } }
@Override public File create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }
@Override public void extract(File archive, File destination) throws IOException { assertExtractSource(archive); IOUtils.requireDirectory(destination); ArchiveInputStream input = null; try { input = createArchiveInputStream(archive); extract(input, destination); } finally { IOUtils.closeQuietly(input); } }
@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 extract(InputStream archive, File destination) throws IOException { IOUtils.requireDirectory(destination); archiver.extract(compressor.decompressingStream(archive), destination); }
private void closeCurrentEntryStream() { InputStream stream = getCurrentEntryStream(); IOUtils.closeQuietly(stream); currentEntryStream = null; }
/** * 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); }
/** * Recursively writes all given source {@link File}s into the given {@link ArchiveOutputStream}. The paths of the * sources in the archive will be relative to the given parent {@code File}. * * @param parent the parent file node for computing a relative path (see {@link IOUtils#relativePath(File, File)}) * @param sources the files to write in to the archive * @param archive the archive to write into * @throws IOException when an I/O error occurs */ protected void writeToArchive(File parent, File[] sources, ArchiveOutputStream archive) throws IOException { for (File source : sources) { String relativePath = IOUtils.relativePath(parent, source); createArchiveEntry(source, relativePath, archive); if (source.isDirectory()) { writeToArchive(parent, source.listFiles(), archive); } } }
@Override public void extract(File archive, File destination) throws IOException { assertExtractSource(archive); IOUtils.requireDirectory(destination); ArchiveInputStream input = null; try { input = createArchiveInputStream(archive); extract(input, destination); } finally { IOUtils.closeQuietly(input); } }
@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 create(String archive, File destination, File... sources) throws IOException { IOUtils.requireDirectory(destination); File temp = File.createTempFile(destination.getName(), archiver.getFilenameExtension(), destination); File destinationArchive = null; try { temp = archiver.create(temp.getName(), temp.getParentFile(), sources); destinationArchive = new File(destination, getArchiveFileName(archive)); compressor.compress(temp, destinationArchive); } finally { temp.delete(); } return destinationArchive; }
private void closeCurrentEntryStream() { InputStream stream = getCurrentEntryStream(); IOUtils.closeQuietly(stream); currentEntryStream = null; }
/** * 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); }
/** * Recursively writes all given source {@link File}s into the given {@link ArchiveOutputStream}. The paths of the * sources in the archive will be relative to the given parent {@code File}. * * @param parent the parent file node for computing a relative path (see {@link IOUtils#relativePath(File, File)}) * @param sources the files to write in to the archive * @param archive the archive to write into * @throws IOException when an I/O error occurs */ protected void writeToArchive(File parent, File[] sources, ArchiveOutputStream archive) throws IOException { for (File source : sources) { String relativePath = IOUtils.relativePath(parent, source); createArchiveEntry(source, relativePath, archive); if (source.isDirectory()) { writeToArchive(parent, source.listFiles(), archive); } } }
/** * 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); } }
@Override public void extract(File archive, File destination) throws IOException { IOUtils.requireDirectory(destination); /* * The decompressor has to map F-N-F to I-A-E in some cases to preserve compatibility, * and we don't want that here. */ if (!archive.exists()) { throw new FileNotFoundException(String.format("Archive %s does not exist.", archive.getAbsolutePath())); } InputStream archiveStream = null; try { archiveStream = new BufferedInputStream(new FileInputStream(archive)); archiver.extract(compressor.decompressingStream(archiveStream), destination); } catch (FileNotFoundException e) { // Java throws F-N-F for no access, and callers expect I-A-E for that. throw new IllegalArgumentException(String.format("Access control or other error opening %s", archive.getAbsolutePath()), e); } finally { IOUtils.closeQuietly(archiveStream); } }
@Override public void extract(InputStream archive, File destination) throws IOException { IOUtils.requireDirectory(destination); archiver.extract(compressor.decompressingStream(archive), destination); }
@Override public int read(byte[] b, int off, int len) throws IOException { int read = getCurrentEntryStream().read(b, off, len); if (read == -1) { IOUtils.closeQuietly(getCurrentEntryStream()); } count(read); return read; }
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 create(String archive, File destination, File source) throws IOException { return create(archive, destination, IOUtils.filesContainedIn(source)); }