Java Code Examples for org.apache.commons.compress.archivers.ArchiveOutputStream#close()

The following examples show how to use org.apache.commons.compress.archivers.ArchiveOutputStream#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompressExample.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: ZipTest.java    From document-management-system with GNU General Public License v2.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: ArchiveWorkItemHandler.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public void executeWorkItem(WorkItem workItem,
                            WorkItemManager manager) {
    String archive = (String) workItem.getParameter("Archive");
    List<File> files = (List<File>) workItem.getParameter("Files");

    try {
        RequiredParameterValidator.validate(this.getClass(),
                                            workItem);

        OutputStream outputStream = new FileOutputStream(new File(archive));
        ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar",
                                                                                      outputStream);

        if (files != null) {
            for (File file : files) {
                final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml");
                entry.setModTime(0);
                entry.setSize(file.length());
                entry.setUserId(0);
                entry.setGroupId(0);
                entry.setMode(0100000);
                os.putArchiveEntry(entry);
                IOUtils.copy(new FileInputStream(file),
                             os);
            }
        }
        os.closeArchiveEntry();
        os.close();
        manager.completeWorkItem(workItem.getId(),
                                 null);
    } catch (Exception e) {
        handleException(e);
        manager.abortWorkItem(workItem.getId());
    }
}
 
Example 4
Source File: CompressExample.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
public static void makeZip() throws IOException, ArchiveException{
		File f1 = new File("D:/compresstest.txt");
        File f2 = new File("D:/test1.xml");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        //ArchiveOutputStream ostemp = new ArchiveStreamFactory().createArchiveOutputStream("zip", baos);
        ZipArchiveOutputStream ostemp = new ZipArchiveOutputStream(baos);
        ostemp.setEncoding("GBK");
        ostemp.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
        IOUtils.copy(new FileInputStream(f1), ostemp);
        ostemp.closeArchiveEntry();
        ostemp.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
        IOUtils.copy(new FileInputStream(f2), ostemp);
        ostemp.closeArchiveEntry();
        ostemp.finish();
        ostemp.close();

//      final OutputStream out = new FileOutputStream("D:/testcompress.zip");
        final OutputStream out = new FileOutputStream("D:/中文名字.zip");
        ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
        os.putArchiveEntry(new ZipArchiveEntry("打包.zip"));
        baos.writeTo(os);
        os.closeArchiveEntry();
        baos.close();
        os.finish();
        os.close();
	}
 
Example 5
Source File: CompressedFileReference.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static void createArchiveFile(ArchiveOutputStream archiveOutputStream, File baseDir, List<File> inputFiles) throws IOException {
    inputFiles.forEach(file -> {
        try {
            writeFileToTar(archiveOutputStream, baseDir, file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    archiveOutputStream.close();
}
 
Example 6
Source File: CompressedApplicationInputStreamTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static File createArchiveFile(ArchiveOutputStream taos, File outFile) throws IOException {
    File app = new File("src/test/resources/deploy/validapp");
    writeFileToTar(taos, new File(app, "services.xml"));
    writeFileToTar(taos, new File(app, "hosts.xml"));
    writeFileToTar(taos, new File(app, "deployment.xml"));
    taos.close();
    return outFile;
}