當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。