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


Java ArchiveStreamFactory类代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.ArchiveStreamFactory的典型用法代码示例。如果您正苦于以下问题:Java ArchiveStreamFactory类的具体用法?Java ArchiveStreamFactory怎么用?Java ArchiveStreamFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ArchiveStreamFactory类属于org.apache.commons.compress.archivers包,在下文中一共展示了ArchiveStreamFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeOnlyUnZip

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例2: testApache

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
public void testApache() throws IOException, ArchiveException {
	log.debug("testApache()");
	File zip = File.createTempFile("apache_", ".zip");
	
	// Create zip
	FileOutputStream fos = new FileOutputStream(zip);
	ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
	aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
	aos.closeArchiveEntry();
	aos.close();
	
	// Read zip
	FileInputStream fis = new FileInputStream(zip);
	ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
	ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
	assertEquals(zae.getName(), "coñeta");
	ais.close();
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:ZipTest.java

示例3: testOpenForGeneratedArchives

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
@Test
public void testOpenForGeneratedArchives() throws Exception
{
    String[] testFormats = new String[]{
            ArchiveStreamFactory.AR,
            // ArchiveStreamFactory.ARJ, // ArchiveException: Archiver: arj not found.
            ArchiveStreamFactory.CPIO,
            // ArchiveStreamFactory.DUMP, // ArchiveException: Archiver: dump not found.
            ArchiveStreamFactory.JAR,
            // ArchiveStreamFactory.SEVEN_Z, // StreamingNotSupportedException: The 7z doesn't support streaming.
            ArchiveStreamFactory.TAR,
            ArchiveStreamFactory.ZIP,
    };

    for (String format : testFormats) {
        TaskSource mockTaskSource = new MockTaskSource(format);
        FileInput mockInput = new MockFileInput(
                getInputStreamAsBuffer(
                        getArchiveInputStream(format, "sample_1.csv", "sample_2.csv")));
        CommonsCompressDecoderPlugin plugin = new CommonsCompressDecoderPlugin();
        FileInput archiveFileInput = plugin.open(mockTaskSource, mockInput);
        verifyContents(archiveFileInput, "1,foo", "2,bar");
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:25,代码来源:TestCommonsCompressDecoderPlugin.java

示例4: tarFolder

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
/**
 * Tar a given folder to a file.
 *
 * @param folder the original folder to tar
 * @param destinationFile the destination file
 * @param waitingHandler a waiting handler used to cancel the process (can
 * be null)
 * @throws FileNotFoundException exception thrown whenever a file is not
 * found
 * @throws ArchiveException exception thrown whenever an error occurred
 * while taring
 * @throws IOException exception thrown whenever an error occurred while
 * reading/writing files
 */
public static void tarFolder(File folder, File destinationFile, WaitingHandler waitingHandler) throws FileNotFoundException, ArchiveException, IOException {
    FileOutputStream fos = new FileOutputStream(destinationFile);
    try {
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        try {
            TarArchiveOutputStream tarOutput = (TarArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, bos);
            try {
                tarOutput.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
                File matchFolder = folder;
                addFolderContent(tarOutput, matchFolder, waitingHandler);
            } finally {
                tarOutput.close();
            }
        } finally {
            bos.close();
        }
    } finally {
        fos.close();
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:35,代码来源:TarUtils.java

示例5: extractMetadataFromArchive

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
private static Map<String, String> extractMetadataFromArchive(final String archiveType, final InputStream is) {
  final ArchiveStreamFactory archiveFactory = new ArchiveStreamFactory();
  try (ArchiveInputStream ais = archiveFactory.createArchiveInputStream(archiveType, is)) {
    ArchiveEntry entry = ais.getNextEntry();
    while (entry != null) {
      if (!entry.isDirectory() && DESCRIPTION_FILE_PATTERN.matcher(entry.getName()).matches()) {
        return parseDescriptionFile(ais);
      }
      entry = ais.getNextEntry();
    }
  }
  catch (ArchiveException | IOException e) {
    throw new RException(null, e);
  }
  throw new IllegalStateException("No metadata file found");
}
 
开发者ID:sonatype-nexus-community,项目名称:nexus-repository-r,代码行数:17,代码来源:RDescriptionUtils.java

示例6: packageSubmission

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
/**
 * @param additionalFiles A map of filename -> content pairs to include in the package.
 * @return The packaged submission as a TAR archive.
 */
@Override
public byte[] packageSubmission(Map<String, byte[]> additionalFiles)
    throws IOException, ArchiveException {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

  try (ArchiveOutputStream archive = new ArchiveStreamFactory()
      .createArchiveOutputStream(ArchiveStreamFactory.TAR, outputStream)) {

    addTemplateFiles(archive);
    addAdditionalFiles(archive, additionalFiles);

    archive.finish();
  }

  logger.debug("Finished packaging submission, size {} bytes.", outputStream.size());

  return outputStream.toByteArray();
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:23,代码来源:SubmissionPackagingService.java

示例7: makeOnlyZip

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
public static void makeOnlyZip() throws IOException, ArchiveException{
	File f1 = new File("D:/compresstest.txt");
       File f2 = new File("D:/test1.xml");
       
       final OutputStream out = new FileOutputStream("D:/中文名字.zip");
       ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
       
       os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
       IOUtils.copy(new FileInputStream(f1), os);
       os.closeArchiveEntry();

       os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
       IOUtils.copy(new FileInputStream(f2), os);
       os.closeArchiveEntry();
       os.close();
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例8: addFilesToZip

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
    OutputStream archiveStream = new FileOutputStream(destination);
    ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
    Collection<File> fileList = FileUtils.listFiles(source, null, true);
    for (File file : fileList) {
        String entryName = getEntryName(source, file);
        ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
        archive.putArchiveEntry(entry);
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();
        archive.closeArchiveEntry();
    }
    archive.finish();
    archiveStream.close();
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:17,代码来源:Npm.java

示例9: compressDirectory

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
public static void compressDirectory(File rootDir, boolean includeAsRoot, File output) throws IOException {
    if (!rootDir.isDirectory()) {
        throw new IOException("Provided file is not a directory");
    }
    try (OutputStream archiveStream = new FileOutputStream(output);
         ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream)) {
        String rootName = "";
        if (includeAsRoot) {
            insertDirectory(rootDir, rootDir.getName(), archive);
            rootName = rootDir.getName()+"/";
        }
        Collection<File> fileCollection = FileUtils.listFilesAndDirs(rootDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE);
        for (File file : fileCollection) {
            String relativePath = getRelativePath(rootDir, file);
            String entryName = rootName+relativePath;
            if (!relativePath.isEmpty() && !"/".equals(relativePath)) {
                insertObject(file, entryName, archive);
            }
        }
        archive.finish();
    } catch (IOException | ArchiveException e) {
        throw new IOException(e);
    }
}
 
开发者ID:ctco,项目名称:gradle-mobile-plugin,代码行数:25,代码来源:ZipUtil.java

示例10: createArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
/**
 * Create a new ArchiveInputStream to read an archive file based on a format
 * parameter.
 * 
 * If format is not set, this method tries to detect file format
 * automatically. In this case, BufferedInputStream is used to wrap
 * FileInputInputStream instance. BufferedInputStream may read a data
 * partially when calling files.nextFile(). However, it doesn't matter
 * because the partial read data should be discarded. And then this method
 * is called again to create a new ArchiveInputStream.
 * 
 * @return a new ArchiveInputStream instance.
 */
ArchiveInputStream createArchiveInputStream(String format, InputStream in)
        throws IOException, ArchiveException {
    ArchiveStreamFactory factory = new ArchiveStreamFactory();
    if (CommonsCompressUtil.isAutoDetect(format)) {
        in = in.markSupported() ? in : new BufferedInputStream(in);
        try {
            return factory.createArchiveInputStream(in);
        } catch (ArchiveException e) {
            throw new IOException(
                    "Failed to detect a file format. Please try to set a format explicitly.",
                    e);
        }
    } else {
        return factory.createArchiveInputStream(format, in);
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:30,代码来源:CommonsCompressProvider.java

示例11: getArchiveInputStream

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的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

示例12: testArchiveFile

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
@Test
public void testArchiveFile() throws Exception {
    InputStream in = getClass().getResourceAsStream("samples.tar");
    ArchiveInputStream ain = new ArchiveStreamFactory().createArchiveInputStream(in);
    ArchiveInputStreamIterator it = new ArchiveInputStreamIterator(ain);
    assertTrue("Verify there is 1st item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", "1,foo", readContents(it.next()));
    assertTrue("Verify there is 2nd item.", it.hasNext());
    assertEquals("Verify ArchiveInputStream is return.", "2,bar", readContents(it.next()));
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());

    // Verify calling after no data.
    assertFalse("Verify there is no next item.", it.hasNext());
    assertNull("Verify there is no stream.", it.next());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:17,代码来源:TestArchiveInputStreamIterator.java

示例13: UploadedFileIterator

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
public UploadedFileIterator(UploadedFile item, String... extension) throws IOException {
    super();
    this.extension = extension;
    isZip = item.getFileName().toLowerCase().endsWith(".zip");
    itemInputStream = item.getInputstream();
    if (isZip) {
        try {
            in = new MyInputStream(
                    new ArchiveStreamFactory().createArchiveInputStream("zip", itemInputStream));
            // moveNext();
        } catch (ArchiveException e) {
            throw new IOException(e);
        }
    } else if (isValid(item.getFileName())) {
        next = new FileInputStreamWrapper(item.getFileName(), itemInputStream);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:18,代码来源:UploadedFileIterator.java

示例14: initialize

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
@Override
protected void initialize(BufferedOutputStream os, int compressionlevel) throws IOException {
    try {
        switch (compressionlevel) {
            case 9:
                lz4Stream = new LZ4HCFrameOutputStream(os);
                break;
            case 1:
                lz4Stream = new LZ4FrameOutputStream(os);
                break;
            default:
                log.printf("warning only currently support compressionlevels 1 and 9 [%d]", compressionlevel);
                lz4Stream = new LZ4FrameOutputStream(os);
        }
        tar = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.TAR, lz4Stream);
    } catch (ArchiveException ex) {
        log.fatalexception(ex, "initialize compressionlevel=%d", compressionlevel);
    }
}
 
开发者ID:htools,项目名称:htools,代码行数:20,代码来源:TarLz4FileWriter.java

示例15: detectArchiveFormat

import org.apache.commons.compress.archivers.ArchiveStreamFactory; //导入依赖的package包/类
private static MediaType detectArchiveFormat(byte[] prefix, int length) {
    try {
        ArchiveStreamFactory factory = new ArchiveStreamFactory();
        ArchiveInputStream ais = factory.createArchiveInputStream(
                new ByteArrayInputStream(prefix, 0, length));
        try {
            if ((ais instanceof TarArchiveInputStream)
                    && !TarArchiveInputStream.matches(prefix, length)) {
                // ArchiveStreamFactory is too relaxed, see COMPRESS-117
                return MediaType.OCTET_STREAM;
            } else {
                return PackageParser.getMediaType(ais);
            }
        } finally {
            IOUtils.closeQuietly(ais);
        }
    } catch (ArchiveException e) {
        return MediaType.OCTET_STREAM;
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:21,代码来源:ZipContainerDetector.java


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