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


Java ArchiveOutputStream.finish方法代码示例

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


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

示例1: addFilesToZip

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

示例2: 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

示例3: createPackageZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Creates the {@code CRX} package definition.
 *
 * @param packageName Name of the package to create.
 */
public final void createPackageZip(final String packageName) {
    try {
        ArchiveOutputStream archiveOutputStream =
                new ZipArchiveOutputStream(new File("src/main/resources/" + packageName + ".zip"));
        addZipEntry(archiveOutputStream, "META-INF/vault/definition/.content.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/config.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/filter.xml");
        addZipEntry(archiveOutputStream, "META-INF/vault/nodetypes.cnd");
        addZipEntry(archiveOutputStream, "META-INF/vault/properties.xml");
        addZipEntry(archiveOutputStream, "jcr_root/.content.xml");
        archiveOutputStream.finish();
        archiveOutputStream.close();
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Unable to create package zip: {0}", e.getMessage());
    }
}
 
开发者ID:steuyfish,项目名称:aem-data-exporter,代码行数:22,代码来源:PackageFileZipper.java

示例4: addFilesToZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value = "OBL_UNSATISFIED_OBLIGATION",
    justification = "Lombok construct of @Cleanup is handing this, but not detected by FindBugs")
private static void addFilesToZip(File zipFile, List<File> filesToAdd) throws IOException {
  try {
    @Cleanup
    OutputStream archiveStream = new FileOutputStream(zipFile);
    @Cleanup
    ArchiveOutputStream archive =
        new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);

    for (File fileToAdd : filesToAdd) {
      ZipArchiveEntry entry = new ZipArchiveEntry(fileToAdd.getName());
      archive.putArchiveEntry(entry);

      @Cleanup
      BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToAdd));
      IOUtils.copy(input, archive);
      archive.closeArchiveEntry();
    }

    archive.finish();
  } catch (ArchiveException e) {
    throw new IOException("Issue with creating archive", e);
  }
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:27,代码来源:AzkabanJobHelper.java

示例5: makeZip

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
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();
	}
 
开发者ID:h819,项目名称:spring-boot,代码行数:28,代码来源:CompressExample.java

示例6: zipFile

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Zip file.
 *
 * @param filePath the file path
 * @return the string
 */
public String zipFile(String filePath) {
	try {
		/* Create Output Stream that will have final zip files */
		OutputStream zipOutput = new FileOutputStream(new File(filePath
				+ ".zip"));
		/*
		 * Create Archive Output Stream that attaches File Output Stream / and
		 * specifies type of compression
		 */
		ArchiveOutputStream logicalZip = new ArchiveStreamFactory()
				.createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipOutput);
		/* Create Archieve entry - write header information */
		logicalZip.putArchiveEntry(new ZipArchiveEntry(FilenameUtils.getName(filePath)));
		/* Copy input file */
		IOUtils.copy(new FileInputStream(new File(filePath)), logicalZip);
		/* Close Archieve entry, write trailer information */
		logicalZip.closeArchiveEntry();

		/* Finish addition of entries to the file */
		logicalZip.finish();
		/* Close output stream, our files are zipped */
		zipOutput.close();
	} catch (Exception e) {
		System.err.println(e.getMessage());
		return null;
	}
	return filePath + ".zip";
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:35,代码来源:ZipFiles.java

示例7: inspectBlobData

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
private void inspectBlobData(Statement stmt, Table table, Column column) throws SchemaCrawlerException{
    String tableName = table.getName().replaceAll("\"", "");
    String columnName = column.getName().replaceAll("\"", "");

    String sql = "select " + columnName + " from " + tableName ;
    LOGGER.log(Level.CONFIG, "SQL : {0}", sql);

    InputStream byte_stream;
    try(ResultSet rs = stmt.executeQuery(sql)){
        if(rs.next()){
            File file = new File("target/file");

            try(FileOutputStream fos = new FileOutputStream(file)){
                byte[] buffer = new byte[1];
                byte_stream = rs.getBinaryStream(columnName);
                int nbBytes = 0;
                while (byte_stream.read(buffer) > 0 && nbBytes < 512000) {
                    fos.write(buffer);
                    nbBytes++;
                }
                byte_stream.close();
                int extract_size = nbBytes-1;

                /* Create Output Stream that will have final zip files */
                OutputStream zip_output = new FileOutputStream(new File("target/zip_output.zip"));
                /* Create Archive Output Stream that attaches File Output Stream / and specifies type of compression */
                ArchiveOutputStream logical_zip = null;
                logical_zip = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zip_output);
                /* Create Archieve entry - write header information*/
                logical_zip.putArchiveEntry(new ZipArchiveEntry("target/file"));
                /* Copy input file */
                IOUtils.copy(new FileInputStream(new File("target/file")), logical_zip);
                /* Close Archieve entry, write trailer information */
                logical_zip.closeArchiveEntry();
                /* Finish addition of entries to the file */
                logical_zip.finish();
                /* Close output stream, our files are zipped */
                zip_output.close();

                File zip_file = new File("target/zip_output.zip");
                if(zip_file.length() < extract_size) {
                    double rate = (zip_file.length() - extract_size)*100/extract_size;
                    if (Math.abs(rate) >= minCompressionPercent) {
                        LOGGER.info("Extract size :" + extract_size + "ko, zip file size :" + zip_file.length() + " rate :" +rate+"%");
                        addLint(table, "Blob should be compressed", column.getFullName());
                    }
                }

            } catch (IOException | ArchiveException e){
                LOGGER.severe(e.getMessage());
                throw new SchemaCrawlerException(e.getMessage(), e);
            }
        }
    }catch (SQLException ex) {
        LOGGER.severe(ex.getMessage());
        throw new SchemaCrawlerException(ex.getMessage(), ex);
    }
}
 
