Search in sources :

Example 1 with TarInputStream

use of org.apache.tools.tar.TarInputStream in project OpenGrok by OpenGrok.

the class TarAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    ArrayList<String> names = new ArrayList<>();
    try (TarInputStream zis = new TarInputStream(src.getStream())) {
        TarEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            names.add(name);
            if (xrefOut != null) {
                Util.htmlize(name, xrefOut);
                xrefOut.append("<br/>");
            }
        }
    }
    doc.add(new TextField("full", new IteratorReader(names)));
}
Also used : IteratorReader(org.opensolaris.opengrok.analysis.IteratorReader) TarInputStream(org.apache.tools.tar.TarInputStream) ArrayList(java.util.ArrayList) TextField(org.apache.lucene.document.TextField) TarEntry(org.apache.tools.tar.TarEntry)

Example 2 with TarInputStream

use of org.apache.tools.tar.TarInputStream in project ant by apache.

the class TarResource method fetchEntry.

/**
 * fetches information from the named entry inside the archive.
 */
@Override
protected void fetchEntry() {
    Resource archive = getArchive();
    try (TarInputStream i = new TarInputStream(archive.getInputStream())) {
        TarEntry te = null;
        while ((te = i.getNextEntry()) != null) {
            if (te.getName().equals(getName())) {
                setEntry(te);
                return;
            }
        }
    } catch (IOException e) {
        log(e.getMessage(), Project.MSG_DEBUG);
        throw new BuildException(e);
    }
    setEntry(null);
}
Also used : TarInputStream(org.apache.tools.tar.TarInputStream) Resource(org.apache.tools.ant.types.Resource) TarEntry(org.apache.tools.tar.TarEntry) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 3 with TarInputStream

use of org.apache.tools.tar.TarInputStream in project gradle by gradle.

the class AntTarPacker method unpack.

@Override
public void unpack(DataSource input, DataTargetFactory targetFactory) throws IOException {
    TarInputStream tarInput = new TarInputStream(input.openInput());
    while (true) {
        TarEntry entry = tarInput.getNextEntry();
        if (entry == null) {
            break;
        }
        PackerUtils.unpackEntry(entry.getName(), tarInput, buffer, targetFactory);
    }
    tarInput.close();
}
Also used : TarInputStream(org.apache.tools.tar.TarInputStream) TarEntry(org.apache.tools.tar.TarEntry)

Example 4 with TarInputStream

use of org.apache.tools.tar.TarInputStream in project OpenRefine by OpenRefine.

the class ImportingUtilities method explodeArchive.

