List of usage examples for org.apache.commons.vfs2.provider AbstractFileName getParent
public FileName getParent()
From source file:com.github.junrar.vfs2.provider.rar.RARFileSystem.java
@Override public void init() throws FileSystemException { super.init(); try {//from w ww . j a va2 s . c o m try { archive = new Archive(new VFSVolumeManager(parentLayer)); // Build the index List<RARFileObject> strongRef = new ArrayList<RARFileObject>(100); for (final FileHeader header : archive.getFileHeaders()) { AbstractFileName name = (AbstractFileName) getFileSystemManager().resolveName(getRootName(), UriParser.encode(header.getFileNameString())); // Create the file RARFileObject fileObj; if (header.isDirectory() && getFileFromCache(name) != null) { fileObj = (RARFileObject) getFileFromCache(name); fileObj.setHeader(header); continue; } fileObj = createRARFileObject(name, header); putFileToCache(fileObj); strongRef.add(fileObj); fileObj.holdObject(strongRef); // Make sure all ancestors exist RARFileObject parent; for (AbstractFileName parentName = (AbstractFileName) name .getParent(); parentName != null; fileObj = parent, parentName = (AbstractFileName) parentName .getParent()) { // Locate the parent parent = (RARFileObject) getFileFromCache(parentName); if (parent == null) { parent = createRARFileObject(parentName, null); putFileToCache(parent); strongRef.add(parent); parent.holdObject(strongRef); } // Attach child to parent parent.attachChild(fileObj.getName()); } } } catch (RarException e) { throw new FileSystemException(e); } catch (IOException e) { throw new FileSystemException(e); } } finally { // closeCommunicationLink(); } }
From source file:org.ysb33r.groovy.vfsplugin.cpio.CpioFileSystem.java
@Override public void init() throws FileSystemException { super.init(); // Build the index try {/* ww w .j av a 2 s. co m*/ final List<CpioFileObject> strongRef = new ArrayList<CpioFileObject>(DEFAULT_INDEX_SIZE); CpioArchiveEntry entry; while ((entry = getCpioFile().getNextCPIOEntry()) != null) { final AbstractFileName name = (AbstractFileName) getFileSystemManager().resolveName(getRootName(), UriParser.encode(entry.getName())); // Create the file CpioFileObject fileObj; if (entry.isDirectory() && getFileFromCache(name) != null) { fileObj = (CpioFileObject) getFileFromCache(name); fileObj.setCpioEntry(entry); continue; } fileObj = createCpioFileObject(name, entry); putFileToCache(fileObj); strongRef.add(fileObj); fileObj.holdObject(strongRef); // Make sure all ancestors exist // TODO - create these on demand CpioFileObject parent = null; for (AbstractFileName parentName = (AbstractFileName) name .getParent(); parentName != null; fileObj = parent, parentName = (AbstractFileName) parentName .getParent()) { // Locate the parent parent = (CpioFileObject) getFileFromCache(parentName); if (parent == null) { parent = createCpioFileObject(parentName, null); putFileToCache(parent); strongRef.add(parent); parent.holdObject(strongRef); } // Attach child to parent parent.attachChild(fileObj.getName()); } } } catch (final IOException e) { throw new FileSystemException(e); } finally { closeCommunicationLink(); } }