java.util.zip.ZipOutputStream.setLevel()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中java.util.zip.ZipOutputStream.setLevel()方法的一些代码示例,展示了ZipOutputStream.setLevel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipOutputStream.setLevel()方法的具体详情如下:
包路径:java.util.zip.ZipOutputStream
类名称:ZipOutputStream
方法名:setLevel

ZipOutputStream.setLevel介绍

[英]Sets the compression level to be used for writing entry data.
[中]设置用于写入条目数据的{$0$}。

代码示例

代码示例来源:origin: syncany/syncany

public ZipMultiChunk(MultiChunkId id, int minSize, OutputStream os) throws IOException {
  super(id, minSize);        
  
  this.zipOut = new ZipOutputStream(os);
  this.zipOut.setLevel(ZipOutputStream.STORED); // No compression        
}

代码示例来源:origin: zeroturnaround/zt-zip

private RepackZipEntryCallback(File dstZip, int compressionLevel) {
 try {
  this.out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(dstZip)));
  this.out.setLevel(compressionLevel);
 }
 catch (IOException e) {
  ZipExceptionUtil.rethrow(e);
 }
}

代码示例来源:origin: gocd/gocd

public void done() throws IOException {
    ZipOutputStream zip = null;
    try {
      zip = new ZipOutputStream(new BufferedOutputStream(destinationStream));
      zip.setLevel(level);
      for (Map.Entry<String, File> zipDirToSourceFileEntry : toAdd.entrySet()) {
        File sourceFileToZip = zipDirToSourceFileEntry.getValue();
        String destinationFolder = zipDirToSourceFileEntry.getKey();
        zipUtil.addToZip(new ZipPath(destinationFolder), sourceFileToZip, zip, excludeRootDir);
      }
      zip.flush();
    } finally {
      if (zip != null) {
        try {
          zip.close();
        } catch (IOException e) {
          LOGGER.error("Failed to close the stream", e);
        }
      }
    }
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void writeObject(ByteBuffer buffer, Object object) throws IOException {
    if (!(object instanceof ZIPCompressedMessage)) return;

    ZIPCompressedMessage zipMessage = (ZIPCompressedMessage)object;
    Message message = zipMessage.getMessage();
    ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
    Serializer.writeClassAndObject(tempBuffer, message);

    ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
    ZipOutputStream zipOutput = new ZipOutputStream(byteArrayOutput);
    zipOutput.setLevel(zipMessage.getLevel());

    ZipEntry zipEntry = new ZipEntry("zip");

    zipOutput.putNextEntry(zipEntry);
    tempBuffer.flip();
    zipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
    zipOutput.flush();
    zipOutput.closeEntry();
    zipOutput.close();

    buffer.put(byteArrayOutput.toByteArray());
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param bytes Byte array to compress.
 * @param compressionLevel Level of compression to encode.
 * @return Compressed bytes.
 * @throws IgniteCheckedException If failed.
 */
public static byte[] zip(@Nullable byte[] bytes, int compressionLevel) throws IgniteCheckedException {
  try {
    if (bytes == null)
      return null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (ZipOutputStream zos = new ZipOutputStream(bos)) {
      zos.setLevel(compressionLevel);
      ZipEntry entry = new ZipEntry("");
      try {
        entry.setSize(bytes.length);
        zos.putNextEntry(entry);
        zos.write(bytes);
      }
      finally {
        zos.closeEntry();
      }
    }
    return bos.toByteArray();
  }
  catch (Exception e) {
    throw new IgniteCheckedException(e);
  }
}

代码示例来源:origin: scouter-project/scouter

zos.setLevel(9);
indexFile = new File(filename + ".inx"); // Index file
if(!indexFile.exists()){

代码示例来源:origin: spotbugs/spotbugs

public CopyBuggySource(String[] args) throws Exception {
  origCollection = new SortedBugCollection();
  origCollection.readXML(args[0]);
  project = origCollection.getProject();
  sourceFinder = new SourceFinder(project);
  src = new File(args[1]);
  kind = SrcKind.get(src);
  switch (kind) {
  case DIR:
    break;
  case ZIP:
    zOut = new ZipOutputStream(new FileOutputStream(src));
    break;
  case Z0P_GZ:
    zOut = new ZipOutputStream(new DeflaterOutputStream(new FileOutputStream(src)));
    zOut.setLevel(0);
    break;
  }
}

代码示例来源:origin: zeroturnaround/zt-zip

try {
 out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZip)));
 out.setLevel(compressionLevel);
 pack(sourceDir, out, mapper, "", true);

代码示例来源:origin: org.apache.ant/ant

output.setLevel(Deflater.DEFAULT_COMPRESSION);
} else {
  output.setMethod(ZipOutputStream.STORED);

代码示例来源:origin: zeroturnaround/zt-zip

try {
 out = new ZipOutputStream(new BufferedOutputStream(os));
 out.setLevel(compressionLevel);
 pack(sourceDir, out, mapper, "", true);

代码示例来源:origin: apache/nifi

@Override
  public void process(final OutputStream rawOut) throws IOException {
    try (final OutputStream bufferedOut = new BufferedOutputStream(rawOut);
      final ZipOutputStream out = new ZipOutputStream(bufferedOut)) {
      out.setLevel(compressionLevel);
      for (final FlowFile flowFile : contents) {
        final String path = keepPath ? getPath(flowFile) : "";
        final String entryName = path + flowFile.getAttribute(CoreAttributes.FILENAME.key());
        final ZipEntry zipEntry = new ZipEntry(entryName);
        zipEntry.setSize(flowFile.getSize());
        try {
          out.putNextEntry(zipEntry);
          bin.getSession().exportTo(flowFile, out);
          out.closeEntry();
          unmerged.remove(flowFile);
        } catch (ZipException e) {
          getLogger().error("Encountered exception merging {}", new Object[] {flowFile}, e);
        }
      }
      out.finish();
      out.flush();
    }
  }
});

