Example usage for org.apache.commons.compress.archivers.tar TarInputStream close

List of usage examples for org.apache.commons.compress.archivers.tar TarInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this stream.

Usage

From source file:ch.randelshofer.cubetwister.HTMLExporter.java

private int countHTMLTemplates(ProgressObserver p) throws IOException {
    int count = 0;

    HashSet<CubeKind> cubeKinds = new HashSet<CubeKind>();
    EntityModel dmtn = model.getChild(model.getRoot(), DocumentModel.CUBE_INDEX);
    for (EntityModel node : dmtn.getChildren()) {
        CubeModel cm = (CubeModel) node;
        cubeKinds.add(cm.getKind());//  ww  w .  j  a v  a2  s . com
    }
    int cubeCount = dmtn.getChildCount();
    dmtn = model.getChild(model.getRoot(), DocumentModel.NOTATION_INDEX);
    int notationCount = dmtn.getChildCount();
    dmtn = model.getChild(model.getRoot(), DocumentModel.SCRIPT_INDEX);
    int scriptCount = dmtn.getChildCount();
    dmtn = model.getChild(model.getRoot(), DocumentModel.TEXT_INDEX);
    int textCount = dmtn.getChildCount();

    TarInputStream tin = null;
    try {
        InputStream in = getClass().getResourceAsStream("/htmltemplates.tar.bz");
        in.read(); // skip header chars;
        in.read();
        tin = new TarInputStream(new BZip2CompressorInputStream(in));

        for (TarArchiveEntry entry = tin.getNextEntry(); entry != null && !p.isCanceled();) {
            if (entry.isDirectory()) {
                //System.out.println("dir:" + entry.getName());
            } else {
                //System.out.println("file:"+entry.getName());

                String name = entry.getName();
                if (name.indexOf("${cube}") != -1) {
                    count += cubeCount;
                } else if (name.indexOf("${notation}") != -1) {
                    count += notationCount;
                } else if (name.indexOf("${script}") != -1) {
                    count += scriptCount;
                } else if (name.indexOf("${note}") != -1) {
                    count += textCount;
                } else if (name.endsWith(".html")) {
                    count++;
                } else if (name.endsWith(".jar.pack.gz")) {
                    count++;
                } else {
                    count++;
                }

            }

            entry = tin.getNextEntry();
        }

    } finally {
        if (tin != null) {
            tin.close();
        }
    }

    return count;
}

From source file:ch.randelshofer.cubetwister.HTMLExporter.java

private void processHTMLTemplates(ProgressObserver p) throws IOException {
    TarInputStream tin = null;
    try {//from w w w .j a va 2s  .co  m
        InputStream in = getClass().getResourceAsStream("/htmltemplates.tar.bz");
        in.read(); // skip header chars;
        in.read();
        tin = new TarInputStream(new BZip2CompressorInputStream(in));

        for (TarArchiveEntry entry = tin.getNextEntry(); entry != null && !p.isCanceled();) {
            if (entry.isDirectory()) {
                //System.out.println("dir:" + entry.getName());
            } else {
                //System.out.println("file:"+entry.getName());

                String name = entry.getName();
                if (name.indexOf("${cube}") != -1) {
                    processCubeTemplate(name, toTokens(name, tin));
                } else if (name.indexOf("${notation}") != -1) {
                    processNotationTemplate(name, toTokens(name, tin));
                } else if (name.indexOf("${script}") != -1) {
                    processScriptTemplate(name, toTokens(name, tin));
                } else if (name.indexOf("${note}") != -1) {
                    processNoteTemplate(name, toTokens(name, tin));
                } else if (name.endsWith(".html")) {
                    processHTMLTemplate(name, toTokens(name, tin));
                } else if (name.endsWith(".jar.pack.gz")) {
                    processPack200Template(name, tin);
                } else {
                    processBinaryTemplate(name, tin);
                }

            }

            entry = tin.getNextEntry();
        }

    } finally {
        if (tin != null) {
            tin.close();
        }
    }
}