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

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

Introduction

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

Prototype

public void closeEntry() throws IOException 

Source Link

Document

Close an entry.

Usage

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

private void putCssFile(TarOutputStream tos) throws IOException {
    byte[] cssRawBytes = getStandaloneCssRaw().getBytes(EXPORT_ENCODING);
    TarEntry entry = new TarEntry("style.css");
    entry.setSize(cssRawBytes.length);//from ww  w.j  a v  a 2 s.c  o m
    tos.putNextEntry(entry);
    tos.write(cssRawBytes);
    tos.closeEntry();
}

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

private void putIndexFile(IArticleList articleList, TarOutputStream tos) throws IOException {
    byte[] indexFileBytes = getIndexFileContent(articleList).getBytes(EXPORT_ENCODING);

    TarEntry entry = new TarEntry("index.html");
    entry.setSize(indexFileBytes.length);
    tos.putNextEntry(entry);//w  w w  . j  a v  a  2 s .  c  o m
    tos.write(indexFileBytes);
    tos.closeEntry();
}

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

private void putListFile(File listTempFile, TarOutputStream tos) throws IOException {
    // list: append as a TAR entry
    TarEntry entry = new TarEntry("list.html");
    entry.setSize(listTempFile.length());
    tos.putNextEntry(entry);//from   ww  w.  j a v  a  2s.  c  o  m

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(listTempFile);
        tos.copyEntryContents(fis);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                LOG.error("Exception caught when tried to close list HTML FileInputStream", e);
            }
        }
    }
    tos.closeEntry();
}

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

private void writeArticles(IArticleList articleList, TarOutputStream tos, OutputStream listOs,
        DecimalFormat format, IMonitor monitor) throws IOException {
    // list: prefix
    listOs.write(getListFileHeader().getBytes(EXPORT_ENCODING));

    monitor.start(0, articleList.size());

    // traverse through articles
    for (int i = 0; i < articleList.size(); i++) {
        IArticle article = articleList.get(i);
        String articleFileName = format.format(i) + ".html";

        byte[] bytes = toHtmlStandalone(article, false).getBytes(EXPORT_ENCODING);
        TarEntry entry = new TarEntry(articleFileName);
        entry.setSize(bytes.length);/*from  w  w w  .j  a v a  2 s.c  om*/

        tos.putNextEntry(entry);
        tos.write(bytes);
        tos.closeEntry();

        // list: entry
        listOs.write(
                getListFileEntry(articleFileName, articleList.get(i).getTitle()).getBytes(EXPORT_ENCODING));

        monitor.update(i);
    }

    // list: suffix
    listOs.write(getListFileFooter().getBytes(EXPORT_ENCODING));
}

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

private void writeMD5SUM(TarOutputStream tar, List<FileInfo> fileInfos, String[] tarEntryNames)
        throws IOException {
    byte[] md5sum = new byte[fileInfos.size() * MD5SUM_ENTRY_LEN];
    final TarEntry tarEntry = new TarEntry("MD5SUM");
    tarEntry.setSize(md5sum.length);// w ww.j av  a  2  s .  c o  m
    tar.putNextEntry(tarEntry);
    int i = 0;
    for (int j = 0; j < tarEntryNames.length; j++) {
        MD5Utils.toHexChars(MD5.toBytes(fileInfos.get(j).md5), md5sum, i);
        md5sum[i + 32] = ' ';
        md5sum[i + 33] = ' ';
        System.arraycopy(tarEntryNames[j].getBytes("US-ASCII"), 0, md5sum, i + 34, 17);
        md5sum[i + 51] = '\n';
        i += MD5SUM_ENTRY_LEN;
    }
    tar.write(md5sum);
    tar.closeEntry();
}

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

private void writeFile(TarOutputStream tar, FileInfo fileInfo, String tarEntryName)
        throws IOException, FileNotFoundException {
    File file = FileUtils.toFile(fileInfo.basedir, fileInfo.fileID);
    if (file.length() != fileInfo.size) {
        log.error("Filesize doesn't match for file entry:" + fileInfo + "!(" + file.length() + " vs. "
                + fileInfo.size + ") skipped!");
        throw new IOException("Filesize doesn't match! file:" + file);
    }//from w ww  .  j av a 2 s.  c o m
    TarEntry entry = new TarEntry(tarEntryName);
    entry.setSize(fileInfo.size);
    tar.putNextEntry(entry);
    FileInputStream fis = new FileInputStream(file);
    try {
        tar.copyEntryContents(fis);
    } finally {
        fis.close();
    }
    tar.closeEntry();
}

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

private void writeMD5SUM(TarOutputStream tar, FileDTO[] dto, String[] tarEntryNames) throws IOException {
    byte[] md5sum = new byte[dto.length * MD5SUM_ENTRY_LEN];
    final TarEntry tarEntry = new TarEntry("MD5SUM");
    tarEntry.setSize(md5sum.length);/*from   ww  w.ja  va  2s.  co m*/
    tar.putNextEntry(tarEntry);
    int i = 0;
    for (int j = 0; j < tarEntryNames.length; j++) {
        MD5Utils.toHexChars(dto[j].getFileMd5(), md5sum, i);
        md5sum[i + 32] = ' ';
        md5sum[i + 33] = ' ';
        System.arraycopy(tarEntryNames[j].getBytes("US-ASCII"), 0, md5sum, i + 34, 17);
        md5sum[i + 51] = '\n';
        i += MD5SUM_ENTRY_LEN;
    }
    tar.write(md5sum);
    tar.closeEntry();
}

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

private File writeFile(TarOutputStream tar, FileDTO dto, String tarEntryName)
        throws IOException, FileNotFoundException {
    File file = FileUtils.toFile(dto.getDirectoryPath(), dto.getFilePath());
    TarEntry entry = new TarEntry(tarEntryName);
    entry.setSize(dto.getFileSize());/*from  w w  w  . ja v a2  s.  c  om*/
    tar.putNextEntry(entry);
    FileInputStream fis = new FileInputStream(file);
    try {
        tar.copyEntryContents(fis);
    } finally {
        fis.close();
    }
    tar.closeEntry();
    return file;
}