org.terrier.utility.io
Class LocalFileSystem

java.lang.Object
  extended by org.terrier.utility.io.LocalFileSystem
All Implemented Interfaces:
Files.FSCapability, FileSystem

public class LocalFileSystem
extends Object
implements FileSystem, Files.FSCapability

This is a Terrier File Abstraction Layer implementation of the local file system. The file system implementation for the "file:" scheme can handle all file system capabilities (READ,WRITE,RANDOM_READ,RANDOM_WRITE,LS_DIR and STAT). Generally speaking, this is a lightweight wrapper around the following four Java SE classes: java.io.File and java.io.FileInputStream and java.io.FileOutputStream, java.io.RandomAccessFile.

On Windows, this FileSystem also advertises support for all the single-letter file systems, eg A:, C:, D:

Since:
2.1
Author:
Craig Macdonald

Nested Class Summary
protected static class LocalFileSystem.LocalRandomAccessFile
          A file that supports random access
 
Field Summary
 
Fields inherited from interface org.terrier.utility.Files.FSCapability
DEL_ON_EXIT, LS_DIR, RANDOM_READ, RANDOM_WRITE, READ, STAT, WRITE
 
Constructor Summary
LocalFileSystem()
           
 
Method Summary
 boolean canRead(String filename)
          returns true if filename can be read
 boolean canWrite(String filename)
          returns true if filename can be written to
 byte capabilities()
          Get the capabilities of the file system
 boolean delete(String filename)
          Delete a file
 boolean deleteOnExit(String pathname)
          Delete the file on program exit
 boolean exists(String filename)
          Does the file exist?
 String getParent(String path)
          whats the parent path to this path - eg directory containing a file
 boolean isDirectory(String path)
          Does the path point to a directory
 long length(String filename)
          What is the length of the file?
 String[] list(String path)
          list contents of a directory etc
 boolean mkdir(String filename)
          Make a directory
 String name()
          Get the name of the file system
protected  String normalise(String filename)
           
 RandomDataInput openFileRandom(String filename)
          Opens an input random access file
 InputStream openFileStream(String filename)
          Opens an input file
 boolean rename(String source, String destination)
          rename a file/dir to another name, on the same file system
 String[] schemes()
          Get the schemes
 RandomDataOutput writeFileRandom(String filename)
          Opens a writable random access file
 OutputStream writeFileStream(String filename)
          Opens an output file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalFileSystem

public LocalFileSystem()
Method Detail

normalise

protected String normalise(String filename)

name

public String name()
Get the name of the file system

Specified by:
name in interface FileSystem

capabilities

public byte capabilities()
Get the capabilities of the file system

Specified by:
capabilities in interface FileSystem

schemes

public String[] schemes()
Get the schemes

Specified by:
schemes in interface FileSystem

exists

public boolean exists(String filename)
Does the file exist?

Specified by:
exists in interface FileSystem

canRead

public boolean canRead(String filename)
returns true if filename can be read

Specified by:
canRead in interface FileSystem

canWrite

public boolean canWrite(String filename)
returns true if filename can be written to

Specified by:
canWrite in interface FileSystem

openFileStream

public InputStream openFileStream(String filename)
                           throws IOException
Opens an input file

Specified by:
openFileStream in interface FileSystem
Throws:
IOException

writeFileStream

public OutputStream writeFileStream(String filename)
                             throws IOException
Opens an output file

Specified by:
writeFileStream in interface FileSystem
Throws:
IOException

openFileRandom

public RandomDataInput openFileRandom(String filename)
                               throws IOException
Opens an input random access file

Specified by:
openFileRandom in interface FileSystem
Throws:
IOException

writeFileRandom

public RandomDataOutput writeFileRandom(String filename)
                                 throws IOException
Opens a writable random access file

Specified by:
writeFileRandom in interface FileSystem
Throws:
IOException

delete

public boolean delete(String filename)
Delete a file

Specified by:
delete in interface FileSystem

deleteOnExit

public boolean deleteOnExit(String pathname)
                     throws IOException
Delete the file on program exit

Specified by:
deleteOnExit in interface FileSystem
Throws:
IOException

mkdir

public boolean mkdir(String filename)
Make a directory

Specified by:
mkdir in interface FileSystem

isDirectory

public boolean isDirectory(String path)
Does the path point to a directory

Specified by:
isDirectory in interface FileSystem

length

public long length(String filename)
What is the length of the file?

Specified by:
length in interface FileSystem

rename

public boolean rename(String source,
                      String destination)
               throws IOException
rename a file/dir to another name, on the same file system

Specified by:
rename in interface FileSystem
Throws:
IOException

getParent

public String getParent(String path)
                 throws IOException
whats the parent path to this path - eg directory containing a file

Specified by:
getParent in interface FileSystem
Throws:
IOException

list

public String[] list(String path)
              throws IOException
list contents of a directory etc

Specified by:
list in interface FileSystem
Throws:
IOException


Terrier 3.6. Copyright © 2004-2011 University of Glasgow