当前位置: 首页>>代码示例>>Java>>正文


Java GZIPOutputStream.finish方法代码示例

本文整理汇总了Java中java.util.zip.GZIPOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java GZIPOutputStream.finish方法的具体用法?Java GZIPOutputStream.finish怎么用?Java GZIPOutputStream.finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.GZIPOutputStream的用法示例。


在下文中一共展示了GZIPOutputStream.finish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public byte[] compress( final byte[] data , final int start , final int length ) throws IOException{
  ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  GZIPOutputStream out = new GZIPOutputStream( bOut );

  out.write( data , start , length );
  out.flush();
  out.finish();
  byte[] compressByte = bOut.toByteArray();
  byte[] retVal = new byte[ Integer.BYTES + compressByte.length ];
  ByteBuffer wrapBuffer = ByteBuffer.wrap( retVal );
  wrapBuffer.putInt( length );
  wrapBuffer.put( compressByte );

  bOut.close();
  out.close();

  return retVal;
}
 
开发者ID:yahoojapan,项目名称:multiple-dimension-spread,代码行数:20,代码来源:GzipCompressor.java

示例2: gzipFile

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private File gzipFile(File src) throws IOException {
    // Never try to make it stream-like on the fly, because content-length still required
    // Create the GZIP output stream
    String outFilename = src.getAbsolutePath() + ".gz";
    notifier.notifyAbout("Gzipping " + src.getAbsolutePath());
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename), 1024 * 8, true);

    // Open the input file
    FileInputStream in = new FileInputStream(src);

    // Transfer bytes from the input file to the GZIP output stream
    byte[] buf = new byte[10240];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    // Complete the GZIP file
    out.finish();
    out.close();

    src.delete();

    return new File(outFilename);
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:27,代码来源:LoadosophiaAPIClient.java

示例3: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * 数据压缩
 *
 * @param is
 * @param os
 * @throws Exception
 */
public static void compress(InputStream is, OutputStream os)
        throws Exception {

    GZIPOutputStream gos = new GZIPOutputStream(os);

    int count;
    byte data[] = new byte[BUFFER];
    while ((count = is.read(data, 0, BUFFER)) != -1) {
        gos.write(data, 0, count);
    }

    gos.finish();

    gos.flush();
    gos.close();
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:24,代码来源:GZipUtils.java

示例4: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static final byte[] compress(byte[] bytes)
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
    {
        GZIPOutputStream gzip = new GZIPOutputStream(baos);
        gzip.write(bytes, 0, bytes.length);
        gzip.finish();
        byte[] fewerBytes = baos.toByteArray();
        gzip.close();
        baos.close();
        gzip = null;
        baos = null;
        return fewerBytes;
    }
    catch (IOException e)
    {
        throw new FacesException(e);
    }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:21,代码来源:StateUtils.java

示例5: gzipIt

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static void gzipIt(File sourceFile) throws IOException {

    // modified from: http://www.mkyong.com/java/how-to-compress-a-file-in-gzip-format/
    byte[] buffer = new byte[1024];
    GZIPOutputStream gzos =
        new GZIPOutputStream(new FileOutputStream(sourceFile.getPath() + ".gz"));

    FileInputStream in =
        new FileInputStream(sourceFile);

    int len;
    while ((len = in.read(buffer)) > 0) {
      gzos.write(buffer, 0, len);
    }
    in.close();
    gzos.finish();
    gzos.close();
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:19,代码来源:TestJsonReader.java

示例6: gZip

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] gZip(byte[] data) {
    byte[] b = null;
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(bos);
        gzip.write(data);
        gzip.finish();
        gzip.close();
        b = bos.toByteArray();
        bos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:16,代码来源:GzipUtils.java

示例7: uploadGZFile

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private static void uploadGZFile(PrintStream os, File f) throws IOException {
    GZIPOutputStream gzip = new GZIPOutputStream(os);
    try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(f))) {
        byte[] buffer = new byte[4096];
        int readLength = is.read(buffer);
        while (readLength != -1){
            gzip.write(buffer, 0, readLength);
            readLength = is.read(buffer);
        }
    } finally {
        gzip.finish();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:Installer.java

示例8: sendBodyWithCorrectEncoding

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private void sendBodyWithCorrectEncoding(OutputStream outputStream, long pending) throws IOException {
    if (encodeAsGzip) {
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream);
        sendBody(gzipOutputStream, -1);
        gzipOutputStream.finish();
    } else {
        sendBody(outputStream, pending);
    }
}
 
开发者ID:ZavixDragon,项目名称:LiteJavaWebsite,代码行数:10,代码来源:NanoHTTPD.java

示例9: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] compress(byte[] data) throws IOException {  
    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    GZIPOutputStream gos = new GZIPOutputStream(baos);// 压缩
    gos.write(data, 0, data.length);  
    gos.finish();
    byte[] output = baos.toByteArray();  
    baos.flush();  
    baos.close();
    return output;  
}
 
