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 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
Constructors Constructor Description LocalFileSystem()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRead(java.lang.String filename)
returns true if filename can be readboolean
canWrite(java.lang.String filename)
returns true if filename can be written tobyte
capabilities()
Get the capabilities of the file systemboolean
delete(java.lang.String filename)
Delete a fileboolean
deleteOnExit(java.lang.String pathname)
Delete the file on program exitboolean
exists(java.lang.String filename)
Does the file exist?java.lang.String
getParent(java.lang.String path)
whats the parent path to this path - eg directory containing a fileboolean
isDirectory(java.lang.String path)
Does the path point to a directorylong
length(java.lang.String filename)
What is the length of the file?java.lang.String[]
list(java.lang.String path)
list contents of a directory etcboolean
mkdir(java.lang.String filename)
Make a directoryjava.lang.String
name()
Get the name of the file systemprotected java.lang.String
normalise(java.lang.String filename)
RandomDataInput
openFileRandom(java.lang.String filename)
Opens an input random access filejava.io.InputStream
openFileStream(java.lang.String filename)
Opens an input fileboolean
rename(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 schemesRandomDataOutput
writeFileRandom(java.lang.String filename)
Opens a writable random access filejava.io.OutputStream
writeFileStream(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:
name
in interfaceFileSystem
-
capabilities
public byte capabilities()
Get the capabilities of the file system- Specified by:
capabilities
in interfaceFileSystem
-
schemes
public java.lang.String[] schemes()
Get the schemes- Specified by:
schemes
in interfaceFileSystem
-
exists
public boolean exists(java.lang.String filename)
Does the file exist?- Specified by:
exists
in interfaceFileSystem
-
canRead
public boolean canRead(java.lang.String filename)
returns true if filename can be read- Specified by:
canRead
in interfaceFileSystem
-
canWrite
public boolean canWrite(java.lang.String filename)
returns true if filename can be written to- Specified by:
canWrite
in interfaceFileSystem
-
openFileStream
public java.io.InputStream openFileStream(java.lang.String filename) throws java.io.IOException
Opens an input file- Specified by:
openFileStream
in interfaceFileSystem
- Throws:
java.io.IOException
-
writeFileStream
public java.io.OutputStream writeFileStream(java.lang.String filename) throws java.io.IOException
Opens an output file- Specified by:
writeFileStream
in 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:
openFileRandom
in 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:
writeFileRandom
in interfaceFileSystem
- Throws:
java.io.IOException
-
delete
public boolean delete(java.lang.String filename)
Delete a file- Specified by:
delete
in interfaceFileSystem
-
deleteOnExit
public boolean deleteOnExit(java.lang.String pathname) throws java.io.IOException
Delete the file on program exit- Specified by:
deleteOnExit
in interfaceFileSystem
- Throws:
java.io.IOException
-
mkdir
public boolean mkdir(java.lang.String filename)
Make a directory- Specified by:
mkdir
in interfaceFileSystem
-
isDirectory
public boolean isDirectory(java.lang.String path)
Does the path point to a directory- Specified by:
isDirectory
in interfaceFileSystem
-
length
public long length(java.lang.String filename)
What is the length of the file?- Specified by:
length
in interfaceFileSystem
-
rename
public boolean rename(java.lang.String source, java.lang.String destination) throws java.io.IOException
rename a file/dir to another name, on the same file system- Specified by:
rename
in interfaceFileSystem
- Throws:
java.io.IOException
-
getParent
public java.lang.String getParent(java.lang.String path) throws java.io.IOException
whats the parent path to this path - eg directory containing a file- Specified by:
getParent
in interfaceFileSystem
- Throws:
java.io.IOException
-
list
public java.lang.String[] list(java.lang.String path) throws java.io.IOException
list contents of a directory etc- Specified by:
list
in interfaceFileSystem
- Throws:
java.io.IOException
-
-