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


Java TarArchiveOutputStream.flush方法代码示例

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


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

示例1: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TarArchiveOutputStream aos = new TarArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:33,代码来源:TarProcessor.java

示例2: archive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * 归档
 *
 * @param srcFile
 *            源路径
 * @param destPath
 *            目标路径
 * @throws Exception
 */
public static void archive(File srcFile, File destFile) throws Exception {

    TarArchiveOutputStream taos = new TarArchiveOutputStream(
            new FileOutputStream(destFile));

    archive(srcFile, taos, BASE_DIR);

    taos.flush();
    taos.close();
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:20,代码来源:TarUtils.java

示例3: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GzipCompressorOutputStream cos = new GzipCompressorOutputStream(baos);
    TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        cos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:35,代码来源:TarGzProcessor.java

示例4: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos);
    TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        cos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:35,代码来源:TarBz2Processor.java

示例5: compressData

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * Compress data
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XZCompressorOutputStream cos = new XZCompressorOutputStream(baos);
    TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
                .values()) {
            TarArchiveEntry entry = new TarArchiveEntry(
                    binaryFile.getDesPath());
            entry.setSize(binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        cos.close();
        baos.close();
    }
    return baos.toByteArray();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:35,代码来源:XzProcessor.java

示例6: tar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * 
 * ��һ���ļ��鵵
 * 
 * @param sources
 *            Ҫ�鵵��ԭ�ļ�����
 * @param target
 *            �鵵����ļ�
 * @return File ���ع鵵����ļ�
 * @throws Exception
 */
public static File tar(File[] sources, File target) throws Exception {
	FileOutputStream out = new FileOutputStream(target);
	TarArchiveOutputStream os = new TarArchiveOutputStream(out);
	for (File file : sources) {
		os.putArchiveEntry(new TarArchiveEntry(file));
		IOUtils.copy(new FileInputStream(file), os);
		os.closeArchiveEntry();
	}
	if (os != null) {
		os.flush();
		os.close();
	}
	return target;
}
 
开发者ID:Petasoft,项目名称:Export,代码行数:26,代码来源:Gzip.java

示例7: tarFiles

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
/**
 * @param fileList
 *
 * @return
 *
 * @throws IOException
 * @throws CompressorException
 */
public static String tarFiles(String dir, String fileNamePrefix, List<File> fileList)
    throws IOException, CompressorException {

    //
    OsUtil.makeDirs(dir);

    // 时间
    String curTime = DateUtils.format(new Date(), DataFormatConstants.COMMON_TIME_FORMAT);

    // 文件名
    String outputFilePath = fileNamePrefix + "_" + curTime + ".tar.gz";
    File outputFile = new File(dir, outputFilePath);

    FileOutputStream out = null;
    out = new FileOutputStream(outputFile);

    //
    // 进行打包
    //
    TarArchiveOutputStream os = new TarArchiveOutputStream(out);
    for (File file : fileList) {
        os.putArchiveEntry(new TarArchiveEntry(file, file.getName()));
        IOUtils.copy(new FileInputStream(file), os);
        os.closeArchiveEntry();
    }

    if (os != null) {
        try {
            os.flush();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return outputFile.getAbsolutePath();
}
 
开发者ID:knightliao,项目名称:disconf,代码行数:46,代码来源:TarUtils.java

示例8: writeTo

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //导入方法依赖的package包/类
public String writeTo(final OutputStream outputStream) throws IOException {
    checkState(appManifest != null || filesetManifest != null,
            "neither AppManifest nor a FilesetManifest is given");

    final OutputStream bufferedOutputStream;
    if (buffering) {
        bufferedOutputStream = new BufferedOutputStream(outputStream);
    } else {
        bufferedOutputStream = outputStream;
    }

    // TODO add encryption capabilities (before or after hashing/compression?) (https://github.com/coreos/rocket/issues/233)

    final OutputStream compressedOutputStream = compression.wrapStream(bufferedOutputStream);

    final HashingOutputStream hashingOutputStream = new HashingOutputStream(Hashing.sha256(),
            compressedOutputStream);

    final TarArchiveOutputStream imageOutputStream = new TarArchiveOutputStream(hashingOutputStream);

    if (appManifest != null) {
        final String appManifestJson = JSON_MAPPER.writeValueAsString(appManifest);

        final TarArchiveEntry appManifestEntry = new TarArchiveEntry("/app");
        appManifestEntry.setSize(appManifestJson.length());

        imageOutputStream.putArchiveEntry(appManifestEntry);
        imageOutputStream.write(appManifestJson.getBytes(MANIFEST_CHARSET));
        imageOutputStream.closeArchiveEntry();
    }

    if (filesetManifest != null) {
        final String filesetManifestJson = JSON_MAPPER.writeValueAsString(filesetManifest);

        final TarArchiveEntry filesetManifestEntry = new TarArchiveEntry("/fileset");
        filesetManifestEntry.setSize(filesetManifestJson.length());

        imageOutputStream.putArchiveEntry(filesetManifestEntry);
        imageOutputStream.write(filesetManifestJson.getBytes(MANIFEST_CHARSET));
        imageOutputStream.closeArchiveEntry();
    }

    for (final Content content : contents) {
        content.addToImage(imageOutputStream);
    }

    imageOutputStream.flush();

    return hashingOutputStream.hash().toString();
}
 
开发者ID:sarnowski,项目名称:aci,代码行数:51,代码来源:ACIWriter.java


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