Package io.cui.tools.io
Class FileSystemLoader
- java.lang.Object
-
- io.cui.tools.io.FileSystemLoader
-
- All Implemented Interfaces:
FileLoader,FileReaderWriter,FileWriter,Serializable
public class FileSystemLoader extends Object implements FileReaderWriter
File-system based variant. Responsible for all nonFileTypePrefix.CLASSPATHfiles.- Author:
- Oliver Wolff
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FileSystemLoader(String pathName)FileSystemLoader(Path path)Variant that uses a path as the constructor argument
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(Object other)static StringcheckPathName(String pathName)Checks and modifies a given pathNamebooleanequals(Object o)StructuredFilenamegetFileName()PathgetPath()URLgetURL()inthashCode()InputStreaminputStream()This method should be within atry-with-resourcesstatement as it is not closed by the implementation.booleanisFilesystemLoader()booleanisReadable()booleanisWritable()OutputStreamoutputStream()Truncate and overwrite an existing file, or create the file if it doesn't initially exist.StringtoString()
-
-
-
Constructor Detail
-
FileSystemLoader
public FileSystemLoader(String pathName)
- Parameters:
pathName- must not be null nor empty, must not start with the prefix "classpath:" but may start with the prefix "file:" and contain at least one character despite the prefix. On all other cases aIllegalArgumentExceptionwill be thrown.
-
FileSystemLoader
public FileSystemLoader(Path path)
Variant that uses a path as the constructor argument- Parameters:
path- must not be null
-
-
Method Detail
-
inputStream
public InputStream inputStream() throws IOException
Description copied from interface:FileLoaderThis method should be within atry-with-resourcesstatement as it is not closed by the implementation.- Specified by:
inputStreamin interfaceFileLoader- Returns:
- an
InputStreamon the corresponding file. It implicitly checksFileLoader.isReadable()before accessing the file and will throw anIllegalStateExceptionin case it is not readable. - Throws:
IOException
-
checkPathName
public static String checkPathName(String pathName)
Checks and modifies a given pathName- Parameters:
pathName- must not be null nor empty, must not start with the prefix "classpath:" but may start with the prefix "file:" and contain at least one character despite the prefix. On all other cases aIllegalArgumentExceptionwill be thrown.- Returns:
- the normalized pathname without prefix
-
isFilesystemLoader
public boolean isFilesystemLoader()
- Specified by:
isFilesystemLoaderin interfaceFileLoader- Returns:
- boolean indicating that the loader loads from the file-system and not from the classpath
-
getURL
public URL getURL()
- Specified by:
getURLin interfaceFileLoader- Returns:
- an
URLon the corresponding file.
-
outputStream
public OutputStream outputStream() throws IOException
Truncate and overwrite an existing file, or create the file if it doesn't initially exist.- Specified by:
outputStreamin interfaceFileWriter- Returns:
- an
OutputStreamon the corresponding file. It implicitly checksFileWriter.isWritable()before accessing the file and will throw anIllegalStateExceptionin case it is not readable. - Throws:
IOException
-
isReadable
public boolean isReadable()
- Specified by:
isReadablein interfaceFileLoader- Returns:
- boolean indicating whether the concrete file exists and is accessible
-
isWritable
public boolean isWritable()
- Specified by:
isWritablein interfaceFileWriter- Returns:
- true if an actual file is writable.
-
getFileName
public StructuredFilename getFileName()
- Specified by:
getFileNamein interfaceFileLoader- Specified by:
getFileNamein interfaceFileWriter- Returns:
- the filename in an appropriate presentation.
-
-