List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream putArchiveEntry
public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException
From source file:lucee.commons.io.compress.CompressUtil.java
private static void compressTar(String parent, Resource source, TarArchiveOutputStream tos, int mode) throws IOException { if (source.isFile()) { //TarEntry entry = (source instanceof FileResource)?new TarEntry((FileResource)source):new TarEntry(parent); TarArchiveEntry entry = new TarArchiveEntry(parent); entry.setName(parent);/*from w w w .j ava 2s . com*/ // mode //100777 TODO ist das so ok? if (mode > 0) entry.setMode(mode); else if ((mode = source.getMode()) > 0) entry.setMode(mode); entry.setSize(source.length()); entry.setModTime(source.lastModified()); tos.putArchiveEntry(entry); try { IOUtil.copy(source, tos, false); } finally { tos.closeArchiveEntry(); } } else if (source.isDirectory()) { compressTar(parent, source.listResources(), tos, mode); } }
From source file:net.firejack.platform.core.utils.ArchiveUtils.java
/** * @param basePath/*from w ww.ja v a2 s . co m*/ * @param tarPath * @param filePaths * @throws java.io.IOException */ public static void tar(String basePath, String tarPath, Map<String, String> filePaths) throws IOException { BufferedInputStream origin = null; TarArchiveOutputStream out = null; FileOutputStream dest = null; try { dest = new FileOutputStream(tarPath); out = new TarArchiveOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[BUFFER]; for (Map.Entry<String, String> entryFile : filePaths.entrySet()) { String filename = entryFile.getKey(); String filePath = entryFile.getValue(); System.out.println("Adding: " + filename + " => " + filePath); FileInputStream fi = new FileInputStream(basePath + filePath); origin = new BufferedInputStream(fi, BUFFER); TarArchiveEntry entry = new TarArchiveEntry(filename); out.putArchiveEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } } catch (Exception e) { e.printStackTrace(); } finally { if (origin != null) origin.close(); if (out != null) out.close(); if (dest != null) dest.close(); } }
From source file:com.ibm.util.merge.storage.TarArchive.java
@Override public String writeFile(String entryName, String content, String userName, String groupName) throws IOException, MergeException { String chksum = super.writeFile(entryName, content, userName, groupName); TarArchiveOutputStream outputStream = (TarArchiveOutputStream) this.getOutputStream(); TarArchiveEntry entry = new TarArchiveEntry(entryName); entry.setSize(content.getBytes().length); entry.setNames(userName, groupName); outputStream.putArchiveEntry(entry); outputStream.write(content.getBytes()); outputStream.flush();//from ww w. j a v a2s. co m outputStream.closeArchiveEntry(); return chksum; }
From source file:com.espringtran.compressor4j.processor.TarProcessor.java
/** * Compress data/*w ww .j a v a2s. co m*/ * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TarArchiveOutputStream aos = new TarArchiveOutputStream(baos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { TarArchiveEntry entry = new TarArchiveEntry(binaryFile.getDesPath()); entry.setSize(binaryFile.getActualSize()); aos.putArchiveEntry(entry); aos.write(binaryFile.getData()); aos.closeArchiveEntry(); } aos.flush(); aos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { aos.close(); baos.close(); } return baos.toByteArray(); }
From source file:co.cask.cdap.internal.app.runtime.LocalizationUtilsTest.java
private void addFilesToTar(TarArchiveOutputStream tos, File... filesToAdd) throws IOException { for (File file : filesToAdd) { TarArchiveEntry tarEntry = new TarArchiveEntry(file); tos.putArchiveEntry(tarEntry); if (file.isFile()) { com.google.common.io.Files.copy(file, tos); }/*w w w . jav a2s . co m*/ tos.closeArchiveEntry(); } }
From source file:com.espringtran.compressor4j.processor.TarBz2Processor.java
/** * Compress data/*from ww w .j a va2s.c o m*/ * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos); TarArchiveOutputStream aos = new TarArchiveOutputStream(cos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { TarArchiveEntry entry = new TarArchiveEntry(binaryFile.getDesPath()); entry.setSize(binaryFile.getActualSize()); aos.putArchiveEntry(entry); aos.write(binaryFile.getData()); aos.closeArchiveEntry(); } aos.flush(); aos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { aos.close(); cos.close(); baos.close(); } return baos.toByteArray(); }
From source file:com.espringtran.compressor4j.processor.TarGzProcessor.java
/** * Compress data//from w ww . ja v a 2 s . c o m * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GzipCompressorOutputStream cos = new GzipCompressorOutputStream(baos); TarArchiveOutputStream aos = new TarArchiveOutputStream(cos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { TarArchiveEntry entry = new TarArchiveEntry(binaryFile.getDesPath()); entry.setSize(binaryFile.getActualSize()); aos.putArchiveEntry(entry); aos.write(binaryFile.getData()); aos.closeArchiveEntry(); } aos.flush(); aos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { aos.close(); cos.close(); baos.close(); } return baos.toByteArray(); }
From source file:com.espringtran.compressor4j.processor.XzProcessor.java
/** * Compress data// ww w. j a v a 2 s .c o m * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XZCompressorOutputStream cos = new XZCompressorOutputStream(baos); TarArchiveOutputStream aos = new TarArchiveOutputStream(cos); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { TarArchiveEntry entry = new TarArchiveEntry(binaryFile.getDesPath()); entry.setSize(binaryFile.getActualSize()); aos.putArchiveEntry(entry); aos.write(binaryFile.getData()); aos.closeArchiveEntry(); } aos.flush(); aos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { aos.close(); cos.close(); baos.close(); } return baos.toByteArray(); }
From source file:de.uzk.hki.da.pkg.TarGZArchiveBuilder.java
/** * @param tOut/*from w ww. ja v a2 s . c om*/ * @param the actual file that should be added * @param base * @throws IOException */ private void addFileToTarGZ(TarArchiveOutputStream tOut, File file, String base) throws IOException { String entryName = base + file.getName(); logger.debug("addFileToTarGZ: " + entryName); TarArchiveEntry entry = (TarArchiveEntry) tOut.createArchiveEntry(file, entryName); tOut.putArchiveEntry(entry); if (file.isFile()) { FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, tOut); tOut.closeArchiveEntry(); fis.close(); } if (file.isDirectory()) { tOut.closeArchiveEntry(); File children[] = file.listFiles(); if (children == null) return; for (int i = 0; i < children.length; i++) { addFileToTarGZ(tOut, children[i], entryName + "/"); } } }
From source file:algorithm.TarPackaging.java
private void archiveFile(File carrier, TarArchiveOutputStream tarOutputStream) throws IOException, FileNotFoundException { TarArchiveEntry tarEntry = new TarArchiveEntry(carrier, carrier.getName()); tarOutputStream.putArchiveEntry(tarEntry); FileInputStream inputStream = new FileInputStream(carrier); IOUtils.copy(inputStream, tarOutputStream); tarOutputStream.closeArchiveEntry(); inputStream.close();//from w w w . jav a 2 s.c o m }