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