in commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java [197:240]
public void init() throws FileSystemException {
super.init();
// Build the index
try {
TarArchiveEntry entry;
while ((entry = getTarFile().getNextTarEntry()) != null) {
final AbstractFileName name = (AbstractFileName) getFileSystemManager().resolveName(getRootName(),
UriParser.encode(entry.getName(), ENC));
// Create the file
TarFileObject fileObj;
if (entry.isDirectory() && getFileFromCache(name) != null) {
fileObj = (TarFileObject) getFileFromCache(name);
fileObj.setTarEntry(entry);
continue;
}
fileObj = createTarFileObject(name, entry);
putFileToCache(fileObj);
// Make sure all ancestors exist
// TODO - create these on demand
TarFileObject parent = null;
for (AbstractFileName parentName = (AbstractFileName) name
.getParent(); parentName != null; fileObj = parent, parentName = (AbstractFileName) parentName
.getParent()) {
// Locate the parent
parent = (TarFileObject) getFileFromCache(parentName);
if (parent == null) {
parent = createTarFileObject(parentName, null);
putFileToCache(parent);
}
// Attach child to parent
parent.attachChild(fileObj.getName());
}
}
} catch (final IOException e) {
throw new FileSystemException(e);
} finally {
closeCommunicationLink();
}
}