当前位置: 首页>>代码示例>>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;未经允许,请勿转载。