當前位置: 首頁>>代碼示例>>Java>>正文


Java CompressorStreamFactory.createCompressorOutputStream方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.compressors.CompressorStreamFactory.createCompressorOutputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java CompressorStreamFactory.createCompressorOutputStream方法的具體用法?Java CompressorStreamFactory.createCompressorOutputStream怎麽用?Java CompressorStreamFactory.createCompressorOutputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.compressors.CompressorStreamFactory的用法示例。


在下文中一共展示了CompressorStreamFactory.createCompressorOutputStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildPackages

import org.apache.commons.compress.compressors.CompressorStreamFactory; //導入方法依賴的package包/類
static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
  CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
    try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
      for (Map<String, String> entry : entries) {
        InternetHeaders headers = new InternetHeaders();
        headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
        headers.addHeader(P_VERSION, entry.get(P_VERSION));
        headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
        headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
        headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
        headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
        headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
        Enumeration<String> headerLines = headers.getAllHeaderLines();
        while (headerLines.hasMoreElements()) {
          String line = headerLines.nextElement();
          writer.write(line, 0, line.length());
          writer.write('\n');
        }
        writer.write('\n');
      }
    }
  }
  catch ( CompressorException e ) {
    throw new RException(null, e);
  }
  return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:30,代碼來源:RPackagesUtils.java

示例2: getCompressorInputStream

import org.apache.commons.compress.compressors.CompressorStreamFactory; //導入方法依賴的package包/類
private InputStream getCompressorInputStream(String format, String resource)
        throws CompressorException, URISyntaxException, IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    CompressorStreamFactory factory = new CompressorStreamFactory();
    CompressorOutputStream aout = factory.createCompressorOutputStream(format, bout);

    File f = new File(getClass().getResource(resource).toURI());
    IOUtils.copy(new FileInputStream(f), aout);
    aout.close();

    return new ByteArrayInputStream(bout.toByteArray());
}
 
開發者ID:hata,項目名稱:embulk-decoder-commons-compress,代碼行數:13,代碼來源:TestCommonsCompressDecoderPlugin.java

示例3: getPackages

import org.apache.commons.compress.compressors.CompressorStreamFactory; //導入方法依賴的package包/類
@Override
@TransactionalTouchMetadata
public Content getPackages(final String packagesPath) {
  checkNotNull(packagesPath);
  try {
    // TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
    // the number of packages contained in a particular path. We should be able to generate this when something has
    // changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
    StorageTx tx = UnitOfWork.currentTx();
    RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
    for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
      packagesBuilder.append(asset);
    }
    CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
      try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
        for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation().entrySet()) {
          Map<String, String> packageInfo = eachPackage.getValue();
          InternetHeaders headers = new InternetHeaders();
          headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
          headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
          headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
          headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
          headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
          headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
          headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION));
          Enumeration<String> headerLines = headers.getAllHeaderLines();
          while (headerLines.hasMoreElements()) {
            String line = headerLines.nextElement();
            writer.write(line, 0, line.length());
            writer.write('\n');
          }
          writer.write('\n');
        }
      }
    }
    return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
  }
  catch (CompressorException | IOException e) {
    throw new RException(packagesPath, e);
  }
}
 
開發者ID:sonatype-nexus-community,項目名稱:nexus-repository-r,代碼行數:44,代碼來源:RHostedFacetImpl.java


注:本文中的org.apache.commons.compress.compressors.CompressorStreamFactory.createCompressorOutputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。