use of loci.common.ZipHandle in project bioformats by openmicroscopy.
the class ZipReader method initFile.
// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);
reader = new ImageReader();
reader.setMetadataOptions(getMetadataOptions());
reader.setMetadataFiltered(isMetadataFiltered());
reader.setOriginalMetadataPopulated(isOriginalMetadataPopulated());
reader.setNormalized(isNormalized());
reader.setMetadataStore(getMetadataStore());
String innerFile = id;
if (checkSuffix(id, "zip")) {
innerFile = id.substring(0, id.length() - 4);
}
int sep = innerFile.lastIndexOf(File.separator);
if (sep < 0) {
sep = innerFile.lastIndexOf("/");
}
if (sep >= 0) {
innerFile = innerFile.substring(sep + 1);
}
// NB: We need a raw handle on the ZIP data itself, not a ZipHandle.
IRandomAccess rawHandle = Location.getHandle(id, false, false);
in = new RandomAccessInputStream(rawHandle, id);
ZipInputStream zip = new ZipInputStream(in);
ZipEntry ze = null;
entryName = null;
boolean matchFound = false;
while (true) {
ze = zip.getNextEntry();
if (ze == null)
break;
if (entryName == null) {
entryName = ze.getName();
}
if (!matchFound && ze.getName().startsWith(innerFile)) {
entryName = ze.getName();
matchFound = true;
}
ZipHandle handle = new ZipHandle(id, ze);
Location.mapFile(ze.getName(), handle);
mappedFiles.add(ze.getName());
}
if (entryName == null) {
throw new FormatException("Zip file does not contain any valid files");
}
reader.setId(entryName);
metadataStore = reader.getMetadataStore();
core = new ArrayList<CoreMetadata>(reader.getCoreMetadataList());
metadata = reader.getGlobalMetadata();
}
Aggregations