Class LocalFileStorageConnector

  • All Implemented Interfaces:
    StorageConnector

    public class LocalFileStorageConnector
    extends Object
    implements StorageConnector
    Implementation that uses local filesystem. All paths are appended with the base path, in such a way that it is not visible to the users of this class.
    • Method Detail

      • pathExists

        public boolean pathExists​(String path)
        Description copied from interface: StorageConnector
        Check if the path exists in the underlying storage layer. Most implementations prepend the input path with a basePath.
        Specified by:
        pathExists in interface StorageConnector
        Returns:
        true if path exists else false.
      • read

        public InputStream read​(String path)
                         throws IOException
        Description copied from interface: StorageConnector
        Reads the data present at the path in the underlying storage system. Most implementations prepend the input path with a basePath. The caller should take care of closing the stream when done or in case of error.
        Specified by:
        read in interface StorageConnector
        Returns:
        InputStream
        Throws:
        IOException - if the path is not present or the unable to read the data present on the path.
      • readRange

        public InputStream readRange​(String path,
                                     long from,
                                     long size)
                              throws IOException
        Description copied from interface: StorageConnector
        Reads the data present for a given range at the path in the underlying storage system. Most implementations prepend the input path with a basePath. The caller should take care of closing the stream when done or in case of error. Further, the caller must ensure that the start offset and the size of the read are valid parameters for the given path for correct behavior.
        Specified by:
        readRange in interface StorageConnector
        Parameters:
        path - The path to read data from
        from - Start offset of the read in the path
        size - Length of the read to be done
        Returns:
        InputStream starting from the given offset limited by the given size
        Throws:
        IOException - if the path is not present or the unable to read the data present on the path
      • write

        public OutputStream write​(String path)
                           throws IOException
        Writes the file present with the materialized location as basePath + path. In case the parent directory does not exist, we create the parent dir recursively. Closing of the stream is the responsibility of the caller.
        Specified by:
        write in interface StorageConnector
        Parameters:
        path - path to write contents to.
        Returns:
        OutputStream which can be used by callers to write contents.
        Throws:
        IOException - thrown in case of errors.
      • deleteFile

        public void deleteFile​(String path)
                        throws IOException
        Deletes the file present at the location basePath + path. Throws an exception in case a dir is encountered.
        Specified by:
        deleteFile in interface StorageConnector
        Parameters:
        path - input path
        Throws:
        IOException - thrown in case of errors.
      • deleteFiles

        public void deleteFiles​(Iterable<String> paths)
                         throws IOException
        Deletes the files present at each basePath + path. Throws an exception in case a dir is encountered.
        Specified by:
        deleteFiles in interface StorageConnector
        Parameters:
        paths - list of path to delete
        Throws:
        IOException - thrown in case of errors.
      • deleteRecursively

        public void deleteRecursively​(String dirName)
                               throws IOException
        Deletes the files and sub dirs present at the basePath + dirName. Also removes the dirName
        Specified by:
        deleteRecursively in interface StorageConnector
        Parameters:
        dirName - path
        Throws:
        IOException - thrown in case of errors.
      • listDir

        public Iterator<String> listDir​(String dirName)
        Description copied from interface: StorageConnector
        Returns a lazy iterator containing all the files present in the path. The returned filenames should be such that joining the dirName and the file name form the full path that can be used as the arguments for other methods of the storage connector. For example, for a S3 path such as s3://bucket/parent1/parent2/child, the filename returned for the input path "parent1/parent2" should be "child" and for input "parent1" should be "parent2/child"
        Specified by:
        listDir in interface StorageConnector
      • getBasePath

        public File getBasePath()