public class VirtualFile extends Object
VirtualFileSystem
.
The way this file can be modified, can be controlled by providing the appropriate callbacks. If no appropriate handler is given, the operation is blocked for that file. Therefore, by default, a file is unmodifyable unless some handlers are provided.
Constructor and Description |
---|
VirtualFile(VirtualFile parent,
String name)
Creates a new file with the given name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
createChildDirectory(String name)
Tries to create a subdirectory with the given name.
|
OutputStream |
createChildFile(String childName)
Creates a child file with the given name.
|
InputStream |
createInputStream()
Creates an input stream to read the contents of the file.
|
OutputStream |
createOutputStream()
Creates an output stream to write to the file.
|
static VirtualFile |
createRootNode()
Creates a root node, which represents "/".
|
boolean |
delete()
Tries to delete this file.
|
void |
enumerateChildren(Consumer<VirtualFile> childCollector)
Enumerates all children of this file.
|
Optional<VirtualFile> |
findChild(String name)
Tries to find a child with the given name.
|
long |
getLastModified()
Returns the last modification timestamp.
|
String |
getName()
Returns the name of this file.
|
VirtualFile |
getParent()
Returns the parent file of this file.
|
String |
getPath()
Returns the absolute path of this file within the virtual file system.
|
long |
getSize()
Returns the size of this file.
|
boolean |
isDirectory()
Determines if the file represents a directory.
|
boolean |
isReadable()
Determines if the file is readable.
|
boolean |
isWriteable()
Determines if the file is writeable.
|
String |
toString() |
VirtualFile |
withChildren(BiConsumer<VirtualFile,Consumer<VirtualFile>> childProvider)
Used to retrieve all child files of a directory.
|
VirtualFile |
withCreateDirectoryHandler(Function<String,Boolean> createDirectoryHandler)
Permits to create sub directories by invoking the given handler.
|
VirtualFile |
withCreateFileHandler(Function<String,OutputStream> createFileHandler)
Permits to create a child file with the given name and contents.
|
VirtualFile |
withDeleteHandler(Supplier<Boolean> deleteHandler)
Permits to delete a file.
|
VirtualFile |
withInputStreamSupplier(Supplier<InputStream> inputStreamSupplier)
Permits to read the contents of a file.
|
VirtualFile |
withLastModified(long lastModified)
Specifies the timestamp which represents the last modification.
|
VirtualFile |
withOutputStreamSupplier(Supplier<OutputStream> outputStreamSupplier)
Permits to write the contents of a file.
|
VirtualFile |
withSize(long size)
Specifies the file size in bytes.
|
public VirtualFile(@Nonnull VirtualFile parent, @Nonnull String name)
parent
- the parent of the filename
- the name of the filepublic static VirtualFile createRootNode()
public VirtualFile withChildren(BiConsumer<VirtualFile,Consumer<VirtualFile>> childProvider)
childProvider
- the provider which supplies all children to a consumerpublic VirtualFile withLastModified(long lastModified)
lastModified
- the timestamp of the last modificationFile.lastModified()
public VirtualFile withSize(long size)
size
- the size in bytespublic VirtualFile withCreateDirectoryHandler(Function<String,Boolean> createDirectoryHandler)
createDirectoryHandler
- the handler to create a sub directory with the given namepublic VirtualFile withCreateFileHandler(Function<String,OutputStream> createFileHandler)
createFileHandler
- the handler to create a child filepublic VirtualFile withDeleteHandler(Supplier<Boolean> deleteHandler)
deleteHandler
- the handler to delete the filepublic VirtualFile withInputStreamSupplier(Supplier<InputStream> inputStreamSupplier)
inputStreamSupplier
- the handler which provides an input stream of the files contents.public VirtualFile withOutputStreamSupplier(Supplier<OutputStream> outputStreamSupplier)
outputStreamSupplier
- the handler which provides an output stream to write into the file.public boolean isDirectory()
public VirtualFile getParent()
public String getPath()
public String getName()
public long getLastModified()
File.lastModified()
public long getSize()
public boolean delete()
public void enumerateChildren(Consumer<VirtualFile> childCollector)
childCollector
- the consumer collecting all children of this filepublic Optional<VirtualFile> findChild(String name)
name
- the name of the child to findpublic boolean createChildDirectory(String name)
name
- the name of the subdirectory to createpublic OutputStream createChildFile(String childName)
childName
- the name of the child.public OutputStream createOutputStream()
public boolean isReadable()
public boolean isWriteable()
public InputStream createInputStream()
Copyright © 2018. All rights reserved.