public class DirectoryManagerImpl extends Object implements DirectoryManager
Constructor and Description |
---|
DirectoryManagerImpl(Path baseDirectory,
Boolean readOnly)
Constructor
|
Modifier and Type | Method and Description |
---|---|
long |
createFile(String fileName,
InputStream inputStream)
Creates a new file in the current directory, and fill it with the data
from the given input stream.
|
void |
createFile(String fileName,
String fileContents)
Creates a new file in the current directory, and fill it with the given
data, encoded in UTF-8.
|
long |
createFileAtomic(String fileName,
InputStream inputStream)
Creates a new file in the current directory, and fill it with the data
from the given input stream.
|
protected InputStream |
getCompressorInputStream(InputStream inputStream,
CompressionType compressionType)
Returns an input stream that applies the required decompression to the
given input stream.
|
InputStream |
getInputStreamForFile(String fileName,
CompressionType compressionType)
Returns an input stream to access file of the given name within the
current directory, possibly uncompressing it if required.
|
OutputStream |
getOutputStreamForFile(String fileName)
Opens and returns an output stream that can be used to write to the file
of the given name within the current directory.
|
List<String> |
getSubdirectories(String glob)
Returns a list of the names of all subdirectories of the base directory.
|
DirectoryManager |
getSubdirectoryManager(String subdirectoryName)
Returns a new directory manager for the subdirectory of the given name.
|
boolean |
hasFile(String fileName)
Checks if there is a file of the given name.
|
boolean |
hasSubdirectory(String subdirectoryName)
Checks if there is a subdirectory of the given name.
|
String |
toString() |
public DirectoryManagerImpl(Path baseDirectory, Boolean readOnly) throws IOException
baseDirectory
- the directory where the file manager should point initially;
will be created if not existingreadOnly
- if false, the directory manager will attempt to create
directories when changing to a location that does not existIOException
- if there was a problem creating the directorypublic DirectoryManager getSubdirectoryManager(String subdirectoryName) throws IOException
DirectoryManager
DirectoryManager.hasSubdirectory(String)
first (ignoring the fact that there
might be race conditions when accessing the file system).getSubdirectoryManager
in interface DirectoryManager
subdirectoryName
- the string name of the subdirectoryIOException
- if directory could not be createdpublic boolean hasSubdirectory(String subdirectoryName)
DirectoryManager
hasSubdirectory
in interface DirectoryManager
subdirectoryName
- the name of the subdirectorypublic boolean hasFile(String fileName)
DirectoryManager
hasFile
in interface DirectoryManager
fileName
- the name of the filepublic long createFile(String fileName, InputStream inputStream) throws IOException
DirectoryManager
createFile
in interface DirectoryManager
fileName
- the name of the fileinputStream
- the input stream from which to load the fileIOException
public long createFileAtomic(String fileName, InputStream inputStream) throws IOException
DirectoryManager
If the stream encodes a string, then it should generally be encoded in UTF-8, since access methods assume this.
createFileAtomic
in interface DirectoryManager
fileName
- the name of the fileinputStream
- the input stream from which to load the fileIOException
public void createFile(String fileName, String fileContents) throws IOException
DirectoryManager
createFile
in interface DirectoryManager
fileName
- the name of the filefileContents
- the data to write into the fileIOException
public OutputStream getOutputStreamForFile(String fileName) throws IOException
DirectoryManager
getOutputStreamForFile
in interface DirectoryManager
fileName
- the name of the fileIOException
public InputStream getInputStreamForFile(String fileName, CompressionType compressionType) throws IOException
DirectoryManager
It is important to close the stream after using it to free memory.
getInputStreamForFile
in interface DirectoryManager
fileName
- the name of the filecompressionType
- for types other than CompressionType.NONE
, the file
will be uncompressed appropriately and the returned input
stream will provide access to the uncompressed contentIOException
protected InputStream getCompressorInputStream(InputStream inputStream, CompressionType compressionType) throws IOException
inputStream
- the input stream with the (possibly compressed) datacompressionType
- the kind of compressionIOException
- if there was a problem creating the decompression streamspublic List<String> getSubdirectories(String glob) throws IOException
DirectoryManager
getSubdirectories
in interface DirectoryManager
glob
- pattern to filter directoy namesIOException
Copyright © 2014–2024 Wikidata Toolkit Developers. Generated from source code published under the Apache License 2.0. For more information, see the Wikidata Toolkit homepage