Search in sources :

Example 1 with ArchiveEntry

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

the class CopyDialog method createTransferFileJob.

// ////////////////////////////////////////////
// TransferDestinationDialog implementation //
// ////////////////////////////////////////////
@Override
protected TransferFileJob createTransferFileJob(ProgressDialog progressDialog, PathUtils.ResolvedDestination resolvedDest, int defaultFileExistsAction) {
    AbstractFile baseFolder = files.getBaseFolder();
    AbstractArchiveFile parentArchiveFile = baseFolder.getParentArchive();
    TransferFileJob job;
    String newName = resolvedDest.getDestinationType() == DestinationType.EXISTING_FOLDER ? null : resolvedDest.getDestinationFile().getName();
    // their natural order (more efficient)
    if (parentArchiveFile != null) {
        // Add all selected archive entries to a vector
        int nbFiles = files.size();
        List<ArchiveEntry> selectedEntries = new Vector<ArchiveEntry>();
        for (int i = 0; i < nbFiles; i++) {
            selectedEntries.add((ArchiveEntry) files.elementAt(i).getAncestor(AbstractArchiveEntryFile.class).getUnderlyingFileObject());
        }
        job = new UnpackJob(progressDialog, mainFrame, parentArchiveFile, PathUtils.getDepth(baseFolder.getAbsolutePath(), baseFolder.getSeparator()) - PathUtils.getDepth(parentArchiveFile.getAbsolutePath(), parentArchiveFile.getSeparator()), resolvedDest.getDestinationFolder(), newName, defaultFileExistsAction, selectedEntries);
    } else {
        job = new CopyJob(progressDialog, mainFrame, files, resolvedDest.getDestinationFolder(), newName, TransferMode.COPY, defaultFileExistsAction);
    }
    return job;
}
Also used : AbstractArchiveFile(com.mucommander.commons.file.archive.AbstractArchiveFile) AbstractArchiveEntryFile(com.mucommander.commons.file.archive.AbstractArchiveEntryFile) TransferFileJob(com.mucommander.job.impl.TransferFileJob) AbstractFile(com.mucommander.commons.file.AbstractFile) UnpackJob(com.mucommander.job.impl.UnpackJob) CopyJob(com.mucommander.job.impl.CopyJob) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) Vector(java.util.Vector)

Example 2 with ArchiveEntry

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

the class TarEntryIterator method createArchiveEntry.

/**
 * Creates and returns an {@link ArchiveEntry()} whose attributes are fetched from the given
 * {@link TarArchiveEntry}.
 *
 * @param tarEntry the object that serves to initialize the attributes of the returned ArchiveEntry
 * @return an ArchiveEntry whose attributes are fetched from the given {@link TarArchiveEntry}
 */
private ArchiveEntry createArchiveEntry(TarArchiveEntry tarEntry) {
    ArchiveEntry entry = new ArchiveEntry(tarEntry.getName(), tarEntry.isDirectory(), tarEntry.getModTime().getTime(), tarEntry.getSize(), true);
    entry.setPermissions(new SimpleFilePermissions(tarEntry.getMode() & PermissionBits.FULL_PERMISSION_INT));
    entry.setOwner(tarEntry.getUserName());
    entry.setGroup(tarEntry.getGroupName());
    entry.setEntryObject(tarEntry);
    entry.setSymbolicLink(tarEntry.isSymbolicLink());
    entry.setLinkTarget(tarEntry.getLinkName());
    return entry;
}
Also used : TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) SimpleFilePermissions(com.mucommander.commons.file.SimpleFilePermissions)

Example 3 with ArchiveEntry

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

the class Bzip2ArchiveFile method getEntryIterator.

// //////////////////////////////////////
// AbstractArchiveFile implementation //
// //////////////////////////////////////
@Override
public ArchiveEntryIterator getEntryIterator() throws IOException {
    String extension = getCustomExtension() != null ? getCustomExtension() : getExtension();
    String name = getName();
    if (extension != null) {
        // Remove the 'bz2' or 'tbz2' extension from the entry's name
        extension = extension.toLowerCase();
        int extensionIndex = name.toLowerCase().lastIndexOf("." + extension);
        if (extensionIndex > -1)
            name = name.substring(0, extensionIndex);
        if (extension.equals("tbz2") || extension.equals("tar.bz2"))
            name += ".tar";
    }
    return new SingleArchiveEntryIterator(new ArchiveEntry("/" + name, false, getDate(), -1, true));
}
Also used : SingleArchiveEntryIterator(com.mucommander.commons.file.archive.SingleArchiveEntryIterator) ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry)

Example 4 with ArchiveEntry

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

the class ArArchiveEntryIterator method getNextEntry.

/**
 * Reads the next file header and returns an {@link ArchiveEntry} representing the entry.
 *
 * @return an ArchiveEntry representing the entry
 * @throws IOException if an error occurred
 */