代码示例来源:origin: zeroturnaround/zt-zip

fos = new FileOutputStream(destZipFile);
out = new ZipOutputStream(new BufferedOutputStream(fos));
out.setLevel(compressionLevel);

代码示例来源:origin: apache/ignite

zos.setLevel(dsCfg.getWalCompactionLevel());
zos.putNextEntry(new ZipEntry(nextSegment + ".wal"));

代码示例来源:origin: pentaho/pentaho-kettle

out.setLevel( Deflater.BEST_COMPRESSION );

代码示例来源:origin: apache/usergrid

zipOutputStream.setLevel(9); // best compression to reduce the amount of data to stream over the wire

代码示例来源:origin: syncany/syncany

zipOutputStream.setLevel(ZipOutputStream.STORED);

代码示例来源:origin: pentaho/pentaho-kettle

out.setLevel( Deflater.NO_COMPRESSION );
} else if ( compressionRate == 1 ) {
 out.setLevel( Deflater.DEFAULT_COMPRESSION );
 out.setLevel( Deflater.BEST_COMPRESSION );
 out.setLevel( Deflater.BEST_SPEED );

代码示例来源:origin: jamesagnew/hapi-fhir

public ZipGenerator(String filename) throws FileNotFoundException  {
  dest = new FileOutputStream(filename);
  out = new ZipOutputStream(new BufferedOutputStream(dest));
out.setLevel(Deflater.BEST_COMPRESSION);
}

代码示例来源:origin: jamesagnew/hapi-fhir

public void addMimeTypeFile(String statedPath, String actualPath) throws IOException  {
 //  byte data[] = new byte[BUFFER];
  CRC32 crc = new CRC32();
  
 //  FileInputStream fi = new FileInputStream(actualPath);
 //  BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
  out.setLevel(0);
  ZipEntry entry = new ZipEntry(statedPath);
  entry.setExtra(null);
  names.add(statedPath);
  String contents = "application/epub+zip";
  crc.update(contents.getBytes());
  entry.setCompressedSize(contents.length());
  entry.setSize(contents.length());
  entry.setCrc(crc.getValue());
  entry.setMethod(ZipEntry.STORED);
  out.putNextEntry(entry);
 //   int count;
//    while ((count = origin.read(data, 0, BUFFER)) != -1) {
//      out.write(data, 0, count);
//    }
 //  origin.close();
  out.write(contents.getBytes(),0,contents.length());
  out.setLevel(Deflater.BEST_COMPRESSION);
 }

代码示例来源:origin: OpenNMS/opennms

@Override
public void begin() {
  super.begin();
  try {
    m_zipOutputStream = new ZipOutputStream(new FileOutputStream(m_tempFile));
    m_zipOutputStream.setLevel(9);
  } catch (final Exception e) {
    LOG.error("Unable to create zip file '{}'", m_tempFile, e);
    return;
  }
}

相关文章