Search in sources :

Example 11 with ArchiveEntry

use of com.mucommander.commons.file.archive.ArchiveEntry in project mucommander by mucommander.

the class ZipArchiveFile method getEntryInputStream.

@Override
public synchronized InputStream getEntryInputStream(ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException {
    // If the underlying AbstractFile has random read access, use our own ZipFile implementation to read the entry
    if (file.isFileOperationSupported(FileOperation.RANDOM_READ_FILE)) {
        checkZipFile();
        ZipEntry zipEntry = (com.mucommander.commons.file.archive.zip.provider.ZipEntry) entry.getEntryObject();
        if (// Should not normally happen
        zipEntry == null)
            throw new IOException();
        return zipFile.getInputStream(zipEntry);
    } else // If the underlying AbstractFile doesn't have random read access, use java.util.InputStream to
    // read the entry. This is much slower than the former method as the file cannot be seeked and needs
    // to be traversed to locate the entry we're interested in.
    {
        // (unpack operation). In that case, we save the cost of looking for the entry in the archive.
        if (entryIterator != null && (entryIterator instanceof JavaUtilZipEntryIterator)) {
            ArchiveEntry currentEntry = ((JavaUtilZipEntryIterator) entryIterator).getCurrentEntry();
            if (currentEntry.getPath().equals(entry.getPath())) {
                // we don't want the ZipInputStream to be closed when the caller closes the entry's stream.
                return new FilterInputStream(((JavaUtilZipEntryIterator) entryIterator).getZipInputStream()) {

                    @Override
                    public void close() throws IOException {
                    // No-op
                    }
                };
            }
        // This is not the one, look for the entry from the beginning of the archive
        }
        // Iterate through the archive until we've found the entry
        java.util.zip.ZipInputStream zin = new java.util.zip.ZipInputStream(file.getInputStream());
        java.util.zip.ZipEntry zipEntry;
        String entryPath = entry.getPath();
        // Iterate until we find the entry we're looking for
        while ((zipEntry = zin.getNextEntry()) != null) if (// That's the one, return it
        zipEntry.getName().equals(entryPath))
            return zin;
        throw new IOException("Unknown Zip entry: " + entry.getName());
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(com.mucommander.commons.file.archive.zip.provider.ZipEntry) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) ZipInputStream(java.util.zip.ZipInputStream) com.mucommander.commons.file(com.mucommander.commons.file)

Example 12 with ArchiveEntry

use of com.mucommander.commons.file.archive.ArchiveEntry in project mucommander by mucommander.

the class ZipArchiveFile method createArchiveEntry.

/**
 * Creates and return an {@link ArchiveEntry()} whose attributes are fetched from the given {@link com.mucommander.commons.file.archive.zip.provider.ZipEntry}.
 * It is worth noting that the returned entry has the {@link ArchiveEntry#exists exists} flag set to <code>true</code>.
 *
 * @param zipEntry the object that serves to initialize the attributes of the returned ArchiveEntry
 * @return an ArchiveEntry whose attributes are fetched from the given ZipEntry
 */
static ArchiveEntry createArchiveEntry(ZipEntry zipEntry) {
    ArchiveEntry entry = new ArchiveEntry(zipEntry.getName(), zipEntry.isDirectory(), zipEntry.getTime(), zipEntry.getSize(), true);
    if (zipEntry.hasUnixMode())
        entry.setPermissions(new SimpleFilePermissions(zipEntry.getUnixMode()));
    entry.setEntryObject(zipEntry);
    return entry;
}
Also used : ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry)

Example 13 with ArchiveEntry

use of com.mucommander.commons.file.archive.ArchiveEntry in project mucommander by mucommander.

the class SevenZipArchiveFile method getEntryIterator.

@Override
public ArchiveEntryIterator getEntryIterator() throws IOException {
    final IInArchive sevenZipFile = openSevenZipFile();
    try {
        int nbEntries = sevenZipFile.size();
        Vector<ArchiveEntry> entries = new Vector<ArchiveEntry>();
        for (int i = 0; i < nbEntries; i++) entries.add(createArchiveEntry(sevenZipFile.getEntry(i)));
        return new WrapperArchiveEntryIterator(entries.iterator());
    } finally {
    /*try { sevenZipFile.close(); }
            catch(IOException e) {
                // Not much we can do about it
            }*/
    }
}
Also used : IInArchive(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive) WrapperArchiveEntryIterator(com.mucommander.commons.file.archive.WrapperArchiveEntryIterator) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) Vector(java.util.Vector)

Aggregations

ArchiveEntry (com.mucommander.commons.file.archive.ArchiveEntry)13 IOException (java.io.IOException)4 AbstractArchiveFile (com.mucommander.commons.file.archive.AbstractArchiveFile)3 SingleArchiveEntryIterator (com.mucommander.commons.file.archive.SingleArchiveEntryIterator)3 Vector (java.util.Vector)3 AbstractFile (com.mucommander.commons.file.AbstractFile)2 AbstractArchiveEntryFile (com.mucommander.commons.file.archive.AbstractArchiveEntryFile)2 ArchiveEntryIterator (com.mucommander.commons.file.archive.ArchiveEntryIterator)2 CopyJob (com.mucommander.job.impl.CopyJob)2 TransferFileJob (com.mucommander.job.impl.TransferFileJob)2 UnpackJob (com.mucommander.job.impl.UnpackJob)2 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)2 com.mucommander.commons.file (com.mucommander.commons.file)1 SimpleFilePermissions (com.mucommander.commons.file.SimpleFilePermissions)1 WrapperArchiveEntryIterator (com.mucommander.commons.file.archive.WrapperArchiveEntryIterator)1 IInArchive (com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive)1 ZipEntry (com.mucommander.commons.file.archive.zip.provider.ZipEntry)1 BoundedInputStream (com.mucommander.commons.io.BoundedInputStream)1 DialogAction (com.mucommander.ui.dialog.DialogAction)1 FilterInputStream (java.io.FilterInputStream)1