Package org.terrier.utility.io

Examples of org.terrier.utility.io.FileSystem


  /** 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);
  }
View Full Code Here


    * @param filename path to file to delete
    */
  public static boolean delete(String filename)
  {
    filename = transform(filename);
    final FileSystem fs = getFileSystem(filename);
    if (fs == null)
      return false;
    if ((fs.capabilities() & FSCapability.WRITE) == 0)
      return false;
    try{
      return fs.delete(filename);
    } catch (IOException ioe) {
      return false;
    }
  }
View Full Code Here

    * have write capability, or the file system does not have deleteOnExit
    * capability */
  public static boolean deleteOnExit(String path)
  {
    path = transform(path);
        final FileSystem fs = getFileSystem(path);
        if (fs == null)
            return false;
    if ((fs.capabilities() & FSCapability.WRITE) == 0)
            return false;
    if ((fs.capabilities() & FSCapability.DEL_ON_EXIT) == 0)
      return false
    try{
            return fs.deleteOnExit(path);
        } catch (IOException ioe) {
            return false;
        }
  }
View Full Code Here

  /** 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;
    }
  }
View Full Code Here

  /** 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;
    }
  }
View Full Code Here

  /** 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;
    }
  }
View Full Code Here

  /** 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;
    }
  }
View Full Code Here

  /** 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;
    }
  }
View Full Code Here

  /** 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;
        }
  }
View Full Code Here

  /** rename a file or directory. If the two are on different file systems, it is assumed to be a file */
  public static boolean rename(String sourceFilename, String destFilename)
  {
    sourceFilename = transform(sourceFilename);
    destFilename = transform(destFilename);
    final FileSystem destFS = getFileSystem(destFilename);
    final FileSystem sourceFS = getFileSystem(sourceFilename);
    try{
      if (destFS == sourceFS)//yes, that's object equals
      {
        sourceFS.rename(sourceFilename, destFilename);
      }
      else
      {
        copyFile(sourceFS.openFileStream(sourceFilename), destFS.writeFileStream(destFilename));
        sourceFS.delete(sourceFilename);
      }
      return true;
    } catch (IOException ioe) {
      return false;
    }
View Full Code Here

TOP

Related Classes of org.terrier.utility.io.FileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.