当前位置: 首页>>代码示例>>Java>>正文


Java Deflater.needsInput方法代码示例

本文整理汇总了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;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:ByteBuffer.java

示例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;
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:35,代码来源:ByteBuffer.java


注:本文中的java.util.zip.Deflater.needsInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。