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


Java Deflater.reset方法代码示例

本文整理汇总了Java中java.util.zip.Deflater.reset方法的典型用法代码示例。如果您正苦于以下问题:Java Deflater.reset方法的具体用法?Java Deflater.reset怎么用?Java Deflater.reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.Deflater的用法示例。


在下文中一共展示了Deflater.reset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
    Deflater deflater = new Deflater(level);
    deflater.reset();
    deflater.setInput(data);
    deflater.finish();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
    byte[] buf = new byte[1024];
    try {
        while (!deflater.finished()) {
            int i = deflater.deflate(buf);
            bos.write(buf, 0, i);
        }
    } finally {
        deflater.end();
        bos.close();
    }
    return bos.toByteArray();
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:19,代码来源:Zlib.java

示例2: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
    Deflater deflater = new Deflater(level);
    deflater.reset();
    deflater.setInput(data);
    deflater.finish();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
    byte[] buf = new byte[1024];
    try {
        while (!deflater.finished()) {
            int i = deflater.deflate(buf);
            bos.write(buf, 0, i);
        }
    } finally {
        deflater.end();
    }
    return bos.toByteArray();
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:Zlib.java

示例3: deflate

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
    Deflater deflater = getDef(level);
    if (deflater == null) throw new IllegalArgumentException("No deflate for level " + level + " !");
    deflater.reset();
    deflater.setInput(data);
    deflater.finish();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
    while (!deflater.finished()) {
        int i = deflater.deflate(buf.get());
        bos.write(buf.get(), 0, i);
    }
    //Deflater::end is called the time when the process exits.
    return bos.toByteArray();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:Zlib.java

示例4: 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

示例5: write

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static boolean write(Save save, Area area) {
	if (save.readOnly)
		return false;
	if (!area.isReady())
		return false;

	AreaMap map = area.areaMap();
	DataGroup[] dataGroups;
	if (map == null || map.world == null || map.world.entities == null) {
		dataGroups = new DataGroup[0];
	} else {
		dataGroups = map.world.entities.getEntitiesForSave(area.areaX, area.areaZ);
	}
	if (!area.modifiedSinceSave(dataGroups))
		return false;
	area.saveModCount();

	Deflater deflater = deflaterThreadLocal.get();

	FileHandle file = file(save, area.areaX, area.areaZ);
	try {
		deflater.reset();
		OutputStream stream = file.write(false, 8192);
		DeflaterOutputStream deflaterStream = new DeflaterOutputStream(stream, deflater);
		BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(deflaterStream);
		DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);
		area.writeSave(dataOutputStream, dataGroups);
		bufferedOutputStream.flush();
		deflaterStream.finish();
		stream.close();
	} catch (Exception e) {
		Log.error("Failed to write area " + area.areaX + "," + area.areaZ, e);
		return false;
	}

	return true;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:38,代码来源:SaveAreaIO.java

示例6: releaseDeflater

import java.util.zip.Deflater; //导入方法依赖的package包/类
private void releaseDeflater(Deflater def) {
    synchronized (deflaters) {
        if (inflaters.size() < MAX_FLATER) {
           def.reset();
           deflaters.add(def);
        } else {
           def.end();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:ZipFileSystem.java

示例7: write

import java.util.zip.Deflater; //导入方法依赖的package包/类
public static boolean write(Save save, Area area) {
  if (save.readOnly) return false;
  if (!area.isReady()) return false;

  AreaMap map = area.areaMap();
  DataGroup[] dataGroups;
  if (map == null || map.world == null || map.world.entities == null) {
    dataGroups = new DataGroup[0];
  } else {
    dataGroups = map.world.entities.getEntitiesForSave(area.areaX, area.areaZ);
  }
  if (!area.modifiedSinceSave(dataGroups)) return false;
  area.saveModCount();

  Deflater deflater = deflaterThreadLocal.get();

  FileHandle file = file(save, area.areaX, area.areaZ);
  try {
    deflater.reset();
    OutputStream stream = file.write(false, 8192);
    DeflaterOutputStream deflaterStream = new DeflaterOutputStream(stream, deflater);
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(deflaterStream);
    DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);
    area.writeSave(dataOutputStream, dataGroups);
    bufferedOutputStream.flush();
    deflaterStream.finish();
    stream.close();
  } catch (Exception e) {
    Log.error("Failed to write area " + area.areaX + "," + area.areaZ, e);
    return false;
  }

  return true;
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:35,代码来源:SaveAreaIO.java


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