开发者ID:penggle,项目名称:xproject,代码行数:11,代码来源:GZipUtils.java

示例10: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Compresses file from given filePath into a gzipPath
 *
 * @param filePath The file to be compressed
 * @param gzipPath The path to compress to (.gz)
 * @return The result
 */
public static boolean compress(Path filePath, Path gzipPath) {
    byte[] buffer = new byte[1024];

    try {
        FileOutputStream fos = new FileOutputStream(gzipPath.toString());
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        FileInputStream in = new FileInputStream(filePath.toString());

        int len;
        while((len = in.read(buffer)) > 0){
            gzos.write(buffer, 0, len);
        }

        in.close();

        gzos.finish();
        gzos.close();
        fos.close();
        return true;
    }
    catch(IOException ex) {
        System.err.println("Exception while compressing '" + filePath.toString() + "':");
        ex.printStackTrace();
    }
    return false;
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:34,代码来源:GzipUtil.java

示例11: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * 数据压缩
 * @param is
 * @param os
 * @throws Exception
 */
public static void compress(InputStream is, OutputStream os) throws Exception {
	GZIPOutputStream gos = new GZIPOutputStream(os);
	int count;
	byte data[] = new byte[BUFFER];
	while ((count = is.read(data, 0, BUFFER)) != -1) {
		gos.write(data, 0, count);
	}
	gos.finish();
	gos.flush();
	gos.close();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:18,代码来源:GZipUtils.java

示例12: write

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public void write(OutputStream out) throws IOException {
	// TEMP: just use the object output for now. We can find a more efficient storage format later
	GZIPOutputStream gzipout = new GZIPOutputStream(out);
	ObjectOutputStream oout = new ObjectOutputStream(gzipout);
	oout.writeObject(this);
	gzipout.finish();
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:8,代码来源:MappingsRenamer.java

示例13: write

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public void write(OutputStream out)
throws IOException {
	GZIPOutputStream gzipout = new GZIPOutputStream(out);
	ObjectOutputStream oout = new ObjectOutputStream(gzipout);
	oout.writeObject(m_superclasses);
	oout.writeObject(m_fieldEntries);
	oout.writeObject(m_behaviorEntries);
	gzipout.finish();
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:10,代码来源:TranslationIndex.java

示例14: afterResponse

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpContent httpContent,
    HttpProxyInterceptPipeline pipeline) throws Exception {
  if (isMatch) {
    try {
      contentBuf.writeBytes(httpContent.content());
      if (httpContent instanceof LastHttpContent) {
        ByteUtil.insertText(contentBuf,ByteUtil.findText(contentBuf,"<head>"),hookResponse());
        HttpContent hookHttpContent = new DefaultLastHttpContent();
        if (isGzip) { //转化成gzip编码
          byte[] temp = new byte[contentBuf.readableBytes()];
          contentBuf.readBytes(temp);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          GZIPOutputStream outputStream = new GZIPOutputStream(baos);
          outputStream.write(temp);
          outputStream.finish();
          hookHttpContent.content().writeBytes(baos.toByteArray());
        } else {
          hookHttpContent.content().writeBytes(contentBuf);
        }
        pipeline.getDefault()
            .afterResponse(clientChannel, proxyChannel, hookHttpContent, pipeline);
      }
    } finally {
      ReferenceCountUtil.release(httpContent);
    }
  } else {
    pipeline.afterResponse(clientChannel, proxyChannel, httpContent);
  }
}
 
开发者ID:monkeyWie,项目名称:proxyee-down,代码行数:31,代码来源:ResponseTextIntercept.java

示例15: doTest

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private static void doTest(final boolean appendGarbage,
                           final boolean limitGISBuff)
        throws Throwable {

    byte[] buf;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ZipOutputStream zos = new ZipOutputStream(baos)) {

        final byte[] xbuf = { 'x' };

        zos.putNextEntry(new ZipEntry("a.gz"));
        GZIPOutputStream gos1 = new GZIPOutputStream(zos);
        gos1.write(xbuf);
        gos1.finish();
        if (appendGarbage)
            zos.write(xbuf);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("b.gz"));
        GZIPOutputStream gos2 = new GZIPOutputStream(zos);
        gos2.write(xbuf);
        gos2.finish();
        zos.closeEntry();

        zos.flush();
        buf = baos.toByteArray();
    }

    try (ByteArrayInputStream bais = new ByteArrayInputStream(buf);
         ZipInputStream zis = new ZipInputStream(bais)) {

        zis.getNextEntry();
        GZIPInputStream gis1 = limitGISBuff ?
                new GZIPInputStream(zis, 4) :
                new GZIPInputStream(zis);
        // try to read more than the entry has
        gis1.skip(2);

        try {
            zis.getNextEntry();
        } catch (IOException e) {
            throw new RuntimeException("ZIP stream was prematurely closed", e);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:GZIPInZip.java


注:本文中的java.util.zip.GZIPOutputStream.finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。