/** * This method builds the parent directory hierarchy for a file. * @param foundEntry * @return the parent of the entry. */ private ZipDirectory buildParent(ZipEntry foundEntry) { ZipDirectory result = this; String name = foundEntry.getName(); name = name.substring(getNameInZip().length()); String[] paths = name.split("/"); StringBuilder baseBuilderCrapThingToGetRoundFindBugs = new StringBuilder(getNameInZip()); if (!!!isZipRoot()) baseBuilderCrapThingToGetRoundFindBugs.append('/'); // Build 'result' as a chain of ZipDirectories. This will only work if java.util.ZipFile recognises every // directory in the chain as being a ZipEntry in its own right. outer: if (paths != null && paths.length > 1) { for (int i = 0; i < paths.length - 1; i++) { String path = paths[i]; baseBuilderCrapThingToGetRoundFindBugs.append(path); ZipEntry dirEntry = getEntry(baseBuilderCrapThingToGetRoundFindBugs.toString()); if (dirEntry == null) { result = this; break outer; } result = new ZipDirectory(zip, dirEntry, result, cache); baseBuilderCrapThingToGetRoundFindBugs.append('/'); } } return result; }
private List<IFile> listFiles(boolean includeFilesInNestedSubdirs) { List<IFile> files = new ArrayList<IFile>(); ZipFile z = openZipFile(); List<? extends ZipEntry> entries = Collections.list(z.entries()); for (ZipEntry possibleEntry : entries) { if (isInDir(getNameInZip(), possibleEntry, includeFilesInNestedSubdirs)) { ZipDirectory parent = includeFilesInNestedSubdirs ? buildParent(possibleEntry) : this; if (possibleEntry.isDirectory()) { files.add(new ZipDirectory(zip, possibleEntry, parent, cache)); } else { files.add(new ZipFileImpl(zip, possibleEntry, parent, cache)); } } } closeZipFile(z); return files; }
public IFile getFile(String name) { IFile result = null; String entryName = isZipRoot() ? name : getNameInZip() + "/" + name; ZipEntry entryFile = getEntry(entryName); if (entryFile != null) { if (!!!entryFile.isDirectory()) { result = new ZipFileImpl(zip, entryFile, buildParent(entryFile), cache); } else { result = new ZipDirectory(zip, entryFile, buildParent(entryFile), cache); } } return result; }