Example usage for org.apache.commons.compress.tar TarOutputStream TarOutputStream

List of usage examples for org.apache.commons.compress.tar TarOutputStream TarOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.compress.tar TarOutputStream TarOutputStream.

Prototype

public TarOutputStream(final OutputStream output) 

Source Link

Document

Construct a TarOutputStream using specified input stream and default block and record sizes.

Usage

From source file:ja.lingo.engine.Exporter.java

public void toFile(String fileName, IArticleList articleList, IMonitor monitor) throws IOException {
    File listTempFile = EngineFiles.createTempFile("html_export_list.html");

    TarOutputStream tos = null;/*  w w w. jav a  2  s .  co m*/
    try {
        tos = new TarOutputStream(
                new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))));

        DecimalFormat format = createFormat(articleList.size() - 1);

        OutputStream listOs = null;
        try {
            listOs = new BufferedOutputStream(new FileOutputStream(listTempFile));

            writeArticles(articleList, tos, listOs, format, monitor);
        } finally {
            if (listOs != null) {
                try {
                    listOs.close();
                } catch (IOException e) {
                    LOG.error("Exception caught when tried to close list HTML FileOutputStream", e);
                }
            }
        }

        putListFile(listTempFile, tos);

        putIndexFile(articleList, tos);

        putCssFile(tos);

        tos.finish();

        monitor.finish();

    } finally {
        if (tos != null) {
            try {
                tos.close();
            } catch (IOException e) {
                LOG.error("Exception caught when tried to close TarOutputStream", e);
            }
        }

        listTempFile.delete();
    }
}

From source file:org.dcm4chex.archive.hsm.FileCopyService.java

private void mkTar(List<FileInfo> fileInfos, File tarFile, String[] tarEntryNames) throws Exception {
    try {/*w w w  .  j  a  va 2s  .com*/
        if (tarFile.getParentFile().mkdirs()) {
            log.info("M-WRITE " + tarFile.getParent());
        }
        log.info("M-WRITE " + tarFile);
        TarOutputStream tar = new TarOutputStream(new FileOutputStream(tarFile));
        try {
            writeMD5SUM(tar, fileInfos, tarEntryNames);
            for (int i = 0; i < tarEntryNames.length; i++) {
                writeFile(tar, fileInfos.get(i), tarEntryNames[i]);
            }
        } finally {
            tar.close();
        }
        if (verifyCopy) {
            VerifyTar.verify(tarFile, new byte[bufferSize]);
        }
    } catch (Exception e) {
        log.error("M-DELETE tar file due to an error! " + tarFile);
        tarFile.delete();
        throw e;
    }
}

From source file:org.dcm4chex.archive.hsm.FileMoveService.java

private File[] mkTar(FileDTO[] dto, File tarFile, String[] tarEntryNames) throws Exception {
    File[] srcFiles = new File[dto.length];
    try {//from   w  w  w . jav  a  2  s  .  c o m
        if (tarFile.getParentFile().mkdirs()) {
            log.info("M-WRITE " + tarFile.getParent());
        }
        log.info("M-WRITE " + tarFile);
        TarOutputStream tar = new TarOutputStream(new FileOutputStream(tarFile));
        try {
            writeMD5SUM(tar, dto, tarEntryNames);
            for (int i = 0; i < tarEntryNames.length; i++) {
                srcFiles[i] = writeFile(tar, dto[i], tarEntryNames[i]);
            }
        } finally {
            tar.close();
        }
        if (verifyCopy) {
            VerifyTar.verify(tarFile, new byte[bufferSize]);
        }
    } catch (Exception e) {
        deleteFile(tarFile);
        throw e;
    }
    return srcFiles;
}