List of usage examples for org.apache.commons.compress.archivers ArchiveOutputStream closeArchiveEntry
public abstract void closeArchiveEntry() throws IOException;
From source file:org.rauschig.jarchivelib.CommonsArchiver.java
/** * Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File} * into the new entry./*from www . ja v a 2 s . c o m*/ * * @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(); }
From source file:org.seadva.archive.impl.cloud.SdaArchiveStore.java
public void createTar(final File dir, final String tarFileName) { try {/*from w w w . j a v a 2 s. c o m*/ OutputStream tarOutput = new FileOutputStream(new File(tarFileName)); ArchiveOutputStream tarArchive = new TarArchiveOutputStream(tarOutput); List<File> files = new ArrayList<File>(); File[] filesList = dir.listFiles(); if (filesList != null) { for (File file : filesList) { files.addAll(recurseDirectory(file)); } } for (File file : files) { // tarArchiveEntry = new TarArchiveEntry(file, file.getPath()); TarArchiveEntry tarArchiveEntry = new TarArchiveEntry( file.toString().substring(dir.getAbsolutePath().length() + 1, file.toString().length())); tarArchiveEntry.setSize(file.length()); tarArchive.putArchiveEntry(tarArchiveEntry); FileInputStream fileInputStream = new FileInputStream(file); IOUtils.copy(fileInputStream, tarArchive); fileInputStream.close(); tarArchive.closeArchiveEntry(); } tarArchive.finish(); tarOutput.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.structr.web.function.CreateArchiveFunction.java
private void addFileToZipArchive(String path, File file, ArchiveOutputStream aps) throws IOException { logger.info("Adding File \"{}\" to new archive...", path); ZipArchiveEntry entry = new ZipArchiveEntry(path); aps.putArchiveEntry(entry);/*from w w w . j av a2s . co m*/ try (final InputStream in = file.getInputStream()) { IOUtils.copy(in, aps); } aps.closeArchiveEntry(); }
From source file:org.trustedanalytics.servicebroker.gearpump.service.file.FileHelper.java
private static void addArchiveEntry(ArchiveOutputStream outputStream, ArchiveEntry entry, byte[] content) throws IOException { outputStream.putArchiveEntry(entry); outputStream.write(content);//from ww w. ja v a 2s .c om outputStream.closeArchiveEntry(); }
From source file:org.wso2.carbon.connector.util.FileCompressUtil.java
/** * Add the files to compression/*from w w w.j a v a 2 s. c o m*/ * * @param taos * @param file * @param dir * @param archiveType * @throws IOException */ private void addFilesToCompression(ArchiveOutputStream taos, File file, String dir, ArchiveType archiveType) throws IOException { // Create an entry for the file switch (archiveType) { case TAR_GZIP: taos.putArchiveEntry(new TarArchiveEntry(file, dir + "/" + file.getName())); break; case ZIP: taos.putArchiveEntry(new ZipArchiveEntry(file, dir + "/" + file.getName())); break; } if (file.isFile()) { // Add the file to the archive BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(bis, taos); taos.closeArchiveEntry(); bis.close(); } else if (file.isDirectory()) { // close the archive entry taos.closeArchiveEntry(); // go through all the files in the directory and using recursion, // add them to the archive for (File childFile : file.listFiles()) { addFilesToCompression(taos, childFile, file.getName(), archiveType); } } }