本文整理汇总了Java中java.util.zip.Deflater.needsInput方法的典型用法代码示例。如果您正苦于以下问题:Java Deflater.needsInput方法的具体用法?Java Deflater.needsInput怎么用?Java Deflater.needsInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Deflater
的用法示例。
在下文中一共展示了Deflater.needsInput方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpFlate
import java.util.zip.Deflater; //导入方法依赖的package包/类
/** Write the entire content into the given file using Flate compression (see RFC1951) then return the number of bytes written. */
public long dumpFlate(RandomAccessFile os) throws IOException {
Deflater zip = new Deflater(Deflater.BEST_COMPRESSION);
byte[] output = new byte[8192];
Iterator<byte[]> it = list.iterator(); // when null, that means we have told the Deflater that no more input would be coming
long ans = 0; // the number of bytes written out so far
while(true) {
if (it!=null && zip.needsInput() && it.hasNext()) {
byte[] in = it.next();
if (in == list.getLast()) { zip.setInput(in, 0, n); it=null; zip.finish(); } else { zip.setInput(in, 0, SIZE); }
}
if (it==null && zip.finished()) break;
int count = zip.deflate(output);
if (count > 0) {
ans = ans + count;
if (ans < 0) throw new IOException("Data too large to be written to the output file.");
os.write(output, 0, count);
}
}
return ans;
}
示例2: dumpFlate
import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
* Write the entire content into the given file using Flate compression (see
* RFC1951) then return the number of bytes written.
*/
public long dumpFlate(RandomAccessFile os) throws IOException {
Deflater zip = new Deflater(Deflater.BEST_COMPRESSION);
byte[] output = new byte[8192];
Iterator<byte[]> it = list.iterator(); // when null, that means we have
// told the Deflater that no
// more input would be coming
long ans = 0; // the number of bytes written out so far
while (true) {
if (it != null && zip.needsInput() && it.hasNext()) {
byte[] in = it.next();
if (in == list.getLast()) {
zip.setInput(in, 0, n);
it = null;
zip.finish();
} else {
zip.setInput(in, 0, SIZE);
}
}
if (it == null && zip.finished())
break;
int count = zip.deflate(output);
if (count > 0) {
ans = ans + count;
if (ans < 0)
throw new IOException("Data too large to be written to the output file.");
os.write(output, 0, count);
}
}
return ans;
}