|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.objectledge.filesystem.FileSystem
public class FileSystem
Provides an abstration of files available in the local file system, in the ClassLoader, web application context, or through java.net.URL mechanism.
| Field Summary | |
|---|---|
private int |
bufferSize
The size of the buffer. |
private int |
maxReadSize
Maximum size of a file that is loaded into memory in one chunk by the. |
private String |
protocol
|
private List<FileSystemProvider> |
providers
The providers. |
| Constructor Summary | |
|---|---|
protected |
FileSystem()
Protected no-arg constructor to allow mocking. |
|
FileSystem(FileSystemProvider[] providers,
int bufferSize,
int maxReadSize)
Creates a new instance of the File System. |
| Method Summary | |
|---|---|
static String |
basePath(String path)
Returns the base name of a file. |
boolean |
canRead(String path)
Returns true if the file specified by the abstract
pathname can be read. |
boolean |
canWrite(String path)
Returns true if the file specified by the abstract
pathname can be written. |
boolean |
checkPathChars(String path)
Returns true if the given path contains acceptable characters. |
void |
copyDir(String src,
String dst)
Copies the contents of a directory to another location. |
void |
copyFile(String from,
String to)
Copies a file from one location to another. |
boolean |
createNewFile(String path)
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. |
void |
delete(String path)
Deletes a file or directory. |
void |
deleteRecursive(String path)
Deletes recursive a directory. |
static String |
directoryPath(String path)
Returns hte directory name of a file. |
boolean |
exists(String path)
Returns true if the file specified by the abstract
pathname exists. |
static FileSystem |
getClasspathFileSystem()
Creates a classpath file system. |
InputStream |
getInputStream(String path)
Returns an InputStream for reading the file. |
OutputStream |
getOutputStream(String path)
Returns an OutputStream for writing the file. |
OutputStream |
getOutputStream(String path,
boolean append)
Returns an OutputStream for writing the file, or appending to it. |
String |
getProtocol()
Return the URL protocol name for this FileSystem. |
FileSystemProvider |
getProvider(String name)
Return the provider with the specified name. |
FileSystemProvider[] |
getProviders()
Return the installed providers. |
RandomAccessFile |
getRandomAccess(String path,
String mode)
Returns a RandomAccess interface implementation for accessing the file at
arbitrary positions. |
Reader |
getReader(String path,
String encoding)
Returns a Reader for reading the file. |
URL |
getResource(String path)
Returns an URL poiting to a file. |
static FileSystem |
getStandardFileSystem(String root)
Creates a standard file system. |
Writer |
getWriter(String path,
String encoding)
Returns a Writer for writing the file, or appendig to it. |
Writer |
getWriter(String path,
String encoding,
boolean append)
Returns a Writer for writing the file, or appendig to it. |
boolean |
isDirectory(String path)
Returns true if the abstract pathname points to a
directory. |
boolean |
isFile(String path)
Returns true if the abstract pathname points to an
ordinary file. |
long |
lastModified(String path)
Returns the time of the last modificaion of the specified file. |
long |
length(String path)
Returns the size of the specified file. |
String[] |
list(String path)
Lists the contents of a directory. |
void |
mkdirs(String path)
Creates a directory and all neccessary parent directories. |
static String |
normalizedPath(String path)
Normalizes a pathname. |
byte[] |
read(String path)
Read the contents of a file into a byte array. |
void |
read(String path,
OutputStream out)
Read the contents of a file and write them into an OutputStream. |
String |
read(String path,
String encoding)
Read the contents of a file into a String. |
static String |
relativePath(String path,
String base)
Returns the relative pathname of a file with respect to given base directory. |
void |
rename(String from,
String to)
Atomically renames a file or directory. |
void |
write(String path,
byte[] bytes)
Write contents of a byte array into a file. |
void |
write(String path,
InputStream in)
Write the data read from an InputStream into a file. |
void |
write(String path,
String string,
String encoding)
Write contents of a byte array into a file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private String protocol
private List<FileSystemProvider> providers
private int bufferSize
private int maxReadSize
| Constructor Detail |
|---|
protected FileSystem()
public FileSystem(FileSystemProvider[] providers,
int bufferSize,
int maxReadSize)
providers - the backend implementations of the service.bufferSize - the size of the buffers using for reading/writing files.maxReadSize - maximum size of file that is loaded into memory as a single chunk.| Method Detail |
|---|
public String getProtocol()
public FileSystemProvider[] getProviders()
The provider objects are returned in the same order in which they are accessed.
public FileSystemProvider getProvider(String name)
throws IllegalArgumentException
name - the name of the provider
IllegalArgumentException - if the requested provider is not installed.
public URL getResource(String path)
throws MalformedURLException
path - the abstract pathname
null if the file is not found.
MalformedURLException - if the pathname is not valid.public InputStream getInputStream(String path)
path - the abstract pathname.
null if the file is not found.
public Reader getReader(String path,
String encoding)
throws UnsupportedEncodingException
path - the abstract pathname.encoding - character encoding to use.
null if the file is not found.
UnsupportedEncodingException - if the requested encoding is not supported.
public OutputStream getOutputStream(String path,
boolean append)
path - the abstract pathname.append - false to truncate the file,
true to append.
null if the operation is not
supported, or the file could not be opened for writing.public OutputStream getOutputStream(String path)
path - the abstract pathname.
null if the operation is not
supported, or the file could not be opened for writing.
public Writer getWriter(String path,
String encoding,
boolean append)
throws UnsupportedEncodingException
path - the abstract pathname.encoding - the character encoding to use.append - false to truncate the file,
true to append.
null if the operation is not
supported, or the file could not be opened for writing.
UnsupportedEncodingException - if the requested encoding is not supported.
public Writer getWriter(String path,
String encoding)
throws UnsupportedEncodingException
path - the abstract pathname.encoding - the character encoding to use.
null if the operation is not
supported, or the file could not be opened for writing.
UnsupportedEncodingException - if the requested encoding is not supported.
public RandomAccessFile getRandomAccess(String path,
String mode)
RandomAccess interface implementation for accessing the file at
arbitrary positions.
path - the abstract pathname.mode - the string which defines the opening mode for this random access file,
the form of this string is equal to the mode parameter in
java.io.RandomAccessFile constructor.
null
if the operation is not supported.public boolean exists(String path)
true if the file specified by the abstract
pathname exists.
path - the abstract pathname
true if the file specified by the abstract
pathname exists.public boolean isFile(String path)
true if the abstract pathname points to an
ordinary file.
path - the abstract pathname
true if the file specified by the abstract
pathname exists.public boolean isDirectory(String path)
true if the abstract pathname points to a
directory.
path - the abstract pathname
true if the file specified by the abstract
pathname exists.public boolean canRead(String path)
true if the file specified by the abstract
pathname can be read.
path - the abstract pathname
true if the file specified by the abstract
pathname can be read.public boolean canWrite(String path)
true if the file specified by the abstract
pathname can be written.
path - the abstract pathname
true if the file specified by the abstract
pathname can be written.public long lastModified(String path)
The time of the modification is returned as the number of milliseconds sice the epoch (Jan 1 1970), or -1L if the feature is not supported.
path - the abstract pathname.
public long length(String path)
If the operation is not supported -1L is returned.
path - an abstract pathname.
public String[] list(String path)
throws IOException
path - the directory to list.
IOException - if the pathname does not point to a directory.
public boolean createNewFile(String path)
throws IOException,
UnsupportedCharactersInFilePathException
The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.
path - the pathname of the file to create.
true if the named file does not exist and was
successfully created; false if the named file
already exists.
UnsupportedCharactersInFilePathException - if the given path contains
characters incompatible with underlying filesystem.
IOException - if the operation fails.
public void mkdirs(String path)
throws IOException,
UnsupportedCharactersInFilePathException
path - the directory name.
UnsupportedCharactersInFilePathException - if the given path contains
characters incompatible with underlying filesystem.
IOException - if the operation fails.
public void delete(String path)
throws IOException
A directory must be empty at the time it is deleted.
path - the path of the file or directory
IOException - if the operation fails.
public void deleteRecursive(String path)
throws IOException
path - the path of the directory.
IOException - if the operation fails.
public void rename(String from,
String to)
throws IOException,
UnsupportedCharactersInFilePathException
from - source path.to - destination path.
UnsupportedCharactersInFilePathException - if the given destination path contains
characters incompatible with underlying filesystem.
IOException - if the operation fails.
public void copyFile(String from,
String to)
throws IOException,
UnsupportedCharactersInFilePathException
from - the source path.to - the destination path.
UnsupportedCharactersInFilePathException - if the given destination path contains
characters incompatible with underlying filesystem.
IOException - if the operation fails.
public void copyDir(String src,
String dst)
throws IOException,
UnsupportedCharactersInFilePathException
src - source directory.dst - destination directory.
UnsupportedCharactersInFilePathException - if the given destination path contains
characters incompatible with underlying filesystem.
IOException - if the operation fails.
public void read(String path,
OutputStream out)
throws IOException
path - the pathname of the file.out - the stream to write file contents to.
IOException - if the operation fails.
public byte[] read(String path)
throws IOException
path - the pathnamame of the file.
IOException - if the operation fails.
public String read(String path,
String encoding)
throws IOException
path - the pathnamame of the file.encoding - the character encoding to use for decoding bytes into
Unicode characters.
IOException - if the file cannot be read, or the specified encoding
is not supported
public void write(String path,
InputStream in)
throws IOException
path - the pathname of the filein - the steram to read data from.
IOException - if the opreation fails.
public void write(String path,
byte[] bytes)
throws IOException
path - the pathname of the file.bytes - the bytes to be written
IOException - if the operation fails.
public void write(String path,
String string,
String encoding)
throws IOException
path - the pathname of the file.string - the String to be writtenencoding - the character encoding to use for encoding Unicode
characters into bytes.
IOException - if the file cannot be written to, or the specified encoding is not
supported.
public static String normalizedPath(String path)
throws IllegalArgumentException
This method removes redundant / characters, removes . and .. path elements, taking care that the paths dont reach outside filesystem root, removes trailing / from directories and adding leading / as neccessary.
path - the path.
IllegalArgumentException - if the path reaches outside the filesystem root.public static String basePath(String path)
This method returns the contents of the pathname after the last '/' character.
path - the pathname of the file.
public static String directoryPath(String path)
This method returns the normalized path before the last '/' character in the path.
path - the pathname of the file.
public static String relativePath(String path,
String base)
throws IllegalArgumentException
path - the pathname of a file.base - the base pathname.
IllegalArgumentException - if the file is contained
outside of base.public boolean checkPathChars(String path)
true if the given path contains acceptable characters.
path - the path
true if the given path contains acceptable characters.public static FileSystem getStandardFileSystem(String root)
The file system is composed of a local file system, with the specified root, augmented with a classpath file system.
root - the local filesystem root.
public static FileSystem getClasspathFileSystem()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||