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;
}
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;
}
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));
}
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();
}
}
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;
}
Aggregations