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


Java ArchiveOutputStream.createArchiveEntry方法代码示例

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


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

示例1: getArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private InputStream getArchiveInputStream(String format, String ...resourceFiles)
        throws ArchiveException, URISyntaxException, IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ArchiveStreamFactory factory = new ArchiveStreamFactory();
    ArchiveOutputStream aout = factory.createArchiveOutputStream(format, bout);

    for (String resource : resourceFiles) {
        File f = new File(getClass().getResource(resource).toURI());
        ArchiveEntry entry = aout.createArchiveEntry(f, resource);
        aout.putArchiveEntry(entry);
        IOUtils.copy(new FileInputStream(f),aout);
        aout.closeArchiveEntry();
    }
    aout.finish();
    aout.close();

    return new ByteArrayInputStream(bout.toByteArray());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:19,代码来源:TestCommonsCompressDecoderPlugin.java

示例2: addZipEntry

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Adds an entry to the zip.
 *
 * @param archiveOutputStream {@code ArchiveOutputStream} to output zip entry to.
 * @param filename Name of the file to add to the zip.
 * @throws IOException If an error occurs adding the file to the zip.
 */
private void addZipEntry(final ArchiveOutputStream archiveOutputStream, final String filename) throws IOException {
    FileInputStream fileInputStream = null;
    try {
        File file = new File("src/main/resources/" + filename);
        ArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(file, filename);
        archiveOutputStream.putArchiveEntry(archiveEntry);
        fileInputStream = new FileInputStream(file);
        IOUtils.copy(fileInputStream, archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to create zip entry for file: [{0}]. {1}",
                new String[]{filename, e.getMessage()});
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
}
 
开发者ID:steuyfish,项目名称:aem-data-exporter,代码行数:26,代码来源:PackageFileZipper.java

示例3: createArchiveEntry

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Creates a new {@link ArchiveEntry} in the given {@link ArchiveOutputStream}, and copies the given {@link File}
 * into the new entry.
 * 
 * @param file the file to add to the archive
 * @param entryName the name of the archive entry
 * @param archive the archive to write to
 * @throws IOException when an I/O error occurs during FileInputStream creation or during copying
 */
protected void createArchiveEntry(File file, String entryName, ArchiveOutputStream archive) throws IOException {
    ArchiveEntry entry = archive.createArchiveEntry(file, entryName);
    // TODO #23: read permission from file, write it to the ArchiveEntry
    archive.putArchiveEntry(entry);

    if (!entry.isDirectory()) {
        FileInputStream input = null;
        try {
            input = new FileInputStream(file);
            IOUtils.copy(input, archive);
        } finally {
            IOUtils.closeQuietly(input);
        }
    }

    archive.closeArchiveEntry();
}
 
开发者ID:thrau,项目名称:jarchivelib,代码行数:27,代码来源:CommonsArchiver.java

示例4: addFile

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private void addFile(ArchiveOutputStream archive, String tarFileName, Path filePath)
    throws IOException {
  ArchiveEntry archiveEntry = archive.createArchiveEntry(filePath.toFile(), tarFileName);

  archive.putArchiveEntry(archiveEntry);
  Files.copy(filePath, archive);
  archive.closeArchiveEntry();

  logger.debug("Added file {} as {}", filePath.toAbsolutePath(), tarFileName);
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:11,代码来源:SubmissionPackagingService.java

示例5: compress

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Private method for compression and recursive call.
 *
 * @param files the files to compress.
 * @param base the base path to store files to.
 * @param aos the output stream to use.
 * @throws IOException if an I/O error occurs.
 */
private void compress(File[] files, String base, ArchiveOutputStream aos) throws IOException {

    final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    int readBytes;

    if (files.length > 0) {
        for (int i = 0; !_interrupt && i < files.length; ++i) {
            // create next file and define entry name based on folder level
            final File newFile = files[i];
            String entryName = base + newFile.getName();
            // start compressing the file
            if (newFile.isFile()) {
                try (BufferedInputStream buf = new BufferedInputStream(
                        new FileInputStream(newFile))) {
                    // create next archive entry and put it on output stream
                    ArchiveEntry entry = aos.createArchiveEntry(newFile, entryName);
                    aos.putArchiveEntry(entry);
                    // write bytes to file
                    while (!_interrupt && (readBytes = buf.read(buffer)) != -1) {
                        aos.write(buffer, 0, readBytes);
                        updateProgress(readBytes);
                    }
                    aos.closeArchiveEntry();
                } catch (IOException ex) {
                    if (!_interrupt) {
                        Log.e(ex.getLocalizedMessage(), ex);
                        Log.e("{0}\n{1}",
                                I18N.getString("errorReadingFile.text"), newFile.getPath()
                        );
                        throw ex; // re-throw
                    }
                }
            } else { // child is a directory
                File[] children = getFiles(newFile.getAbsolutePath());
                compress(children, entryName + "/", aos);
            }
        }
    }
}
 
开发者ID:turbolocust,项目名称:GZipper,代码行数:48,代码来源:ArchivingAlgorithm.java

示例6: testArchive

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void testArchive(String archiveType) throws Exception {
  //create an archive with multiple files, files containing multiple objects
  File dir = new File("target", UUID.randomUUID().toString());
  dir.mkdirs();

  OutputStream archiveOut = new FileOutputStream(new File(dir, "myArchive"));
  ArchiveOutputStream archiveOutputStream = new ArchiveStreamFactory().createArchiveOutputStream(archiveType, archiveOut);

  File inputFile;
  ArchiveEntry archiveEntry;
  FileOutputStream fileOutputStream;
  for(int i = 0; i < 5; i++) {
    String fileName = "file-" + i + ".txt";
    inputFile = new File(dir, fileName);
    fileOutputStream = new FileOutputStream(inputFile);
    IOUtils.write(("StreamSets" + i).getBytes(), fileOutputStream);
    fileOutputStream.close();
    archiveEntry = archiveOutputStream.createArchiveEntry(inputFile, fileName);
    archiveOutputStream.putArchiveEntry(archiveEntry);
    IOUtils.copy(new FileInputStream(inputFile), archiveOutputStream);
    archiveOutputStream.closeArchiveEntry();
  }
  archiveOutputStream.finish();
  archiveOut.close();

  //create compression input
  FileInputStream fileInputStream = new FileInputStream(new File(dir, "myArchive"));
  CompressionDataParser.CompressionInputBuilder compressionInputBuilder =
      new CompressionDataParser.CompressionInputBuilder(Compression.ARCHIVE, "*.txt", fileInputStream, "0");
  CompressionDataParser.CompressionInput input = compressionInputBuilder.build();

  // before reading
  Assert.assertNotNull(input);

  // The default wrapped offset before reading any file
  String wrappedOffset = "{\"fileName\": \"myfile\", \"fileOffset\":\"0\"}";

  Map<String, Object> archiveInputOffset = OBJECT_MAPPER.readValue(wrappedOffset, Map.class);
  Assert.assertNotNull(archiveInputOffset);
  Assert.assertEquals("myfile", archiveInputOffset.get("fileName"));
  Assert.assertEquals("0", archiveInputOffset.get("fileOffset"));

  Assert.assertEquals("0", input.getStreamPosition(wrappedOffset));
  // read and check wrapped offset
  BufferedReader reader = new BufferedReader(
      new InputStreamReader(input.getNextInputStream()));
  Assert.assertEquals("StreamSets0", reader.readLine());
  wrappedOffset = input.wrapOffset("4567");
  archiveInputOffset = OBJECT_MAPPER.readValue(wrappedOffset, Map.class);
  Assert.assertNotNull(archiveInputOffset);
  Assert.assertEquals("file-0.txt", archiveInputOffset.get("fileName"));
  Assert.assertEquals("4567", archiveInputOffset.get("fileOffset"));
  checkHeader(input, "file-0.txt", input.getStreamPosition(wrappedOffset));

  String recordIdPattern = "myFile/file-0.txt";
  Assert.assertEquals(recordIdPattern, input.wrapRecordId("myFile"));

}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:60,代码来源:TestCompressionInputBuilder.java


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