本文整理匯總了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;
}