Package org.apache.druid.storage.local
Class LocalFileStorageConnector
- java.lang.Object
-
- org.apache.druid.storage.local.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.
-
-
Constructor Summary
Constructors Constructor Description LocalFileStorageConnector(File basePath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
deleteFile(String path)
Deletes the file present at the location basePath + path.void
deleteFiles(Iterable<String> paths)
Deletes the files present at each basePath + path.void
deleteRecursively(String dirName)
Deletes the files and sub dirs present at the basePath + dirName.File
getBasePath()
Iterator<String>
listDir(String dirName)
Returns a lazy iterator containing all the files present in the path.boolean
pathExists(String path)
Check if the path exists in the underlying storage layer.InputStream
read(String path)
Reads the data present at the path in the underlying storage system.InputStream
readRange(String path, long from, long size)
Reads the data present for a given range at the path in the underlying storage system.OutputStream
write(String path)
Writes the file present with the materialized location as basePath + path.
-
-
-
Constructor Detail
-
LocalFileStorageConnector
public LocalFileStorageConnector(File basePath) throws IOException
- Throws:
IOException
-
-
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 interfaceStorageConnector
- 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 interfaceStorageConnector
- 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 interfaceStorageConnector
- Parameters:
path
- The path to read data fromfrom
- Start offset of the read in the pathsize
- 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 interfaceStorageConnector
- 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 interfaceStorageConnector
- 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 interfaceStorageConnector
- 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 interfaceStorageConnector
- 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 interfaceStorageConnector
-
getBasePath
public File getBasePath()
-
-