當前位置: 首頁>>代碼示例>>Java>>正文


Java GzipCompressorOutputStream.close方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java GzipCompressorOutputStream.close方法的具體用法?Java GzipCompressorOutputStream.close怎麽用?Java GzipCompressorOutputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream的用法示例。


在下文中一共展示了GzipCompressorOutputStream.close方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: charsEncodeAndCompress

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
public static byte[] charsEncodeAndCompress(CharSequence v) {	
	try {
		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;
}
 
開發者ID:Gadreel,項目名稱:divconq,代碼行數:18,代碼來源:IOUtil.java

示例2: compressData

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
/**
 * Compress data
 * 
 * @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();
}
 
開發者ID:espringtran,項目名稱:compressor4j,代碼行數:35,代碼來源:TarGzProcessor.java

示例3: compressData

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GzipCompressorOutputStream cos = new GzipCompressorOutputStream(baos);
    ZipOutputStream zos = new ZipOutputStream(cos);
    try {
        zos.setLevel(fileCompressor.getLevel().getValue());
        zos.setMethod(ZipOutputStream.DEFLATED);
        zos.setComment(fileCompressor.getComment());
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            zos.putNextEntry(new ZipEntry(binaryFile.getDesPath()));
            zos.write(binaryFile.getData());
            zos.closeEntry();
        }
        zos.flush();
        zos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        zos.close();
        cos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
開發者ID:espringtran,項目名稱:compressor4j,代碼行數:35,代碼來源:GzipProcessor.java

示例4: gzip

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
public static void gzip(File f, File gzf) throws Throwable {

		BufferedInputStream is = new BufferedInputStream(new FileInputStream(f), BUFFER_SIZE);
		GzipCompressorOutputStream os = new GzipCompressorOutputStream(new BufferedOutputStream(new FileOutputStream(
				gzf), BUFFER_SIZE));
		try {
			IOUtils.copy(is, os, BUFFER_SIZE);
			os.flush();
		} finally {
			os.close();
			is.close();
		}
	}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:14,代碼來源:GzipUtil.java

示例5: createLargeFile

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
protected void createLargeFile(String path, final String name) throws Exception {
    final long _1K = 1024;
    final long _1M = 1024 * _1K;
//    long _256M = 256 * _1M;
//    long _512M = 512 * _1M;
    final long _1G = 1024 * _1M;

    // File size of 3 GB
    final long fileSize = 3 * _1G;

    File tarGzFile = new File(path + name + ".tar.gz");

    if(!tarGzFile.exists()) {
      System.out.println("This test is a bit slow. It needs to write 3GB of data as a compressed file (approx. 3MB) to your hard drive");

      final PipedOutputStream outTarFileStream = new PipedOutputStream();
      PipedInputStream inTarFileStream = new PipedInputStream(outTarFileStream);

      Thread source = new Thread(){

        @Override
        public void run() {
            byte ba_1k[] = new byte[(int) _1K];
            for(int i=0; i < ba_1k.length; i++){
                ba_1k[i]='a';
            }
            try {
                TarArchiveOutputStream outTarStream =
                    (TarArchiveOutputStream)new ArchiveStreamFactory()
                    .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);
                // Create archive contents
                TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
                tarArchiveEntry.setSize(fileSize);

                outTarStream.putArchiveEntry(tarArchiveEntry);
                for(long i = 0; i < fileSize; i+= ba_1k.length) {
                    outTarStream.write(ba_1k);
                }
                outTarStream.closeArchiveEntry();
                outTarStream.close();
                outTarFileStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

      };
      source.start();

      // Create compressed archive
      OutputStream outGzipFileStream = new FileOutputStream(path + name + ".tar.gz");

      GzipCompressorOutputStream outGzipStream = (GzipCompressorOutputStream)new CompressorStreamFactory()
      .createCompressorOutputStream(CompressorStreamFactory.GZIP, outGzipFileStream);

      IOUtils.copy(inTarFileStream, outGzipStream);
      inTarFileStream.close();

      outGzipStream.close();
      outGzipFileStream.close();

    }
  }
 
開發者ID:wso2,項目名稱:wso2-commons-vfs,代碼行數:64,代碼來源:LargeTarTestCase.java

示例6: createLargeFile

import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; //導入方法依賴的package包/類
@SuppressWarnings("unused")
protected void createLargeFile(String path, String name) throws Exception {
  long _1K = 1024;
  long _1M = 1024 * _1K;
  long _256M = 256 * _1M;
  long _512M = 512 * _1M;
  long _1G = 1024 * _1M;
  
  // File size of 3 GB
  long fileSize = 3 * _1G;
  
  File tarGzFile = new File(path + name + ".tar.gz");
  
  if(!tarGzFile.exists()) {

    // Create archive
    OutputStream outTarFileStream = new FileOutputStream(path + name + ".tar");

    TarArchiveOutputStream outTarStream = (TarArchiveOutputStream)new ArchiveStreamFactory()
    .createArchiveOutputStream(ArchiveStreamFactory.TAR, outTarFileStream);

    // Create archive contents
    TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(name + ".txt");
    tarArchiveEntry.setSize(fileSize);
    
    outTarStream.putArchiveEntry(tarArchiveEntry);
    for(long i = 0; i < fileSize; i++) {
      outTarStream.write('a');
    }
    
    outTarStream.closeArchiveEntry();
    outTarStream.close();
    
    outTarFileStream.close();
    
    // Create compressed archive
    OutputStream outGzipFileStream = new FileOutputStream(path + name + ".tar.gz");
    
    GzipCompressorOutputStream outGzipStream = (GzipCompressorOutputStream)new CompressorStreamFactory()
    .createCompressorOutputStream(CompressorStreamFactory.GZIP, outGzipFileStream);
    
    // Compress archive
    InputStream inTarFileStream = new FileInputStream(path + name + ".tar");
    // TODO: Change to a Piped Stream to conserve disk space
    IOUtils.copy(inTarFileStream, outGzipStream);
    inTarFileStream.close();
    
    outGzipStream.close();
    outGzipFileStream.close();      
    
    // Cleanup original tar
    File tarFile = new File(path + name + ".tar");
    if(tarFile.exists()) {
      tarFile.delete();
    }
  }      
}
 
開發者ID:pentaho,項目名稱:pdi-vfs,代碼行數:58,代碼來源:LargeTarTestCase.java


注:本文中的org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。