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

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

Introduction

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

Prototype

public void finish() throws IOException 

Source Link

Document

Ends the TAR archive without closing the underlying OutputStream.

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;
    try {/*from  w w  w  .ja  va 2s.  c o m*/
        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();
    }
}