Package org.terrier.utility.io
Class LocalFileSystem
- java.lang.Object
-
- org.terrier.utility.io.LocalFileSystem
-
- All Implemented Interfaces:
Files.FSCapability,FileSystem
public class LocalFileSystem extends java.lang.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
Nested Classes Modifier and Type Class Description protected static classLocalFileSystem.LocalRandomAccessFileA 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
Constructors Constructor Description LocalFileSystem()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead(java.lang.String filename)returns true if filename can be readbooleancanWrite(java.lang.String filename)returns true if filename can be written tobytecapabilities()Get the capabilities of the file systembooleandelete(java.lang.String filename)Delete a filebooleandeleteOnExit(java.lang.String pathname)Delete the file on program exitbooleanexists(java.lang.String filename)Does the file exist?java.lang.StringgetParent(java.lang.String path)whats the parent path to this path - eg directory containing a filebooleanisDirectory(java.lang.String path)Does the path point to a directorylonglength(java.lang.String filename)What is the length of the file?java.lang.String[]list(java.lang.String path)list contents of a directory etcbooleanmkdir(java.lang.String filename)Make a directoryjava.lang.Stringname()Get the name of the file systemprotected java.lang.Stringnormalise(java.lang.String filename)RandomDataInputopenFileRandom(java.lang.String filename)Opens an input random access filejava.io.InputStreamopenFileStream(java.lang.String filename)Opens an input filebooleanrename(java.lang.String source, java.lang.String destination)rename a file/dir to another name, on the same file systemjava.lang.String[]schemes()Get the schemesRandomDataOutputwriteFileRandom(java.lang.String filename)Opens a writable random access filejava.io.OutputStreamwriteFileStream(java.lang.String filename)Opens an output file
-
-
-
Method Detail
-
normalise
protected java.lang.String normalise(java.lang.String filename)
-
name
public java.lang.String name()
Get the name of the file system- Specified by:
namein interfaceFileSystem
-
capabilities
public byte capabilities()
Get the capabilities of the file system- Specified by:
capabilitiesin interfaceFileSystem
-
schemes
public java.lang.String[] schemes()
Get the schemes- Specified by:
schemesin interfaceFileSystem
-
exists
public boolean exists(java.lang.String filename)
Does the file exist?- Specified by:
existsin interfaceFileSystem
-
canRead
public boolean canRead(java.lang.String filename)
returns true if filename can be read- Specified by:
canReadin interfaceFileSystem
-
canWrite
public boolean canWrite(java.lang.String filename)
returns true if filename can be written to- Specified by:
canWritein interfaceFileSystem
-
openFileStream
public java.io.InputStream openFileStream(java.lang.String filename) throws java.io.IOExceptionOpens an input file- Specified by:
openFileStreamin interfaceFileSystem- Throws:
java.io.IOException
-
writeFileStream
public java.io.OutputStream writeFileStream(java.lang.String filename) throws java.io.IOExceptionOpens an output file- Specified by:
writeFileStreamin interfaceFileSystem- Throws:
java.io.IOException
-
openFileRandom
public RandomDataInput openFileRandom(java.lang.String filename) throws java.io.IOException
Opens an input random access file- Specified by:
openFileRandomin interfaceFileSystem- Throws:
java.io.IOException
-
writeFileRandom
public RandomDataOutput writeFileRandom(java.lang.String filename) throws java.io.IOException
Opens a writable random access file- Specified by:
writeFileRandomin interfaceFileSystem- Throws:
java.io.IOException
-
delete
public boolean delete(java.lang.String filename)
Delete a file- Specified by:
deletein interfaceFileSystem
-
deleteOnExit
public boolean deleteOnExit(java.lang.String pathname) throws java.io.IOExceptionDelete the file on program exit- Specified by:
deleteOnExitin interfaceFileSystem- Throws:
java.io.IOException
-
mkdir
public boolean mkdir(java.lang.String filename)
Make a directory- Specified by:
mkdirin interfaceFileSystem
-
isDirectory
public boolean isDirectory(java.lang.String path)
Does the path point to a directory- Specified by:
isDirectoryin interfaceFileSystem
-
length
public long length(java.lang.String filename)
What is the length of the file?- Specified by:
lengthin interfaceFileSystem
-
rename
public boolean rename(java.lang.String source, java.lang.String destination) throws java.io.IOExceptionrename a file/dir to another name, on the same file system- Specified by:
renamein interfaceFileSystem- Throws:
java.io.IOException
-
getParent
public java.lang.String getParent(java.lang.String path) throws java.io.IOExceptionwhats the parent path to this path - eg directory containing a file- Specified by:
getParentin interfaceFileSystem- Throws:
java.io.IOException
-
list
public java.lang.String[] list(java.lang.String path) throws java.io.IOExceptionlist contents of a directory etc- Specified by:
listin interfaceFileSystem- Throws:
java.io.IOException
-
-