Package com.helger.commons.io.relative
Interface IFileRelativeIO
-
- All Superinterfaces:
IPathRelativeIO
- All Known Implementing Classes:
FileRelativeIO
public interface IFileRelativeIO extends IPathRelativeIO
An extendedIPathRelativeIOversion that uses files as the basis.- Since:
- 7.1.1
- Author:
- Philip Helger
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ESuccessappendFile(String sRelativePath, byte[] aBytes)Helper function for saving a file with correct error handling.default ESuccessappendFile(String sRelativePath, String sContent, Charset aCharset)Helper function for saving a file with correct error handling.default FileIOErrorcreateDirectory(String sRelativePath, boolean bRecursive)Create the appropriate directory if it is not existingdefault FileIOErrordeleteDirectory(String sRelativePath, boolean bDeleteRecursively)default FileIOErrordeleteDirectoryIfExisting(String sRelativePath, boolean bDeleteRecursively)default FileIOErrordeleteFile(String sRelativePath)default FileIOErrordeleteFileIfExisting(String sRelativePath)default booleanexistsDir(String sRelativePath)Check if a directory relative to the base path existsdefault booleanexistsFile(String sRelativePath)Check if a file relative to the base path existsdefault StringgetBasePath()FilegetBasePathFile()default FilegetFile(String sRelativePath)Get aFilerelative to the base path.default OutputStreamgetOutputStream(String sRelativePath)Get theOutputStreamrelative to the base path.default OutputStreamgetOutputStream(String sRelativePath, EAppend eAppend)Get theOutputStreamrelative to the base pathdefault StringgetRelativeFilename(File aAbsoluteFile)Get the relative file name for the passed absolute file.default FileSystemResourcegetResource(String sRelativePath)Get the file system resource relative to the base pathdefault WritergetWriter(String sRelativePath, Charset aCharset)Get theWriterrelative to the base path.default WritergetWriter(String sRelativePath, Charset aCharset, EAppend eAppend)Get theWriterrelative to the base path.default FileIOErrorrenameDir(String sOldDirName, String sNewDirName)default FileIOErrorrenameFile(String sOldFilename, String sNewFilename)default ESuccesssaveFile(String sRelativePath, byte[] aBytes)Helper function for saving a file with correct error handling.default ESuccesssaveFile(String sRelativePath, String sContent, Charset aCharset)Helper function for saving a file with correct error handling.default ESuccesswriteFile(String sRelativePath, EAppend eAppend, byte[] aBytes)Helper function for saving a file with correct error handling.-
Methods inherited from interface com.helger.commons.io.relative.IPathRelativeIO
getInputStream, getReader
-
-
-
-
Method Detail
-
getBasePath
@Nonnull @Nonempty default String getBasePath()
- Specified by:
getBasePathin interfaceIPathRelativeIO- Returns:
- The absolute base path that is used. Neither
nullnor empty.
-
getFile
@Nonnull default File getFile(@Nonnull String sRelativePath)
Get aFilerelative to the base path.- Parameters:
sRelativePath- the relative path- Returns:
- The "absolute"
Fileand nevernull. - See Also:
getBasePathFile()
-
getResource
@Nonnull default FileSystemResource getResource(@Nonnull String sRelativePath)
Get the file system resource relative to the base path- Specified by:
getResourcein interfaceIPathRelativeIO- Parameters:
sRelativePath- the relative path- Returns:
- The "absolute"
FileSystemResourceand nevernull. - See Also:
getBasePathFile()
-
getRelativeFilename
@Nullable default String getRelativeFilename(@Nonnull File aAbsoluteFile)
Get the relative file name for the passed absolute file.- Parameters:
aAbsoluteFile- The non-nullabsolute file to make relative.- Returns:
nullif the passed file is not a child of this base directory.
-
existsFile
default boolean existsFile(@Nonnull String sRelativePath)
Check if a file relative to the base path exists- Parameters:
sRelativePath- the relative path- Returns:
trueif theFileis a file and exists,falseotherwise.- See Also:
getBasePathFile()
-
existsDir
default boolean existsDir(@Nonnull String sRelativePath)
Check if a directory relative to the base path exists- Parameters:
sRelativePath- the relative path- Returns:
trueif theFileis a directory and exists,falseotherwise.- See Also:
getBasePathFile()
-
getOutputStream
@Nullable default OutputStream getOutputStream(@Nonnull String sRelativePath)
Get theOutputStreamrelative to the base path. An eventually existing file is truncated.- Parameters:
sRelativePath- the relative path- Returns:
nullif the path is not writable- See Also:
getBasePathFile()
-
getOutputStream
@Nullable default OutputStream getOutputStream(@Nonnull String sRelativePath, @Nonnull EAppend eAppend)
Get theOutputStreamrelative to the base path- Parameters:
sRelativePath- the relative patheAppend- Append or truncate mode. May not benull.- Returns:
nullif the path is not writable- See Also:
getBasePathFile()
-
getWriter
@Nullable default Writer getWriter(@Nonnull String sRelativePath, @Nonnull Charset aCharset)
Get theWriterrelative to the base path. An eventually existing file is truncated.- Parameters:
sRelativePath- the relative pathaCharset- The charset to use. May not benull.- Returns:
nullif the path is not writable- See Also:
getBasePathFile()
-
getWriter
@Nullable default Writer getWriter(@Nonnull String sRelativePath, @Nonnull Charset aCharset, @Nonnull EAppend eAppend)
Get theWriterrelative to the base path.- Parameters:
sRelativePath- the relative pathaCharset- The charset to use. May not benull.eAppend- Append or truncate mode. May not benull.- Returns:
nullif the path is not writable- See Also:
getBasePathFile()
-
createDirectory
@Nonnull default FileIOError createDirectory(@Nonnull String sRelativePath, boolean bRecursive)
Create the appropriate directory if it is not existing- Parameters:
sRelativePath- the relative pathbRecursive- iftrueall missing parent directories will be created- Returns:
- Success indicator. Never
null. - See Also:
getBasePathFile()
-
deleteDirectory
@Nonnull default FileIOError deleteDirectory(@Nonnull String sRelativePath, boolean bDeleteRecursively)
-
deleteDirectoryIfExisting
@Nonnull default FileIOError deleteDirectoryIfExisting(@Nonnull String sRelativePath, boolean bDeleteRecursively)
-
deleteFile
@Nonnull default FileIOError deleteFile(@Nonnull String sRelativePath)
-
deleteFileIfExisting
@Nonnull default FileIOError deleteFileIfExisting(@Nonnull String sRelativePath)
-
renameDir
@Nonnull default FileIOError renameDir(@Nonnull String sOldDirName, @Nonnull String sNewDirName)
-
renameFile
@Nonnull default FileIOError renameFile(@Nonnull String sOldFilename, @Nonnull String sNewFilename)
-
writeFile
@Nonnull default ESuccess writeFile(@Nonnull String sRelativePath, @Nonnull EAppend eAppend, @Nonnull byte[] aBytes)
Helper function for saving a file with correct error handling.- Parameters:
sRelativePath- name of the file. May not benull.eAppend- Appending mode. May not benull.aBytes- the bytes to be written. May not benull.- Returns:
ESuccess
-
saveFile
@Nonnull default ESuccess saveFile(@Nonnull String sRelativePath, @Nonnull String sContent, @Nonnull Charset aCharset)
Helper function for saving a file with correct error handling.- Parameters:
sRelativePath- name of the file. May not benull.sContent- the content to save. May not benull.aCharset- The character set to use. May not benull.- Returns:
ESuccess
-
saveFile
@Nonnull default ESuccess saveFile(@Nonnull String sRelativePath, byte[] aBytes)
Helper function for saving a file with correct error handling.- Parameters:
sRelativePath- name of the file. May not benull.aBytes- the bytes to be written. May not benull.- Returns:
ESuccess
-
appendFile
@Nonnull default ESuccess appendFile(@Nonnull String sRelativePath, @Nonnull String sContent, @Nonnull Charset aCharset)
Helper function for saving a file with correct error handling.- Parameters:
sRelativePath- name of the file. May not benull.sContent- the content to save. May not benull.aCharset- The character set to use. May not benull.- Returns:
ESuccess
-
-