Files
Testate/WS2526/Testat 3a/InMemoryPathFactory.java
T
2025-09-11 11:21:02 +02:00

45 lines
1.1 KiB
Java

import java.nio.file.FileSystem;
import java.nio.file.Path;
public class InMemoryPathFactory {
private final InMemoryFileSystemProvider provider = new InMemoryFileSystemProvider();
private final InMemoryFileSystem fileSystem = new InMemoryFileSystem(provider);
/**
* Creates a new in-memory path
*
* @param path the path string
* @return a InMemoryPath that exists only in memory
*/
public Path createPath(String path) {
return new InMemoryPath(fileSystem, path);
}
/**
* Gets the in-memory file system instance
*
* @return the file system
*/
public FileSystem getFileSystem() {
return fileSystem;
}
/**
* Clears all data from the in-memory file system
*/
public void clear() {
InMemoryFileSystem.getStorage().clear();
}
/**
* Checks if a path exists in memory
*
* @param path the path to check
* @return true if the path exists
*/
public boolean exists(Path path) {
return InMemoryFileSystem.getStorage().containsKey(path.toString());
}
}