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


Java Deflater.setLevel方法代碼示例

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


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

示例1: compress

import java.util.zip.Deflater; //導入方法依賴的package包/類
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {

    ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

    Deflater compressor = new Deflater();

    try {
      compressor.setLevel(compressionLevel); // 將當前壓縮級別設置為指定值。
      compressor.setInput(value, offset, length);
      compressor.finish(); // 調用時,指示壓縮應當以輸入緩衝區的當前內容結尾。

      // Compress the data
      final byte[] buf = new byte[1024];
      while (!compressor.finished()) {
        // 如果已到達壓縮數據輸出流的結尾,則返回 true。
        int count = compressor.deflate(buf);
        // 使用壓縮數據填充指定緩衝區。
        bos.write(buf, 0, count);
      }
    } finally {
      compressor.end(); // 關閉解壓縮器並放棄所有未處理的輸入。
    }

    return bos.toByteArray();
  }
 
開發者ID:MUFCRyan,項目名稱:BilibiliClient,代碼行數:26,代碼來源:BiliDanmukuCompressionTools.java

示例2: compress

import java.util.zip.Deflater; //導入方法依賴的package包/類
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel)
{

    ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

    Deflater compressor = new Deflater();

    try
    {
        compressor.setLevel(compressionLevel); // 將當前壓縮級別設置為指定值。
        compressor.setInput(value, offset, length);
        compressor.finish(); // 調用時,指示壓縮應當以輸入緩衝區的當前內容結尾。

        // Compress the data
        final byte[] buf = new byte[1024];
        while (!compressor.finished())
        {
            // 如果已到達壓縮數據輸出流的結尾,則返回 true。
            int count = compressor.deflate(buf);
            // 使用壓縮數據填充指定緩衝區。
            bos.write(buf, 0, count);
        }
    } finally
    {
        compressor.end(); // 關閉解壓縮器並放棄所有未處理的輸入。
    }

    return bos.toByteArray();
}
 
開發者ID:WeDevelopTeam,項目名稱:HeroVideo-master,代碼行數:30,代碼來源:BiliDanmukuCompressionTools.java

示例3: divineDeflateParameters

import java.util.zip.Deflater; //導入方法依賴的package包/類
/**
 * Determines the original {@link JreDeflateParameters} that were used to compress a given piece
 * of deflated delivery.
 *
 * @param compressedDataInputStreamFactory a {@link MultiViewInputStreamFactory} that can provide
 *     multiple independent {@link InputStream} instances for the compressed delivery.
 * @return the parameters that can be used to replicate the compressed delivery in the {@link
 *     DefaultDeflateCompatibilityWindow}, if any; otherwise <code>null</code>. Note that <code>
 *     null</code> is also returned in the case of <em>corrupt</em> zip delivery since, by definition,
 *     it cannot be replicated via any combination of normal deflate parameters.
 * @throws IOException if there is a problem reading the delivery, i.e. if the file contents are
 *     changed while reading
 */
public JreDeflateParameters divineDeflateParameters(
    MultiViewInputStreamFactory compressedDataInputStreamFactory) throws IOException {
  byte[] copyBuffer = new byte[32 * 1024];
  // Iterate over all relevant combinations of nowrap, strategy and level.
  for (boolean nowrap : new boolean[] {true, false}) {
    Inflater inflater = new Inflater(nowrap);
    Deflater deflater = new Deflater(0, nowrap);

    strategy_loop:
    for (int strategy : new int[] {0, 1, 2}) {
      deflater.setStrategy(strategy);
      for (int level : LEVELS_BY_STRATEGY.get(strategy)) {
        deflater.setLevel(level);
        inflater.reset();
        deflater.reset();
        try {
          if (matches(inflater, deflater, compressedDataInputStreamFactory, copyBuffer)) {
            end(inflater, deflater);
            return JreDeflateParameters.of(level, strategy, nowrap);
          }
        } catch (ZipException e) {
          // Parse error in input. The only possibilities are corruption or the wrong nowrap.
          // Skip all remaining levels and strategies.
          break strategy_loop;
        }
      }
    }
    end(inflater, deflater);
  }
  return null;
}
 
開發者ID:lizhangqu,項目名稱:CorePatch,代碼行數:45,代碼來源:DefaultDeflateCompressionDiviner.java

示例4: compress

import java.util.zip.Deflater; //導入方法依賴的package包/類
/** Compresses the specified byte range using the
 *  specified compressionLevel (constants are defined in
 *  java.util.zip.Deflater). */
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {

  /* Create an expandable byte array to hold the compressed data.
   * You cannot use an array that's the same size as the orginal because
   * there is no guarantee that the compressed data will be smaller than
   * the uncompressed data. */
  ByteArrayOutputStream bos = new ByteArrayOutputStream(length);

  Deflater compressor = new Deflater();

  try {
    compressor.setLevel(compressionLevel);
    compressor.setInput(value, offset, length);
    compressor.finish();

    // Compress the data
    final byte[] buf = new byte[1024];
    while (!compressor.finished()) {
      int count = compressor.deflate(buf);
      bos.write(buf, 0, count);
    }
  } finally {
    compressor.end();
  }

  return bos.toByteArray();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:CompressionTools.java


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