Example usage for org.apache.commons.compress.archivers.tar TarArchiveEntry getSize

List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveEntry getSize

Introduction

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

Prototype

public long getSize() 

Source Link

Document

Get this entry's file size.

Usage

From source file:uk.ac.man.cs.mdsd.webgen.ui.wizards.NewWebgenProjectOperation.java

@SuppressWarnings("unused")
private void extractTGZ(final URL sourceURL, final IPath rootPath, final int removeSegemntsCount,
        final IPath[] ignoreFilter, final Map<IPath, IPath> renames) {

    try {/* w w w  .  j a  v  a 2 s  .c  om*/
        final File tgzPath = new File(FileLocator.resolve(sourceURL).toURI());
        final TarArchiveInputStream tarIn = new TarArchiveInputStream(
                new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tgzPath))));
        TarArchiveEntry entry = (TarArchiveEntry) tarIn.getNextEntry();
        while (entry != null) {
            IPath path = new Path(entry.getName()).removeFirstSegments(removeSegemntsCount);
            if (renames.containsKey(path)) {
                path = renames.get(path);
            }
            if (rootPath != null) {
                path = new Path(rootPath.toString() + path.toString());
            }
            if (!path.isEmpty() && !ignoreEntry(path, ignoreFilter)) {
                if (entry.isDirectory()) {
                    final IFolder folder = projectHandle.getFolder(path);
                    if (!folder.exists()) {
                        folder.create(false, true, null);
                    }
                } else {
                    byte[] contents = new byte[(int) entry.getSize()];
                    tarIn.read(contents);
                    final IFile file = projectHandle.getFile(path);
                    file.create(new ByteArrayInputStream(contents), false, null);
                }
            }
            entry = (TarArchiveEntry) tarIn.getNextEntry();
        }
        tarIn.close();
    } catch (URISyntaxException | IOException | CoreException e) {
        WebgenUiPlugin.log(e);
    }
}

From source file:utybo.branchingstorytree.swing.utils.BSTPackager.java

public static BranchingStory fromPackage(InputStream in, TabClient client)
        throws IOException, BSTException, InstantiationException, IllegalAccessException {
    TarArchiveInputStream tais = new TarArchiveInputStream(new GZIPInputStream(in));
    VirtualFileHolder vfh = new VirtualFileHolder();
    TarArchiveEntry tae;
    while ((tae = tais.getNextTarEntry()) != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copyLarge(tais, baos, 0, tae.getSize());
        vfh.add(new VirtualFile(baos.toByteArray(), tae.getName()));
    }//from w  ww.  ja  v a2 s  .  com

    HashMap<String, String> meta = new Gson()
            .fromJson(new InputStreamReader(new ByteArrayInputStream(vfh.getFile("bstmeta.json").getData()),
                    StandardCharsets.UTF_8), new TypeToken<HashMap<String, String>>() {
                    }.getType());
    BranchingStoryTreeParser parser = new BranchingStoryTreeParser();
    BranchingStory bs = parser.parse(new BufferedReader(new InputStreamReader(
            new ByteArrayInputStream(vfh.getFile(meta.get("mainFile")).getData()), StandardCharsets.UTF_8)),
            new Dictionary(), client, "<main>");
    client.setBRMHandler(new BRMVirtualFileClient(vfh, client, bs));
    return bs;
}