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


Java GZIPOutputStream.close方法代碼示例

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


在下文中一共展示了GZIPOutputStream.close方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: compressGzipFile

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
public static String compressGzipFile(String file, String gzipFile) {
    try {
        FileInputStream fis = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream(gzipFile);
        GZIPOutputStream gzipOS = new GZIPOutputStream(fos);
        byte[] buffer = new byte[1024];
        int len;
        while((len=fis.read(buffer)) != -1){
            gzipOS.write(buffer, 0, len);
        }
        //close resources
        gzipOS.close();
        fos.close();
        fis.close();
        System.out.println("A json.gz file was created: " + gzipFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return gzipFile;
}
 
開發者ID:michael-hll,項目名稱:BigQueryStudy,代碼行數:21,代碼來源:GZipHelper.java

示例3: 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:dremio,項目名稱:dremio-oss,代碼行數:19,代碼來源:TestJsonReader.java

示例4: compress

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
/**
 * Compresses given Packet. Note that this can increase the total size when used incorrectly
 * @param packet Packet to compress
 * @return Compressed Packet
 * @throws IOException when unable to compress
 */
public static Packet compress(final Packet packet) throws IOException
{
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream)
    {
        {
            def.setLevel(Deflater.BEST_COMPRESSION);
        }
    };

    // Deflate all data
    gzipOutputStream.write(packet.getData());
    gzipOutputStream.close();

    return new Packet(
            packet.getPacketType(),
            packet.getPacketID(),
            byteArrayOutputStream.toByteArray()
    );
}
 
開發者ID:PvdBerg1998,項目名稱:PNet,代碼行數:27,代碼來源:PacketCompressor.java

示例5: i

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
private String i(String str) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes());
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    String str2 = null;
    try {
        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        byte[] bArr = new byte[1024];
        while (true) {
            int read = byteArrayInputStream.read(bArr, 0, 1024);
            if (read == -1) {
                break;
            }
            gZIPOutputStream.write(bArr, 0, read);
        }
        gZIPOutputStream.flush();
        gZIPOutputStream.close();
        byte[] toByteArray = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.flush();
        byteArrayOutputStream.close();
        byteArrayInputStream.close();
        str2 = Base64.encodeToString(toByteArray, 2);
    } catch (Throwable e) {
        Ln.e(e);
    }
    return str2;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:27,代碼來源:a.java

示例6: 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

示例7: 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

示例8: compress

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
/**
 * Gzips the given String.
 *
 * @param str The string to gzip.
 * @return The gzipped String.
 * @throws IOException If the compression failed.
 */
private static byte[] compress(final String str) throws IOException {
    if (str == null) {
        return null;
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
    gzip.write(str.getBytes("UTF-8"));
    gzip.close();
    return outputStream.toByteArray();
}
 
開發者ID:JustBru00,項目名稱:EpicBanRequests,代碼行數:18,代碼來源:Metrics.java

示例9: compressAndBase64EncodeToBytes

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
public static byte[] compressAndBase64EncodeToBytes(byte inBytes[]) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream((int)(inBytes.length * .7));
        GZIPOutputStream gzos = new GZIPOutputStream(baos);
        gzos.write(inBytes);
        gzos.close();
        byte[] outBytes = baos.toByteArray();
        return Base64.encodeBytesToBytes(outBytes);
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:15,代碼來源:Encoder.java

示例10: compressAndBase64EncodeToBytes

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
public static byte[] compressAndBase64EncodeToBytes(String string) {
    try {
        byte[] inBytes = string.getBytes("UTF-8");
        ByteArrayOutputStream baos = new ByteArrayOutputStream((int)(string.length() * 0.7));
        GZIPOutputStream gzos = new GZIPOutputStream(baos);
        gzos.write(inBytes);
        gzos.close();
        byte[] outBytes = baos.toByteArray();
        return Base64.encodeBytesToBytes(outBytes);
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:16,代碼來源:Encoder.java

示例11: compress

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
private static byte[] compress(byte[] data) throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length)) {
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bos);
        gzipOutputStream.write(data);
        gzipOutputStream.close();
        return bos.toByteArray();
    }
}
 
開發者ID:patrickfav,項目名稱:dice,代碼行數:9,代碼來源:CompressionTest.java

示例12: 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

示例13: run

import java.util.zip.GZIPOutputStream; //導入方法依賴的package包/類
@Override
public void run() {
    for (;;) {
        if (mic.available() >= SoundPacket.defaultDataLenght) { //we got enough data to send
            byte[] buff = new byte[SoundPacket.defaultDataLenght];
            while (mic.available() >= SoundPacket.defaultDataLenght) { //flush old data from mic to reduce lag, and read most recent data
                mic.read(buff, 0, buff.length); //read from microphone
            }
            try {
                //this part is used to decide whether to send or not the packet. if volume is too low, an empty packet will be sent and the remote client will play some comfort noise
                long tot = 0;
                for (int i = 0; i < buff.length; i++) {
                    buff[i] *= amplification;
                    tot += Math.abs(buff[i]);
                }
                tot *= 2.5;
                tot /= buff.length;
                //create and send packet
                Message m = null;
                if (tot == 0) {//send empty packet
                    m = new Message(-1, -1, new SoundPacket(null));
                } else { //send data
                    //compress the sound packet with GZIP
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    GZIPOutputStream go = new GZIPOutputStream(baos);
                    go.write(buff);
                    go.flush();
                    go.close();
                    baos.flush();
                    baos.close();
                    m = new Message(-1, -1, new SoundPacket(baos.toByteArray()));  //create message for server, will generate chId and timestamp from this computer's IP and this socket's port 
                }
                toServer.writeObject(m); //send message
            } catch (IOException ex) { //connection error
                stop();
            }
        } else {
            Utils.sleep(10); //sleep to avoid busy wait
        }
    }
}
 
開發者ID:lucas-dolsan,項目名稱:tcc-rpg,代碼行數:42,代碼來源:MicThread.java


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