本文整理汇总了Java中java.util.zip.Deflater.setStrategy方法的典型用法代码示例。如果您正苦于以下问题:Java Deflater.setStrategy方法的具体用法?Java Deflater.setStrategy怎么用?Java Deflater.setStrategy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Deflater
的用法示例。
在下文中一共展示了Deflater.setStrategy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}