public static boolean explodeArchive(File rawDataDir, InputStream archiveIS, JSONObject archiveFileRecord, JSONArray fileRecords, final Progress progress) {
    if (archiveIS instanceof TarInputStream) {
        TarInputStream tis = (TarInputStream) archiveIS;
        try {
            TarEntry te;
            while (!progress.isCanceled() && (te = tis.getNextEntry()) != null) {
                if (!te.isDirectory()) {
                    String fileName2 = te.getName();
                    File file2 = allocateFile(rawDataDir, fileName2);
                    progress.setProgress("Extracting " + fileName2, -1);
                    JSONObject fileRecord2 = new JSONObject();
                    JSONUtilities.safePut(fileRecord2, "origin", JSONUtilities.getString(archiveFileRecord, "origin", null));
                    JSONUtilities.safePut(fileRecord2, "declaredEncoding", (String) null);
                    JSONUtilities.safePut(fileRecord2, "declaredMimeType", (String) null);
                    JSONUtilities.safePut(fileRecord2, "fileName", fileName2);
                    JSONUtilities.safePut(fileRecord2, "archiveFileName", JSONUtilities.getString(archiveFileRecord, "fileName", null));
                    JSONUtilities.safePut(fileRecord2, "location", getRelativePath(file2, rawDataDir));
                    JSONUtilities.safePut(fileRecord2, "size", saveStreamToFile(tis, file2, null));
                    postProcessSingleRetrievedFile(file2, fileRecord2);
                    JSONUtilities.append(fileRecords, fileRecord2);
                }
            }
        } catch (IOException e) {
            // TODO: what to do?
            e.printStackTrace();
        }
        return true;
    } else if (archiveIS instanceof ZipInputStream) {
        ZipInputStream zis = (ZipInputStream) archiveIS;
        try {
            ZipEntry ze;
            while (!progress.isCanceled() && (ze = zis.getNextEntry()) != null) {
                if (!ze.isDirectory()) {
                    String fileName2 = ze.getName();
                    File file2 = allocateFile(rawDataDir, fileName2);
                    progress.setProgress("Extracting " + fileName2, -1);
                    JSONObject fileRecord2 = new JSONObject();
                    JSONUtilities.safePut(fileRecord2, "origin", JSONUtilities.getString(archiveFileRecord, "origin", null));
                    JSONUtilities.safePut(fileRecord2, "declaredEncoding", (String) null);
                    JSONUtilities.safePut(fileRecord2, "declaredMimeType", (String) null);
                    JSONUtilities.safePut(fileRecord2, "fileName", fileName2);
                    JSONUtilities.safePut(fileRecord2, "archiveFileName", JSONUtilities.getString(archiveFileRecord, "fileName", null));
                    JSONUtilities.safePut(fileRecord2, "location", getRelativePath(file2, rawDataDir));
                    JSONUtilities.safePut(fileRecord2, "size", saveStreamToFile(zis, file2, null));
                    postProcessSingleRetrievedFile(file2, fileRecord2);
                    JSONUtilities.append(fileRecords, fileRecord2);
                }
            }
        } catch (IOException e) {
            // TODO: what to do?
            e.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) JSONObject(org.json.JSONObject) TarInputStream(org.apache.tools.tar.TarInputStream) ZipEntry(java.util.zip.ZipEntry) TarEntry(org.apache.tools.tar.TarEntry) IOException(java.io.IOException) File(java.io.File)

Example 5 with TarInputStream

use of org.apache.tools.tar.TarInputStream in project ant by apache.

the class TarScanner method fillMapsFromArchive.

/**
 * Fills the file and directory maps with resources read from the
 * archive.
 *
 * @param src the archive to scan.
 * @param encoding encoding used to encode file names inside the archive.
 * @param fileEntries Map (name to resource) of non-directory
 * resources found inside the archive.
 * @param matchFileEntries Map (name to resource) of non-directory
 * resources found inside the archive that matched all include
 * patterns and didn't match any exclude patterns.
 * @param dirEntries Map (name to resource) of directory
 * resources found inside the archive.
 * @param matchDirEntries Map (name to resource) of directory
 * resources found inside the archive that matched all include
 * patterns and didn't match any exclude patterns.
 */
protected void fillMapsFromArchive(Resource src, String encoding, Map<String, Resource> fileEntries, Map<String, Resource> matchFileEntries, Map<String, Resource> dirEntries, Map<String, Resource> matchDirEntries) {
    try (TarInputStream ti = new TarInputStream(src.getInputStream(), encoding)) {
        try {
            TarEntry entry = null;
            while ((entry = ti.getNextEntry()) != null) {
                Resource r = new TarResource(src, entry);
                String name = entry.getName();
                if (entry.isDirectory()) {
                    name = trimSeparator(name);
                    dirEntries.put(name, r);
                    if (match(name)) {
                        matchDirEntries.put(name, r);
                    }
                } else {
                    fileEntries.put(name, r);
                    if (match(name)) {
                        matchFileEntries.put(name, r);
                    }
                }
            }
        } catch (IOException ex) {
            throw new BuildException("problem reading " + srcFile, ex);
        }
    } catch (IOException ex) {
        throw new BuildException("problem opening " + srcFile, ex);
    }
}
Also used : TarInputStream(org.apache.tools.tar.TarInputStream) TarResource(org.apache.tools.ant.types.resources.TarResource) TarEntry(org.apache.tools.tar.TarEntry) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) TarResource(org.apache.tools.ant.types.resources.TarResource)

Aggregations

TarEntry (org.apache.tools.tar.TarEntry)7 TarInputStream (org.apache.tools.tar.TarInputStream)7 BuildException (org.apache.tools.ant.BuildException)4 IOException (java.io.IOException)3 Resource (org.apache.tools.ant.types.Resource)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 TextField (org.apache.lucene.document.TextField)1 TarResource (org.apache.tools.ant.types.resources.TarResource)1 FileNameMapper (org.apache.tools.ant.util.FileNameMapper)1 JSONObject (org.json.JSONObject)1 IteratorReader (org.opensolaris.opengrok.analysis.IteratorReader)1