Package com.helger.io.resource
Class FileSystemResource
java.lang.Object
com.helger.io.resource.FileSystemResource
- All Implemented Interfaces:
com.helger.base.io.iface.IHasInputStream,com.helger.base.io.iface.IHasInputStreamAndReader,com.helger.base.io.iface.IHasOutputStream,com.helger.base.io.iface.IHasOutputStreamAndWriter,IReadableResource,IReadWriteResource,IResourceBase,IWritableResource
Implementation of the
IReadableResource and
IWritableResource interfaces for file
system objects.- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionFileSystemResource(@NonNull File aFile) Create a new file system resource from aFile.FileSystemResource(@NonNull File aParentFile, String sChildPath) Create a new file system resource from a parent file and a child path.FileSystemResource(@NonNull String sFilename) Create a new file system resource from a filename.FileSystemResource(@NonNull String sParentPath, @NonNull String sChildPath) Create a new file system resource from a parent path and a child path.FileSystemResource(@NonNull URI aURI) Create a new file system resource from a URI.FileSystemResource(@NonNull Path aPath) Create a new file system resource from aPath. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests whether the application can execute the file denoted by this abstract pathname.booleancanRead()Tests whether the application can read the file denoted by this abstract pathname.booleancanWrite()Tests whether the application can modify the file denoted by this abstract pathname.booleanbooleanexists()Check if the underlying file exists.@NonNull FileGet this resource as aFile.@Nullable URLgetAsURL()Get this resource as aURL.@Nullable FileInputStreamGet an input stream for reading from this resource.@Nullable FileOutputStreamgetOutputStream(@NonNull com.helger.base.io.EAppend eAppend) Get an output stream for writing to this resource.@NonNull StringgetPath()Get the absolute path of this file system resource.@NonNull FileSystemResourcegetReadableCloneForPath(@NonNull String sPath) Create a newFileSystemResourcefor a different path.@Nullable Reader@NonNull StringGet the unique resource ID of this file system resource.@NonNull FileSystemResourcegetWritableCloneForPath(@NonNull String sPath) Create a new writableFileSystemResourcefor a different path.@Nullable WriterinthashCode()final booleanCheck if this resource can be read multiple times.final booleanCheck if this resource can be written multiple times.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.io.iface.IHasInputStream
getBufferedInputStream, withBufferedInputStreamDo, withInputStreamDoMethods inherited from interface com.helger.base.io.iface.IHasInputStreamAndReader
getBufferedReaderMethods inherited from interface com.helger.base.io.iface.IHasOutputStream
getBufferedOutputStreamMethods inherited from interface com.helger.base.io.iface.IHasOutputStreamAndWriter
getBufferedWriter
-
Constructor Details
-
FileSystemResource
Create a new file system resource from a URI.- Parameters:
aURI- The URI to create the resource from. May not benull.
-
FileSystemResource
Create a new file system resource from a parent path and a child path.- Parameters:
sParentPath- The parent path. May not benull.sChildPath- The child path. May not benull.
-
FileSystemResource
Create a new file system resource from a filename.- Parameters:
sFilename- The filename of the resource. May not benull.
-
FileSystemResource
Create a new file system resource from a parent file and a child path.- Parameters:
aParentFile- The parent file. May not benull.sChildPath- The child path.
-
FileSystemResource
Create a new file system resource from aFile. The file path is made absolute and cleaned.- Parameters:
aFile- The file to use. May not benull.
-
FileSystemResource
Create a new file system resource from aPath.- Parameters:
aPath- The path to use. May not benull.
-
-
Method Details
-
getResourceID
Get the unique resource ID of this file system resource.- Specified by:
getResourceIDin interfaceIResourceBase- Returns:
- The absolute path of the file. Never
null.
-
getPath
Get the absolute path of this file system resource.- Specified by:
getPathin interfaceIResourceBase- Returns:
- The absolute path. Never
null.
-
getInputStream
Get an input stream for reading from this resource.- Specified by:
getInputStreamin interfacecom.helger.base.io.iface.IHasInputStream- Returns:
nullif the file does not exist or cannot be opened.
-
getReader
- Specified by:
getReaderin interfacecom.helger.base.io.iface.IHasInputStreamAndReader
-
isReadMultiple
public final boolean isReadMultiple()Check if this resource can be read multiple times. File system resources always returntrue.- Specified by:
isReadMultiplein interfacecom.helger.base.io.iface.IHasInputStream- Returns:
- Always
true.
-
getOutputStream
Get an output stream for writing to this resource.- Specified by:
getOutputStreamin interfacecom.helger.base.io.iface.IHasOutputStream- Parameters:
eAppend- Appending mode. May not benull.- Returns:
nullif the file could not be opened.
-
getWriter
public @Nullable Writer getWriter(@NonNull Charset aCharset, @NonNull com.helger.base.io.EAppend eAppend) - Specified by:
getWriterin interfacecom.helger.base.io.iface.IHasOutputStreamAndWriter
-
isWriteMultiple
public final boolean isWriteMultiple()Check if this resource can be written multiple times. File system resources always returntrue.- Specified by:
isWriteMultiplein interfacecom.helger.base.io.iface.IHasOutputStream- Returns:
- Always
true.
-
exists
public boolean exists()Check if the underlying file exists.- Specified by:
existsin interfaceIResourceBase- Returns:
trueif the file exists,falseotherwise.
-
getAsURL
Get this resource as aURL.- Specified by:
getAsURLin interfaceIResourceBase- Returns:
nullif the conversion to URL failed.
-
getAsFile
Get this resource as aFile.- Specified by:
getAsFilein interfaceIResourceBase- Returns:
- The underlying file. Never
null.
-
getReadableCloneForPath
Create a newFileSystemResourcefor a different path.- Specified by:
getReadableCloneForPathin interfaceIReadableResource- Parameters:
sPath- The new path to use. May not benull.- Returns:
- A new
FileSystemResourceinstance. Nevernull.
-
getWritableCloneForPath
Create a new writableFileSystemResourcefor a different path.- Specified by:
getWritableCloneForPathin interfaceIWritableResource- Parameters:
sPath- The new path to use. May not benull.- Returns:
- A new
FileSystemResourceinstance. Nevernull.
-
canRead
public boolean canRead()Tests whether the application can read the file denoted by this abstract pathname.- Returns:
trueif and only if the file specified by this abstract pathname exists and can be read by the application;falseotherwise
-
canWrite
public boolean canWrite()Tests whether the application can modify the file denoted by this abstract pathname.- Returns:
trueif and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file;falseotherwise.
-
canExecute
public boolean canExecute()Tests whether the application can execute the file denoted by this abstract pathname.- Returns:
trueif and only if the abstract pathname exists and the application is allowed to execute the file
-
equals
-
hashCode
public int hashCode() -
toString
-