Package com.mku.file

Class JavaFile

java.lang.Object
com.mku.file.JavaFile
All Implemented Interfaces:
IRealFile

public class JavaFile extends Object implements IRealFile
Salmon RealFile implementation for Java.
  • Constructor Details

    • JavaFile

      public JavaFile(String path)
      Instantiate a real file represented by the filepath provided.
      Parameters:
      path - The filepath.
  • Method Details

    • createDirectory

      public IRealFile createDirectory(String dirName)
      Create a directory under this directory.
      Specified by:
      createDirectory in interface IRealFile
      Parameters:
      dirName - The name of the new directory.
      Returns:
      The newly created directory.
    • createFile

      public IRealFile createFile(String filename) throws IOException
      Create a file under this directory.
      Specified by:
      createFile in interface IRealFile
      Parameters:
      filename - The name of the new file.
      Returns:
      The newly created file.
      Throws:
      IOException - Thrown if there is an IO error.
    • delete

      public boolean delete()
      Delete this file or directory.
      Specified by:
      delete in interface IRealFile
      Returns:
      True if deletion is successful.
    • exists

      public boolean exists()
      True if file or directory exists.
      Specified by:
      exists in interface IRealFile
      Returns:
      True if exists.
    • getAbsolutePath

      public String getAbsolutePath()
      Get the absolute path on the physical disk. For java this is the same as the filepath.
      Specified by:
      getAbsolutePath in interface IRealFile
      Returns:
      The absolute path.
    • getBaseName

      public String getBaseName()
      Get the name of this file or directory.
      Specified by:
      getBaseName in interface IRealFile
      Returns:
      The name of this file or directory.
    • getInputStream

      public RandomAccessStream getInputStream() throws FileNotFoundException
      Get a stream for reading the file.
      Specified by:
      getInputStream in interface IRealFile
      Returns:
      The stream to read from.
      Throws:
      FileNotFoundException - Thrown if file not found
    • getOutputStream

      public RandomAccessStream getOutputStream() throws FileNotFoundException
      Get a stream for writing to this file.
      Specified by:
      getOutputStream in interface IRealFile
      Returns:
      The stream to write to.
      Throws:
      FileNotFoundException - Thrown if file not found
    • getParent

      public IRealFile getParent()
      Get the parent directory of this file or directory.
      Specified by:
      getParent in interface IRealFile
      Returns:
      The parent directory.
    • getPath

      public String getPath()
      Get the path of this file. For java this is the same as the absolute filepath.
      Specified by:
      getPath in interface IRealFile
      Returns:
      The path
    • isDirectory

      public boolean isDirectory()
      True if this is a directory.
      Specified by:
      isDirectory in interface IRealFile
      Returns:
      True if it's a directory.
    • isFile

      public boolean isFile()
      True if this is a file.
      Specified by:
      isFile in interface IRealFile
      Returns:
      True if it's a file
    • lastModified

      public long lastModified()
      Get the last modified date on disk.
      Specified by:
      lastModified in interface IRealFile
      Returns:
      The last modified date in milliseconds
    • length

      public long length()
      Get the size of the file on disk.
      Specified by:
      length in interface IRealFile
      Returns:
      The length
    • getChildrenCount

      public int getChildrenCount()
      Get the count of files and subdirectories
      Specified by:
      getChildrenCount in interface IRealFile
      Returns:
      The children count
    • listFiles

      public IRealFile[] listFiles()
      List all files under this directory.
      Specified by:
      listFiles in interface IRealFile
      Returns:
      The list of files.
    • move

      public IRealFile move(IRealFile newDir)
      Move this file or directory under a new directory.
      Specified by:
      move in interface IRealFile
      Parameters:
      newDir - The target directory.
      Returns:
      The moved file. Use this file for subsequent operations instead of the original.
    • move

      public IRealFile move(IRealFile newDir, String newName)
      Move this file or directory under a new directory.
      Specified by:
      move in interface IRealFile
      Parameters:
      newDir - The target directory.
      newName - The new filename
      Returns:
      The moved file. Use this file for subsequent operations instead of the original.
    • move

      public IRealFile move(IRealFile newDir, String newName, BiConsumer<Long,Long> progressListener)
      Move this file or directory under a new directory.
      Specified by:
      move in interface IRealFile
      Parameters:
      newDir - The target directory.
      newName - The new filename
      progressListener - Observer to notify when progress changes.
      Returns:
      The moved file. Use this file for subsequent operations instead of the original.
    • copy

      public IRealFile copy(IRealFile newDir) throws IOException
      Move this file or directory under a new directory.
      Specified by:
      copy in interface IRealFile
      Parameters:
      newDir - The target directory.
      Returns:
      The copied file. Use this file for subsequent operations instead of the original.
      Throws:
      IOException - Thrown if there is an IO error.
    • copy

      public IRealFile copy(IRealFile newDir, String newName) throws IOException
      Move this file or directory under a new directory.
      Specified by:
      copy in interface IRealFile
      Parameters:
      newDir - The target directory.
      newName - New filename
      Returns:
      The copied file. Use this file for subsequent operations instead of the original.
      Throws:
      IOException - Thrown if there is an IO error.
    • copy

      public IRealFile copy(IRealFile newDir, String newName, BiConsumer<Long,Long> progressListener) throws IOException
      Move this file or directory under a new directory.
      Specified by:
      copy in interface IRealFile
      Parameters:
      newDir - The target directory.
      newName - New filename
      progressListener - Observer to notify when progress changes.
      Returns:
      The copied file. Use this file for subsequent operations instead of the original.
      Throws:
      IOException - Thrown if there is an IO error.
    • getChild

      public IRealFile getChild(String filename)
      Get the file or directory under this directory with the provided name.
      Specified by:
      getChild in interface IRealFile
      Parameters:
      filename - The name of the file or directory.
      Returns:
      The child
    • renameTo

      public boolean renameTo(String newFilename)
      Rename the current file or directory.
      Specified by:
      renameTo in interface IRealFile
      Parameters:
      newFilename - The new name for the file or directory.
      Returns:
      True if successfully renamed.
    • mkdir

      public boolean mkdir()
      Create this directory under the current filepath.
      Specified by:
      mkdir in interface IRealFile
      Returns:
      True if created.
    • toString

      public String toString()
      Returns a string representation of this object
      Overrides:
      toString in class Object