ArchiveEntry getNextEntry() throws IOException {
    byte[] fileHeader = new byte[60];
    try {
        // Fully read the 60 file header bytes. If it cannot be read, it most likely means we've reached
        // the end of the archive.
        StreamUtils.readFully(in, fileHeader);
    } catch (IOException e) {
        return null;
    }
    try {
        // Read the 16 filename characters and trim string to remove any trailing white space
        String name = new String(fileHeader, 0, 16).trim();
        // Read the 12 file date characters, trim string to remove any trailing white space
        // and parse date as a long.
        // If the entry is the special // GNU one (see below), date is null and thus should not be parsed
        // (would throw a NumberFormatException)
        long date = name.equals("//") ? 0 : Long.parseLong(new String(fileHeader, 16, 12).trim()) * 1000;
        // No use for file's Owner ID, Group ID and mode at the moment, skip them
        // Read the 10 file size characters, trim string to remove any trailing white space
        // and parse size as a long
        long size = Long.parseLong(new String(fileHeader, 48, 10).trim());
        // in the file name field, and appending the real filename to the file header.
        if (name.startsWith("#1/")) {
            // Read extended name
            int extendedNameLength = Integer.parseInt(name.substring(3, name.length()));
            name = new String(StreamUtils.readFully(in, new byte[extendedNameLength])).trim();
            // Decrease remaining file size
            size -= extendedNameLength;
        } else // This entry appears first in the archive, i.e. before any other entries.
        if (name.equals("//")) {
            this.gnuExtendedNames = StreamUtils.readFully(in, new byte[(int) size]);
            // Skip one padding byte if size is odd
            if (size % 2 != 0)
                StreamUtils.skipFully(in, 1);
            // Don't return this entry which should not be visible, but recurse to return next entry instead
            return getNextEntry();
        } else // GNU variant: entry with an extended name, look up extended name in // entry
        if (this.gnuExtendedNames != null && name.startsWith("/")) {
            int off = Integer.parseInt(name.substring(1, name.length()));
            name = "";
            byte b;
            while ((b = this.gnuExtendedNames[off++]) != '/') name += (char) b;
        }
        return new ArchiveEntry(name, false, date, size, true);
    }// Re-throw IOException
     catch (IOException e) {
        LOGGER.info("Caught IOException", e);
        throw e;
    }// Catch any other exceptions (NumberFormatException for instance) and throw an IOException instead
     catch (Exception e2) {
        LOGGER.info("Caught Exception", e2);
        throw new IOException();
    }
}
Also used : ArchiveEntry(com.mucommander.commons.file.archive.ArchiveEntry) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with ArchiveEntry

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

the class CopyDialog method createTransferFileJob.

// ////////////////////////////////////////////
// TransferDestinationDialog implementation //
// ////////////////////////////////////////////
@Override
protected TransferFileJob createTransferFileJob(ProgressDialog progressDialog, PathUtils.ResolvedDestination resolvedDest, FileCollisionDialog.FileCollisionAction defaultFileExistsAction) {
    AbstractFile baseFolder = files.getBaseFolder();
    AbstractArchiveFile parentArchiveFile = baseFolder.getParentArchive();
    TransferFileJob job;
    String newName = resolvedDest.getDestinationType() == DestinationType.EXISTING_FOLDER ? null : resolvedDest.getDestinationFile().getName();
    // their natural order (more efficient)
    if (parentArchiveFile != null) {
        // Add all selected archive entries to a vector
        int nbFiles = files.size();
        List<ArchiveEntry> selectedEntries = new Vector<ArchiveEntry>();
        for (int i = 0; i < nbFiles; i++) {
            selectedEntries.add((ArchiveEntry) files.elementAt(i).getAncestor(AbstractArchiveEntryFile.class).getUnderlyingFileObject());
        }
        job = new UnpackJob(progressDialog, mainFrame, parentArchiveFile, PathUtils.getDepth(baseFolder.getAbsolutePath(), baseFolder.getSeparator()) - PathUtils.getDepth(parentArchiveFile.getAbsolutePath(), parentArchiveFile.getSeparator()), resolvedDest.getDestinationFolder(), newName, defaultFileExistsAction, selectedEntries);
    } else {
        job = new CopyJob(progressDialog, mainFrame, files, resolvedDest.getDestinationFolder(), newName, TransferMode.COPY, defaultFileExistsAction);
    }
    return job;
}
Also used : AbstractArchiveFile(com.mucommander.commons.file.archive.AbstractArchiveFile) AbstractArchiveEntryFile(com.mucommander.commons.file.archive.AbstractArchiveEntryFile) TransferFileJob(com.mucommander.job.impl.TransferFileJob) AbstractFile(com.mucommander.commons.file.AbstractFile) UnpackJob(com.mucommander.job.impl.UnpackJob) CopyJob(com.mucommander.job.impl.CopyJob) 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