开发者ID:mbarre,项目名称:schemacrawler-additional-lints,代码行数:59,代码来源:LinterCompressBlob.java

示例8: 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

示例9: compress

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
@Override
public Target compress(Target... targets) throws IOException {
    Target compressTarget = null;
    Path compressFile = null;

    ArchiveOutputStream archiveOutputStream = null;

    try {

        for (Target target : targets) {
            // get target volume
            final Volume targetVolume = target.getVolume();

            // gets the target infos
            final String targetName = targetVolume.getName(target);
            final String targetDir = targetVolume.getParent(target).toString();
            final boolean isTargetFolder = targetVolume.isFolder(target);

            if (compressFile == null) {
                // create compress file
                String compressFileName = (targets.length == 1) ? targetName : getArchiveName();
                compressFile = Paths.get(targetDir, compressFileName + getExtension());

                // creates a new compress file to not override if already exists
                // if you do not want this behavior, just comment this line
                compressFile = createFile(true, compressFile.getParent(), compressFile);

                compressTarget = targetVolume.fromPath(compressFile.toString());

                // open streams to write the compress target contents and auto close it
                archiveOutputStream = createArchiveOutputStream(compressFile);
            }

            if (isTargetFolder) {
                // compress target directory
                compressDirectory(target, archiveOutputStream);
            } else {
                // compress target file
                compressFile(target, archiveOutputStream);
            }
        }

    } finally {
        // close streams
        if (archiveOutputStream != null) {
            archiveOutputStream.finish();
            archiveOutputStream.close();
        }
    }

    return compressTarget;
}
 
开发者ID:trustsystems,项目名称:elfinder-java-connector,代码行数:53,代码来源:ZipArchiver.java

示例10: compress

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Default compress implementation used by .tar and .tgz
 *
 * @return the compress archive target.
 */
@Override
public Target compress(Target... targets) throws IOException {
    Target compressTarget = null;

    OutputStream outputStream = null;
    BufferedOutputStream bufferedOutputStream = null;
    ArchiveOutputStream archiveOutputStream = null;

    try {

        for (Target target : targets) {
            // get target volume
            final Volume targetVolume = target.getVolume();

            // gets the target infos
            final String targetName = targetVolume.getName(target);
            final String targetDir = targetVolume.getParent(target).toString();
            final boolean isTargetFolder = targetVolume.isFolder(target);

            if (compressTarget == null) {
                // create compress file
                String compressFileName = (targets.length == 1) ? targetName : getArchiveName();
                Path compressFile = Paths.get(targetDir, compressFileName + getExtension());

                // creates a new compress file to not override if already exists
                // if you do not want this behavior, just comment this line
                compressFile = createFile(true, compressFile.getParent(), compressFile);

                compressTarget = targetVolume.fromPath(compressFile.toString());

                // open streams to write the compress target contents and auto close it
                outputStream = targetVolume.openOutputStream(compressTarget);
                bufferedOutputStream = new BufferedOutputStream(outputStream);
                archiveOutputStream = createArchiveOutputStream(bufferedOutputStream);
            }

            if (isTargetFolder) {
                // compress target directory
                compressDirectory(target, archiveOutputStream);
            } else {
                // compress target file
                compressFile(target, archiveOutputStream);
            }
        }

    } finally {
        // close streams
        if (archiveOutputStream != null) {
            archiveOutputStream.finish();
            archiveOutputStream.close();
        }
        if (bufferedOutputStream != null) {
            bufferedOutputStream.close();
        }
        if (outputStream != null) {
            outputStream.close();
        }
    }

    return compressTarget;
}
 
开发者ID:trustsystems,项目名称:elfinder-java-connector,代码行数:67,代码来源:AbstractArchiver.java

示例11: Create

import org.apache.commons.compress.archivers.ArchiveOutputStream; //导入方法依赖的package包/类
public boolean Create() throws IOException, ArchiveException {

        System.out.println("Input Directory "+ INPUT_DIRECTORY);


        OutputStream archiveStream = new FileOutputStream(ZIP_FILE_ABSOLUTE_PATH);
        ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);

        Collection<File> fileList = FileUtils.listFiles(INPUT_DIRECTORY , null, true);

        for (File file : fileList) {

            String relative = INPUT_DIRECTORY.toURI().relativize(file.toURI()).toString();

           // String entryName = getEntryName(INPUT_DIRECTORY, file);


            if ( ! relative.startsWith(".") &! relative.equalsIgnoreCase(ZIP_FILE.toString())) {

                System.out.println("Adding file name "+ relative + " to "+ZIP_FILE_ABSOLUTE_PATH);


                ZipArchiveEntry entry = new ZipArchiveEntry(relative);
                archive.putArchiveEntry(entry);

                BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));

                IOUtils.copy(input, archive);
                input.close();
                archive.closeArchiveEntry();
            }
        }

        archive.finish();
        archiveStream.close();

        return true;
    }
 
开发者ID:inkysea,项目名称:vmware-vrealize-automation,代码行数:39,代码来源:zip.java


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