Erste Version für alle A Testate
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class InMemoryPathFactory {
|
||||
|
||||
private static InMemoryFileSystem fileSystem;
|
||||
|
||||
private InMemoryPathFactory() {
|
||||
// Utility class - private constructor
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
// Create the in-memory file system
|
||||
URI uri = URI.create("memory://default/");
|
||||
Map<String, Object> env = new HashMap<>();
|
||||
fileSystem = (InMemoryFileSystem) FileSystems.newFileSystem(uri, env);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to create in-memory file system", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new in-memory path
|
||||
*
|
||||
* @param path the path string
|
||||
* @return a InMemoryPath that exists only in memory
|
||||
*/
|
||||
public static Path createPath(String path) {
|
||||
return new InMemoryPath(fileSystem, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the in-memory file system instance
|
||||
*
|
||||
* @return the file system
|
||||
*/
|
||||
public static FileSystem getFileSystem() {
|
||||
return fileSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all data from the in-memory file system
|
||||
*/
|
||||
public static 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 static boolean exists(Path path) {
|
||||
return InMemoryFileSystem.getStorage().containsKey(path.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user