public IDirectory getRoot() { IDirectory root = new DirectoryImpl(rootDirFile, rootDirFile); return root; }
public IDirectory getParent() { IDirectory parent = new DirectoryImpl(file.getParentFile(), rootDirFile); return parent; }
public IFile getFile(String name) { File desiredFile = new File(file, name); IFile result = null; if (desiredFile.exists()) { if(!desiredFile.isDirectory()) result = new FileImpl(desiredFile, rootDirFile); else result = new DirectoryImpl(desiredFile, rootDirFile); } return result; }
public List<IFile> listFiles() { List<IFile> files = new ArrayList<IFile>(); File[] filesInDir = file.listFiles(); if (filesInDir != null) { for (File f : filesInDir) { if (f.isFile()) { files.add(new FileImpl(f, rootDirFile)); } else if (f.isDirectory()) { files.add(new DirectoryImpl(f, rootDirFile)); } } } return files; }
public List<IFile> listAllFiles() { List<IFile> files = new ArrayList<IFile>(); File[] filesInDir = file.listFiles(); if (filesInDir != null) { for (File f : filesInDir) { if (f.isFile()) { files.add(new FileImpl(f, rootDirFile)); } else if (f.isDirectory()) { IDirectory subdir = new DirectoryImpl(f, rootDirFile); files.add(subdir); files.addAll(subdir.listAllFiles()); } } } return files; }
/** * This method gets the IDirectory that represents the root of a virtual file * system. The provided file can either identify a directory, or a zip file. * * @param fs the zip file. * @return the root of the virtual FS. */ public static IDirectory getFSRoot(File fs, IDirectory parent) { IDirectory dir = null; if (fs.exists()) { if (fs.isDirectory()) { dir = new DirectoryImpl(fs, fs); } else if (fs.isFile() && isValidZip(fs)) { try { dir = new ZipDirectory(fs, parent); } catch (IOException e) { throw new IORuntimeException("IOException in IDirectory.getFSRoot", e); } } } else { throw new IORuntimeException("File not found in IDirectory.getFSRoot", new FileNotFoundException(fs.getPath())); } return dir; }