List of usage examples for org.apache.commons.compress.compressors.gzip GzipCompressorOutputStream close
public void close() throws IOException
From source file:divconq.util.IOUtil.java
public static byte[] charsEncodeAndCompress(CharSequence v) { try {/*from w w w . j a v a 2s.c o m*/ byte[] buffer = Utf8Encoder.encode(v); ByteArrayOutputStream bos = new ByteArrayOutputStream(); GzipCompressorOutputStream cos = new GzipCompressorOutputStream(bos); cos.write(buffer); cos.close(); bos.close(); return bos.toByteArray(); } catch (Exception x) { } return null; }
From source file:msec.org.GzipUtil.java
static public void zip(String srcFile, String destFile) throws Exception { GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(destFile)); FileInputStream in = new FileInputStream(srcFile); byte[] buf = new byte[10240]; while (true) { int len = in.read(buf); if (len <= 0) { break; }// www. jav a 2 s .co m out.write(buf, 0, len); } out.flush(); out.close(); in.close(); }
From source file:msec.org.GzipUtil.java
static public void zip(String srcFile) throws Exception { GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(srcFile + ".gz")); FileInputStream in = new FileInputStream(srcFile); byte[] buf = new byte[10240]; while (true) { int len = in.read(buf); if (len <= 0) { break; }/* www . j a v a 2 s .com*/ out.write(buf, 0, len); } out.flush(); out.close(); in.close(); }
From source file:com.ipcglobal.fredimport.util.FredUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the specified directory. * * @param directoryPath the directory path * @param tarGzPath the tar gz path/*from w w w. j a v a2 s .c o m*/ * @throws IOException If anything goes wrong */ public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; try { fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); addFileToTarGz(tOut, directoryPath, "/"); } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } }
From source file:com.linkedin.thirdeye.bootstrap.util.TarGzCompressionUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the * specified directory./*from w ww . ja va 2 s . c o m*/ * * @param dirPath * The path to the directory to create an archive of * @param archivePath * The path to the archive to create * * @throws IOException * If anything goes wrong */ public static void createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; try { fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); addFileToTarGz(tOut, directoryPath, ""); } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } }
From source file:com.linkedin.pinot.common.utils.TarGzCompressionUtils.java
/** * Creates a tar.gz file at the specified path with the contents of the * specified directory.// w ww . j a v a2s. c o m * * @param directoryPath * The path to the directory to create an archive of * @param tarGzPath * The path to the archive to create * @return tarGzPath * @throws IOException * If anything goes wrong */ public static String createTarGzOfDirectory(String directoryPath, String tarGzPath) throws IOException { FileOutputStream fOut = null; BufferedOutputStream bOut = null; GzipCompressorOutputStream gzOut = null; TarArchiveOutputStream tOut = null; if (!tarGzPath.endsWith(TAR_GZ_FILE_EXTENTION)) { tarGzPath = tarGzPath + TAR_GZ_FILE_EXTENTION; } try { fOut = new FileOutputStream(new File(tarGzPath)); bOut = new BufferedOutputStream(fOut); gzOut = new GzipCompressorOutputStream(bOut); tOut = new TarArchiveOutputStream(gzOut); tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); addFileToTarGz(tOut, directoryPath, ""); } finally { tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } return tarGzPath; }
From source file:frameworks.Masken.java
public static void CreateTarGZ(String dirPath, String tarGzPath) { FileOutputStream fOut = null; try {//w w w. j a va 2s . c o m System.out.println(new File(".").getAbsolutePath()); // dirPath = "parent/childDirToCompress/"; // tarGzPath = "archive.tar.gz"; fOut = new FileOutputStream(new File(tarGzPath)); BufferedOutputStream bOut = new BufferedOutputStream(fOut); GzipCompressorOutputStream gzOut = new GzipCompressorOutputStream(bOut); TarArchiveOutputStream tOut = new TarArchiveOutputStream(gzOut); addFileToTarGz(tOut, dirPath, ""); tOut.finish(); tOut.close(); gzOut.close(); bOut.close(); fOut.close(); } catch (FileNotFoundException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fOut.close(); } catch (IOException ex) { Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:eu.eubrazilcc.lvl.core.io.FileCompressor.java
/** * Creates a tarball from the source directory and writes it into the target directory. * @param srcDir - directory whose files will be added to the tarball * @param targetName - directory where tarball will be written to * @throws IOException when an exception occurs on creating the tarball *//*ww w .j a v a 2 s. co m*/ public static void tarGzipDir(final String srcDir, final String targetName) throws IOException { FileOutputStream fileOutputStream = null; BufferedOutputStream bufferedOutputStream = null; GzipCompressorOutputStream gzipOutputStream = null; TarArchiveOutputStream tarArchiveOutputStream = null; try { forceMkdir(new File(getFullPath(targetName))); fileOutputStream = new FileOutputStream(new File(targetName)); bufferedOutputStream = new BufferedOutputStream(fileOutputStream); gzipOutputStream = new GzipCompressorOutputStream(bufferedOutputStream); tarArchiveOutputStream = new TarArchiveOutputStream(gzipOutputStream); addFilesInDirectory(tarArchiveOutputStream, srcDir); } finally { if (tarArchiveOutputStream != null) { tarArchiveOutputStream.finish(); } if (tarArchiveOutputStream != null) { tarArchiveOutputStream.close(); } if (gzipOutputStream != null) { gzipOutputStream.close(); } if (bufferedOutputStream != null) { bufferedOutputStream.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } }
From source file:com.mobilesorcery.sdk.builder.linux.deb.BuilderUtil.java
/** * Adds a directory structure to a gzipped tar. * * @param o The output file that the tar+gz will be written to * @param i The directory to add/*from ww w.j av a 2s . c om*/ * * @throws IOException If there's an I/O error */ public void tarGZipDirectory(File o, File i) throws IOException { FileOutputStream fos = new FileOutputStream(o); GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(fos); TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos); // Recursivly add to tar doAddFileToTar(tos, "./", i); // Close tos.close(); gzos.close(); fos.close(); }
From source file:com.chenshu.compress.CompressOldTest.java
@Benchmark public int commonsGzipCompress() { ByteArrayOutputStream bout = null; GzipCompressorOutputStream gzout = null; try {/*from w ww .ja va 2 s . c om*/ GzipParameters p = new GzipParameters(); p.setCompressionLevel(level); bout = new ByteArrayOutputStream(data.length); gzout = new GzipCompressorOutputStream(bout, p); gzout.write(data); } catch (IOException e) { e.printStackTrace(); } finally { if (gzout != null) { try { gzout.close(); } catch (IOException e) { e.printStackTrace(); } } if (bout != null) { try { bout.close(); } catch (IOException e) { e.printStackTrace(); } } } byte[] bs = bout.toByteArray(); return bs.length; }