當前位置: 首頁>>代碼示例>>Java>>正文


Java TarArchiveOutputStream.finish方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish方法的典型用法代碼示例。如果您正苦於以下問題:Java TarArchiveOutputStream.finish方法的具體用法?Java TarArchiveOutputStream.finish怎麽用?Java TarArchiveOutputStream.finish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.archivers.tar.TarArchiveOutputStream的用法示例。


在下文中一共展示了TarArchiveOutputStream.finish方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createArchive

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Create a gzipped tar archive containing the ProGuard/Native mapping files
 *
 * @param files array of mapping.txt files
 * @return the tar-gzipped archive
 */
private static File createArchive(List<File> files, String uuid) {
    try {
        File tarZippedFile = File.createTempFile("tar-zipped-file", ".tgz");
        TarArchiveOutputStream taos = new TarArchiveOutputStream(
                    new GZIPOutputStream(
                                new BufferedOutputStream(
                                            new FileOutputStream(tarZippedFile))));
        for (File file : files) {
            taos.putArchiveEntry(new TarArchiveEntry(file,
                    (uuid != null && !uuid.isEmpty() ? uuid : UUID.randomUUID()) + ".txt"));
            IOUtils.copy(new FileInputStream(file), taos);
            taos.closeArchiveEntry();
        }
        taos.finish();
        taos.close();
        return tarZippedFile;
    } catch (IOException e) {
        failWithError("IO Exception while trying to tar and zip the file.", e);
        return null;
    }
}
 
開發者ID:flurry,項目名稱:upload-clients,代碼行數:28,代碼來源:UploadMapping.java

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

示例3: copyFileOut

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //導入方法依賴的package包/類
public void copyFileOut(String containerId, File output, String pathInContainer)
		throws DockerException, InterruptedException, IOException {
	File temp = new File(output.getParent() + File.separator + "_temp.tar");
	Files.createParentDirs(temp);
	if (!temp.createNewFile())
		throw new IOException("can not new temp file: " + temp.toString());
	TarArchiveOutputStream aos = new TarArchiveOutputStream(new FileOutputStream(temp));
	try (final TarArchiveInputStream tarStream = new TarArchiveInputStream(
			client.archiveContainer(containerId, pathInContainer))) {
		TarArchiveEntry entry;
		while ((entry = tarStream.getNextTarEntry()) != null) {
			aos.putArchiveEntry(entry);
			IOUtils.copy(tarStream, aos);
			aos.closeArchiveEntry();
		}
	}
	aos.finish();
	aos.close();
	boolean unTarStatus = unTar(new TarArchiveInputStream(new FileInputStream(temp)), output.getParent());
	StringBuilder builder = new StringBuilder();
	if (!unTarStatus)
		throw new RuntimeException("un tar file error");
	if (!temp.delete())
		builder.append("temp file delete failed, but ");
	LOGGER.info(builder.append("copy files ").append(pathInContainer).append(" out of container ")
			.append(containerId).append(" successful").toString());
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:28,代碼來源:DockerOperator.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();
    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

示例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();
    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

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

示例7: createTar

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //導入方法依賴的package包/類
/**
 * Creates the tar file with the created JRE for sending to the roborio
 */
private void createTar() {
    File tgzFile = new File("." + File.separator + Arguments.JRE_DEFAULT_NAME);
    File tgzMd5File = new File(tgzFile.getPath() + ".md5");
    if (tgzFile.exists()) {
        tgzFile.delete();
        m_logger.debug("Removed the old tgz file");
    }
    if (tgzMd5File.exists()) {
        tgzMd5File.delete();
        m_logger.debug("Removed the old md5 file");
    }

    try {
        m_logger.debug("Starting zip");
        tgzFile.createNewFile();
        TarArchiveOutputStream tgzStream = new TarArchiveOutputStream(new GZIPOutputStream(
                new BufferedOutputStream(new FileOutputStream(tgzFile))));
        addFileToTarGz(tgzStream, m_jreLocation, "");
        tgzStream.finish();
        tgzStream.close();
        m_logger.debug("Finished zip, starting md5 hash");

        Platform.runLater(() -> fileLabel.setText("Generating md5 hash"));
        String md5Hash = MainApp.hashFile(tgzFile);
        OutputStream md5Out = new BufferedOutputStream(new FileOutputStream(tgzMd5File));
        md5Out.write(md5Hash.getBytes());
        md5Out.flush();
        md5Out.close();
        m_logger.debug("Finished md5 hash, hash is " + md5Hash);
        final boolean interrupted = Thread.interrupted();

        // Show the connect roboRio screen
        Platform.runLater(() -> {
            if (!interrupted) {
                m_args.setArgument(Arguments.Argument.JRE_TAR, tgzFile.getAbsolutePath());
                moveNext(Arguments.Controller.CONNECT_ROBORIO_CONTROLLER);
            }
        });
    } catch (IOException | NoSuchAlgorithmException e) {
        m_logger.error("Could not create the tar gz file. Do we have write permissions to the current working directory?", e);
        showErrorScreen(e);
    }
}
 
開發者ID:wpilibsuite,項目名稱:java-installer,代碼行數:47,代碼來源:TarJREController.java

示例8: disposeContainer

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; //導入方法依賴的package包/類
@Override
protected void disposeContainer(TarArchiveOutputStream container) throws IOException {
    container.finish();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:5,代碼來源:MCRTarServlet.java


注:本文中的org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.finish方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。