Interface IFileRelativeIO

All Superinterfaces:
IPathRelativeIO
All Known Implementing Classes:
FileRelativeIO

public interface IFileRelativeIO extends IPathRelativeIO
An extended IPathRelativeIO version that uses files as the basis.
Since:
7.1.1
Author:
Philip Helger
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NonNull com.helger.base.state.ESuccess
    appendFile(@NonNull String sRelativePath, byte @NonNull [] aBytes)
    Helper function for saving a file with correct error handling.
    default @NonNull com.helger.base.state.ESuccess
    appendFile(@NonNull String sRelativePath, @NonNull String sContent, @NonNull Charset aCharset)
    Helper function for saving a file with correct error handling.
    default @NonNull FileIOError
    createDirectory(@NonNull String sRelativePath, boolean bRecursive)
    Create the appropriate directory if it is not existing
    default @NonNull FileIOError
    deleteDirectory(@NonNull String sRelativePath, boolean bDeleteRecursively)
    Delete a directory relative to the base path.
    default @NonNull FileIOError
    deleteDirectoryIfExisting(@NonNull String sRelativePath, boolean bDeleteRecursively)
    Delete a directory relative to the base path if it exists.
    default @NonNull FileIOError
    deleteFile(@NonNull String sRelativePath)
    Delete a file relative to the base path.
    default @NonNull FileIOError
    deleteFileIfExisting(@NonNull String sRelativePath)
    Delete a file relative to the base path if it exists.
    default boolean
    existsDir(@NonNull String sRelativePath)
    Check if a directory relative to the base path exists
    default boolean
    existsFile(@NonNull String sRelativePath)
    Check if a file relative to the base path exists
    default @NonNull @Nonempty String
     
    @NonNull File
     
    default @NonNull File
    getFile(@NonNull String sRelativePath)
    Get a File relative to the base path.
    default @Nullable OutputStream
    getOutputStream(@NonNull String sRelativePath)
    Get the OutputStream relative to the base path.
    default @Nullable OutputStream
    getOutputStream(@NonNull String sRelativePath, @NonNull com.helger.base.io.EAppend eAppend)
    Get the OutputStream relative to the base path
    default @Nullable String
    getRelativeFilename(@NonNull File aAbsoluteFile)
    Get the relative file name for the passed absolute file.
    default @NonNull FileSystemResource
    getResource(@NonNull String sRelativePath)
    Get the file system resource relative to the base path
    default @Nullable Writer
    getWriter(@NonNull String sRelativePath, @NonNull Charset aCharset)
    Get the Writer relative to the base path.
    default @Nullable Writer
    getWriter(@NonNull String sRelativePath, @NonNull Charset aCharset, @NonNull com.helger.base.io.EAppend eAppend)
    Get the Writer relative to the base path.
    default @NonNull FileIOError
    renameDir(@NonNull String sOldDirName, @NonNull String sNewDirName)
    Rename a directory relative to the base path.
    default @NonNull FileIOError
    renameFile(@NonNull String sOldFilename, @NonNull String sNewFilename)
    Rename a file relative to the base path.
    default @NonNull com.helger.base.state.ESuccess
    saveFile(@NonNull String sRelativePath, byte[] aBytes)
    Helper function for saving a file with correct error handling.
    default @NonNull com.helger.base.state.ESuccess
    saveFile(@NonNull String sRelativePath, @NonNull String sContent, @NonNull Charset aCharset)
    Helper function for saving a file with correct error handling.
    default @NonNull com.helger.base.state.ESuccess
    writeFile(@NonNull String sRelativePath, @NonNull com.helger.base.io.EAppend eAppend, byte @NonNull [] aBytes)
    Helper function for saving a file with correct error handling.

    Methods inherited from interface com.helger.io.relative.IPathRelativeIO

    getInputStream, getReader
  • Method Details

    • getBasePathFile

      @NonNull File getBasePathFile()
      Returns:
      The base path. Never null.
    • getBasePath

      @Nonempty default @NonNull @Nonempty String getBasePath()
      Specified by:
      getBasePath in interface IPathRelativeIO
      Returns:
      The absolute base path that is used. Neither null nor empty.
    • getFile

      default @NonNull File getFile(@NonNull String sRelativePath)
      Get a File relative to the base path.
      Parameters:
      sRelativePath - the relative path
      Returns:
      The "absolute" File and never null.
      See Also:
    • getResource

      default @NonNull FileSystemResource getResource(@NonNull String sRelativePath)
      Get the file system resource relative to the base path
      Specified by:
      getResource in interface IPathRelativeIO
      Parameters:
      sRelativePath - the relative path
      Returns:
      The "absolute" FileSystemResource and never null.
      See Also:
    • getRelativeFilename

      default @Nullable String getRelativeFilename(@NonNull File aAbsoluteFile)
      Get the relative file name for the passed absolute file.
      Parameters:
      aAbsoluteFile - The non-null absolute file to make relative.
      Returns:
      null if 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:
      true if the File is a file and exists, false otherwise.
      See Also:
    • existsDir

      default boolean existsDir(@NonNull String sRelativePath)
      Check if a directory relative to the base path exists
      Parameters:
      sRelativePath - the relative path
      Returns:
      true if the File is a directory and exists, false otherwise.
      See Also:
    • getOutputStream

      default @Nullable OutputStream getOutputStream(@NonNull String sRelativePath)
      Get the OutputStream relative to the base path. An eventually existing file is truncated.
      Parameters:
      sRelativePath - the relative path
      Returns:
      null if the path is not writable
      See Also:
    • getOutputStream

      default @Nullable OutputStream getOutputStream(@NonNull String sRelativePath, @NonNull com.helger.base.io.EAppend eAppend)
      Get the OutputStream relative to the base path
      Parameters:
      sRelativePath - the relative path
      eAppend - Append or truncate mode. May not be null.
      Returns:
      null if the path is not writable
      See Also:
    • getWriter

      default @Nullable Writer getWriter(@NonNull String sRelativePath, @NonNull Charset aCharset)
      Get the Writer relative to the base path. An eventually existing file is truncated.
      Parameters:
      sRelativePath - the relative path
      aCharset - The charset to use. May not be null.
      Returns:
      null if the path is not writable
      See Also:
    • getWriter

      default @Nullable Writer getWriter(@NonNull String sRelativePath, @NonNull Charset aCharset, @NonNull com.helger.base.io.EAppend eAppend)
      Get the Writer relative to the base path.
      Parameters:
      sRelativePath - the relative path
      aCharset - The charset to use. May not be null.
      eAppend - Append or truncate mode. May not be null.
      Returns:
      null if the path is not writable
      See Also:
    • createDirectory

      default @NonNull FileIOError createDirectory(@NonNull String sRelativePath, boolean bRecursive)
      Create the appropriate directory if it is not existing
      Parameters:
      sRelativePath - the relative path
      bRecursive - if true all missing parent directories will be created
      Returns:
      Success indicator. Never null.
      See Also:
    • deleteDirectory

      default @NonNull FileIOError deleteDirectory(@NonNull String sRelativePath, boolean bDeleteRecursively)
      Delete a directory relative to the base path.
      Parameters:
      sRelativePath - The relative path of the directory. May not be null.
      bDeleteRecursively - true to delete recursively, false to delete only if empty.
      Returns:
      The operation result. Never null.
      See Also:
    • deleteDirectoryIfExisting

      default @NonNull FileIOError deleteDirectoryIfExisting(@NonNull String sRelativePath, boolean bDeleteRecursively)
      Delete a directory relative to the base path if it exists.
      Parameters:
      sRelativePath - The relative path of the directory. May not be null.
      bDeleteRecursively - true to delete recursively, false to delete only if empty.
      Returns:
      The operation result. Never null.
      See Also:
    • deleteFile

      default @NonNull FileIOError deleteFile(@NonNull String sRelativePath)
      Delete a file relative to the base path.
      Parameters:
      sRelativePath - The relative path of the file. May not be null.
      Returns:
      The operation result. Never null.
      See Also:
    • deleteFileIfExisting

      default @NonNull FileIOError deleteFileIfExisting(@NonNull String sRelativePath)
      Delete a file relative to the base path if it exists.
      Parameters:
      sRelativePath - The relative path of the file. May not be null.
      Returns:
      The operation result. Never null.
      See Also:
    • renameDir

      default @NonNull FileIOError renameDir(@NonNull String sOldDirName, @NonNull String sNewDirName)
      Rename a directory relative to the base path.
      Parameters:
      sOldDirName - The old directory name. May not be null.
      sNewDirName - The new directory name. May not be null.
      Returns:
      The operation result. Never null.
      See Also:
    • renameFile

      default @NonNull FileIOError renameFile(@NonNull String sOldFilename, @NonNull String sNewFilename)
      Rename a file relative to the base path.
      Parameters:
      sOldFilename - The old filename. May not be null.
      sNewFilename - The new filename. May not be null.
      Returns:
      The operation result. Never null.
      See Also:
    • writeFile

      default @NonNull com.helger.base.state.ESuccess writeFile(@NonNull String sRelativePath, @NonNull com.helger.base.io.EAppend eAppend, byte @NonNull [] aBytes)
      Helper function for saving a file with correct error handling.
      Parameters:
      sRelativePath - name of the file. May not be null.
      eAppend - Appending mode. May not be null.
      aBytes - the bytes to be written. May not be null.
      Returns:
      ESuccess
    • saveFile

      default @NonNull com.helger.base.state.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 be null.
      sContent - the content to save. May not be null.
      aCharset - The character set to use. May not be null.
      Returns:
      ESuccess
    • saveFile

      default @NonNull com.helger.base.state.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 be null.
      aBytes - the bytes to be written. May not be null.
      Returns:
      ESuccess
    • appendFile

      default @NonNull com.helger.base.state.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 be null.
      sContent - the content to save. May not be null.
      aCharset - The character set to use. May not be null.
      Returns:
      ESuccess
    • appendFile

      default @NonNull com.helger.base.state.ESuccess appendFile(@NonNull String sRelativePath, byte @NonNull [] aBytes)
      Helper function for saving a file with correct error handling.
      Parameters:
      sRelativePath - name of the file. May not be null.
      aBytes - the bytes to be written. May not be null.
      Returns:
      ESuccess