Class MemoryFileSystem

java.lang.Object
io.trino.filesystem.memory.MemoryFileSystem
All Implemented Interfaces:
TrinoFileSystem

public class MemoryFileSystem extends Object implements TrinoFileSystem
A blob file system for testing.
  • Constructor Details

    • MemoryFileSystem

      public MemoryFileSystem()
  • Method Details

    • newInputFile

      public TrinoInputFile newInputFile(Location location)
      Description copied from interface: TrinoFileSystem
      Creates a TrinoInputFile which can be used to read the file data. The file location path cannot be empty, and must not end with a slash or whitespace.
      Specified by:
      newInputFile in interface TrinoFileSystem
    • newInputFile

      public TrinoInputFile newInputFile(Location location, long length)
      Description copied from interface: TrinoFileSystem
      Creates a TrinoInputFile with a predeclared length which can be used to read the file data. The length will be returned from TrinoInputFile.length() and the actual file length will never be checked. The file location path cannot be empty, and must not end with a slash or whitespace.
      Specified by:
      newInputFile in interface TrinoFileSystem
    • newOutputFile

      public TrinoOutputFile newOutputFile(Location location)
      Description copied from interface: TrinoFileSystem
      Creates a TrinoOutputFile which can be used to create or overwrite the file. The file location path cannot be empty, and must not end with a slash or whitespace.
      Specified by:
      newOutputFile in interface TrinoFileSystem
    • deleteFile

      public void deleteFile(Location location) throws IOException
      Description copied from interface: TrinoFileSystem
      Deletes the specified file. The file location path cannot be empty, and must not end with a slash or whitespace. If the file is a director, an exception is raised.
      Specified by:
      deleteFile in interface TrinoFileSystem
      Throws:
      IOException - if the file does not exist (optional) or was not deleted
    • deleteDirectory

      public void deleteDirectory(Location location) throws IOException
      Description copied from interface: TrinoFileSystem
      Deletes all files and directories within the specified directory recursively, and deletes the directory itself. If the location does not exist, this method is a noop. If the location does not have a path, all files and directories in the file system are deleted.

      For hierarchical file systems (e.g. HDFS), if the path is not a directory, an exception is raised.

      For blob file systems (e.g., S3), if the location does not end with a slash, one is appended, and all blobs that start with that prefix are deleted.

      If this operation fails, some, none, or all of the directory contents may have been deleted.

      Specified by:
      deleteDirectory in interface TrinoFileSystem
      Parameters:
      location - the directory to delete
      Throws:
      IOException
    • renameFile

      public void renameFile(Location source, Location target) throws IOException
      Description copied from interface: TrinoFileSystem
      Rename source to target without overwriting target. This method is not required to be atomic, but it is required that if an error occurs, the source, target, or both must exist with the data from the source. This operation may or may not preserve the last modified time.
      Specified by:
      renameFile in interface TrinoFileSystem
      Throws:
      IOException
    • listFiles

      public FileIterator listFiles(Location location) throws IOException
      Description copied from interface: TrinoFileSystem
      Lists all files within the specified directory recursively. The location can be empty, listing all files in the file system, otherwise the location must end with a slash. If the location does not exist, an empty iterator is returned.

      For hierarchical file systems, if the path is not a directory, an exception is raised. For hierarchical file systems, if the path does not reference an existing directory, an empty iterator is returned. For blob file systems, all blobs that start with the location are listed. In the rare case that a blob exists with the exact name of the prefix, it is not included in the results.

      The returned FileEntry locations will start with the specified location exactly.

      Specified by:
      listFiles in interface TrinoFileSystem
      Parameters:
      location - the directory to list
      Throws:
      IOException
    • directoryExists

      public Optional<Boolean> directoryExists(Location location) throws IOException
      Description copied from interface: TrinoFileSystem
      Checks if a directory exists at the specified location. For all file system types, this returns true if the location is empty (the root of the file system) or if any files exist within the directory, as determined by TrinoFileSystem.listFiles(Location). Otherwise:
      • For hierarchical file systems, this returns true if the location is an empty directory, else it returns false.
      • For non-hierarchical file systems, an Optional.empty() is returned, indicating that the file system has no concept of an empty directory.
      Specified by:
      directoryExists in interface TrinoFileSystem
      Parameters:
      location - the location to check for a directory
      Throws:
      IOException
    • createDirectory

      public void createDirectory(Location location) throws IOException
      Description copied from interface: TrinoFileSystem
      Creates the specified directory and any parent directories that do not exist. For hierarchical file systems, if the location already exists but is not a directory, or if the directory cannot be created, an exception is raised. This method does nothing for non-hierarchical file systems or if the directory already exists.
      Specified by:
      createDirectory in interface TrinoFileSystem
      Throws:
      IOException
    • renameDirectory

      public void renameDirectory(Location source, Location target) throws IOException
      Description copied from interface: TrinoFileSystem
      Renames source to target. An exception is raised if the target already exists, or on non-hierarchical file systems.
      Specified by:
      renameDirectory in interface TrinoFileSystem
      Throws:
      IOException