/** Get the name of the file system that would be used to access a given file or directory. * @param path * @return name Name of the file system, or null if no filesystem found */ public static String getFileSystemName(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return null; return fs.name(); }
/** Returns a RandomAccessFile implementation accessing the specificed file */ public static RandomDataInput openFileRandom(String filename) throws IOException { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) throw new FileNotFoundException("No file system for "+filename); if ((fs.capabilities() & FSCapability.RANDOM_READ) == 0) throw new IOException("File system not supporting random reads for "+ filename); return fs.openFileRandom(filename); }
/** Returns a RandomAccessFile implementation accessing the specificed file */ public static RandomDataInput openFileRandom(String filename) throws IOException { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) throw new FileNotFoundException("No file system for "+filename); if ((fs.capabilities() & FSCapability.RANDOM_READ) == 0) throw new IOException("File system not supporting random reads for "+ filename); return fs.openFileRandom(filename); }
/** Get the name of the file system that would be used to access a given file or directory. * @param path * @return name Name of the file system, or null if no filesystem found */ public static String getFileSystemName(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return null; return fs.name(); }
/** Returns a RandomAccessFile implementation accessing the specificed file */ public static RandomDataOutput writeFileRandom(String filename) throws IOException { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) throw new FileNotFoundException("No file system for "+filename); if ((fs.capabilities() & FSCapability.RANDOM_WRITE) == 0) throw new IOException("File system not supporting random writes for "+ filename); return fs.writeFileRandom(filename); }
/** Returns a RandomAccessFile implementation accessing the specificed file */ public static RandomDataOutput writeFileRandom(String filename) throws IOException { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) throw new FileNotFoundException("No file system for "+filename); if ((fs.capabilities() & FSCapability.RANDOM_WRITE) == 0) throw new IOException("File system not supporting random writes for "+ filename); return fs.writeFileRandom(filename); }
/** returns the length of the file, or 0L if cannot be found etc */ public static long length(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return 0L; if ((fs.capabilities() & FSCapability.STAT) == 0) return 0L; try{ return fs.length(filename); } catch (IOException ioe) { return 0L; } }
/** List the contents of a directory */ public static String[] list(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return EMPTY_STRING_ARRAY; if ((fs.capabilities() & FSCapability.LS_DIR) == 0) return EMPTY_STRING_ARRAY; try{ return fs.list(path); } catch (IOException ioe) { return EMPTY_STRING_ARRAY; } }
/** returns true iff path can be read */ public static boolean canWrite(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return false; if ((fs.capabilities() & (FSCapability.WRITE | FSCapability.STAT )) == 0) return false; try{ return fs.canWrite(filename); } catch (IOException ioe) { return false; } }
/** What is the parent path to the specified path? */ public static String getParent(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return null; if ((fs.capabilities() & FSCapability.STAT) == 0) return null; try{ return fs.getParent(path); } catch (IOException ioe) { return null; } }
/** returns true iff path can be read */ public static boolean canWrite(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return false; if ((fs.capabilities() & (FSCapability.WRITE | FSCapability.STAT )) == 0) return false; try{ return fs.canWrite(filename); } catch (IOException ioe) { return false; } }
/** returns true if the specificed path can be made as a directory */ public static boolean mkdir(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return false; if ((fs.capabilities() & FSCapability.WRITE) == 0) return false; try{ return fs.mkdir(path); } catch (IOException ioe) { return false; } }
/** return true if path is a directory */ public static boolean isDirectory(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return false; if ((fs.capabilities() & FSCapability.STAT) == 0) return false; try{ return fs.isDirectory(path); } catch (IOException ioe) { return false; } }
/** returns the length of the file, or 0L if cannot be found etc */ public static long length(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return 0L; if ((fs.capabilities() & FSCapability.STAT) == 0) return 0L; try{ return fs.length(filename); } catch (IOException ioe) { return 0L; } }
/** return true if path is a directory */ public static boolean isDirectory(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return false; if ((fs.capabilities() & FSCapability.STAT) == 0) return false; try{ return fs.isDirectory(path); } catch (IOException ioe) { return false; } }
/** returns true iff path can be read */ public static boolean canRead(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return false; if ((fs.capabilities() & (FSCapability.READ | FSCapability.STAT)) == 0) return true; try{ return fs.canRead(filename); } catch (IOException ioe) { return false; } }
/** returns true iff path can be read */ public static boolean canRead(String filename) { filename = transform(filename); final FileSystem fs = getFileSystem(filename); if (fs == null) return false; if ((fs.capabilities() & (FSCapability.READ | FSCapability.STAT)) == 0) return true; try{ return fs.canRead(filename); } catch (IOException ioe) { return false; } }
/** What is the parent path to the specified path? */ public static String getParent(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return null; if ((fs.capabilities() & FSCapability.STAT) == 0) return null; try{ return fs.getParent(path); } catch (IOException ioe) { return null; } }
/** returns true iff the path is really a path */ public static boolean exists(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return false; //System.err.printf("Cap: %d Stat: %d check: %d\n", fs.capabilities() , FSCapability.STAT, (fs.capabilities() & FSCapability.STAT)); if ((fs.capabilities() & FSCapability.STAT) == 0) return true; try{ return fs.exists(path); } catch (IOException ioe) { return false; } }
/** List the contents of a directory */ public static String[] list(String path) { path = transform(path); final FileSystem fs = getFileSystem(path); if (fs == null) return EMPTY_STRING_ARRAY; if ((fs.capabilities() & FSCapability.LS_DIR) == 0) return EMPTY_STRING_ARRAY; try{ return fs.list(path); } catch (IOException ioe) { return EMPTY_STRING_ARRAY; } }