Package com.helger.commons.io.resource
Class FileSystemResource
- java.lang.Object
-
- com.helger.commons.io.resource.FileSystemResource
-
- All Implemented Interfaces:
IHasInputStream,IHasInputStreamAndReader,IHasOutputStream,IHasOutputStreamAndWriter,IReadableResource,IReadWriteResource,IResourceBase,IWritableResource
@NotThreadSafe public class FileSystemResource extends Object implements IReadWriteResource
Implementation of theIReadableResourceandIWritableResourceinterfaces for file system objects.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description FileSystemResource(File aFile)FileSystemResource(File aParentFile, String sChildPath)FileSystemResource(String sFilename)FileSystemResource(String sParentPath, String sChildPath)FileSystemResource(URI aURI)FileSystemResource(Path aPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanExecute()Tests 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.booleanequals(Object o)booleanexists()FilegetAsFile()URLgetAsURL()FileInputStreamgetInputStream()Get the input stream to read from the object.FileOutputStreamgetOutputStream(EAppend eAppend)Get the output stream to read from the object.StringgetPath()FileSystemResourcegetReadableCloneForPath(String sPath)Get a new resource of the same implementation type as this object but for a different path.ReadergetReader(Charset aCharset)Get aReaderbased on this input stream provider using the given charset.StringgetResourceID()FileSystemResourcegetWritableCloneForPath(String sPath)Get a new resource of the same implementation type as this object but for a different path.WritergetWriter(Charset aCharset, EAppend eAppend)Get aWriterbased on this output stream provider using the given charset.inthashCode()booleanisReadMultiple()Check if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.booleanisWriteMultiple()Check if theOutputStreamfromIHasOutputStream.getOutputStream(EAppend)orIHasOutputStream.getBufferedOutputStream(EAppend)can be acquired more than once or not.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream
-
Methods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader
-
Methods inherited from interface com.helger.commons.io.IHasOutputStream
getBufferedOutputStream
-
Methods inherited from interface com.helger.commons.io.IHasOutputStreamAndWriter
getBufferedWriter
-
-
-
-
Method Detail
-
getResourceID
@Nonnull public String getResourceID()
- Specified by:
getResourceIDin interfaceIResourceBase- Returns:
- A non-
nullresource ID used e.g. for system IDs in XML resolving.
-
getPath
@Nonnull public String getPath()
- Specified by:
getPathin interfaceIResourceBase- Returns:
- The requested path. Never
null
-
getInputStream
@Nullable public FileInputStream getInputStream()
Description copied from interface:IHasInputStreamGet the input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created.- Specified by:
getInputStreamin interfaceIHasInputStream- Returns:
nullif resolving failed.
-
getReader
@Nullable public Reader getReader(@Nonnull Charset aCharset)
Description copied from interface:IHasInputStreamAndReaderGet aReaderbased on this input stream provider using the given charset.- Specified by:
getReaderin interfaceIHasInputStreamAndReader- Parameters:
aCharset- The charset to use. May not benull.- Returns:
nullif no input stream could be retrieved.
-
isReadMultiple
public final boolean isReadMultiple()
Description copied from interface:IHasInputStreamCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.- Specified by:
isReadMultiplein interfaceIHasInputStream- Returns:
trueif the input stream can be acquired more than once,falseif not.
-
getOutputStream
@Nullable public FileOutputStream getOutputStream(@Nonnull EAppend eAppend)
Description copied from interface:IHasOutputStreamGet the output stream to read from the object. Each time this method is call, a newOutputStreamneeds to be created!- Specified by:
getOutputStreamin interfaceIHasOutputStream- Parameters:
eAppend- appending mode. May not benull.- Returns:
nullif resolving failed.
-
getWriter
@Nullable public Writer getWriter(@Nonnull Charset aCharset, @Nonnull EAppend eAppend)
Description copied from interface:IHasOutputStreamAndWriterGet aWriterbased on this output stream provider using the given charset.- Specified by:
getWriterin interfaceIHasOutputStreamAndWriter- Parameters:
aCharset- The charset to use. May not benull.eAppend- Appending mode. May not benull.- Returns:
nullif no output stream could be retrieved.
-
isWriteMultiple
public final boolean isWriteMultiple()
Description copied from interface:IHasOutputStreamCheck if theOutputStreamfromIHasOutputStream.getOutputStream(EAppend)orIHasOutputStream.getBufferedOutputStream(EAppend)can be acquired more than once or not.- Specified by:
isWriteMultiplein interfaceIHasOutputStream- Returns:
trueif the output stream can be acquired more than once,falseif not.
-
exists
public boolean exists()
- Specified by:
existsin interfaceIResourceBase- Returns:
trueif the resource exists,falseotherwise.
-
getAsURL
@Nullable public URL getAsURL()
- Specified by:
getAsURLin interfaceIResourceBase- Returns:
- the URL representation of this resource. May be
nullif this resource cannot be represented as an URL.
-
getAsFile
@Nonnull public File getAsFile()
- Specified by:
getAsFilein interfaceIResourceBase- Returns:
- the File representation of this resource. May be
nullif this resource cannot be represented as a file.
-
getReadableCloneForPath
@Nonnull public FileSystemResource getReadableCloneForPath(@Nonnull String sPath)
Description copied from interface:IReadableResourceGet a new resource of the same implementation type as this object but for a different path.- Specified by:
getReadableCloneForPathin interfaceIReadableResource- Parameters:
sPath- The new path to use. May not benull.- Returns:
- The resource of the same implementation but a different path. May
not be
null.
-
getWritableCloneForPath
@Nonnull public FileSystemResource getWritableCloneForPath(@Nonnull String sPath)
Description copied from interface:IWritableResourceGet a new resource of the same implementation type as this object but for a different path.- Specified by:
getWritableCloneForPathin interfaceIWritableResource- Parameters:
sPath- The new path to use. May not benull.- Returns:
- The resource of the same implementation but a different path. May
not be
null.
-
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
-
-