當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。