public abstract class InMemoryFileSystem extends FileSystem
Files
class.
The methods rely on a Path
value, normally created by
calling Paths.get(String, String...)
. In a unit test, you would instead
call getPath(String, String...)
.
Currently, the following methods are supported:
<ul>
<li>Files.exists(Path, LinkOption...)
<li>Files.lines(Path)
<li>Files.lines(Path, Charset)
<li>Files.newBufferedReader(Path)
<li>Files.newBufferedReader(Path, Charset)
<li>Files.newInputStream(Path, OpenOption...)
<li>Files.notExists(Path, LinkOption...)
<li>Files.readAllBytes(Path)
<li>Files.readAllLines(Path)
<li>Files.readAllLines(Path, Charset)
</ul>Constructor and Description |
---|
InMemoryFileSystem() |
Modifier and Type | Method and Description |
---|---|
static InMemoryFileSystem |
createInstance()
Creates an instance for a test.
|
void |
defineFile(String filePath,
byte... contents)
Defines the contents for an in-memory file.
|
void |
defineFile(String filePath,
String contents)
Defines the contents for an in-memory file.
|
void |
defineFile(String filePath,
String contents,
String charset)
Defines the contents for an in-memory file.
|
Path |
getPath(String first,
String... more) |
FileSystemProvider |
provider() |
close, getFileStores, getPathMatcher, getRootDirectories, getSeparator, getUserPrincipalLookupService, isOpen, isReadOnly, newWatchService, supportedFileAttributeViews
public static InMemoryFileSystem createInstance()
public void defineFile(String filePath, String contents)
filePath
- the path to the filecontents
- a string to use as the file constantspublic void defineFile(String filePath, String contents, String charset)
filePath
- the path to the filecontents
- a string to use as the file constantscharset
- the character set to use to translate the string to bytespublic void defineFile(String filePath, byte... contents)
filePath
- the path to the filecontents
- the file contentspublic Path getPath(String first, String... more)
getPath
in class FileSystem
public FileSystemProvider provider()
provider
in class FileSystem
Copyright © 2024. All rights reserved.