Erste Version für alle A Testate

This commit is contained in:
2025-08-12 15:45:03 +02:00
parent edae167d26
commit e884fbca5f
58 changed files with 4290 additions and 192 deletions
@@ -0,0 +1,126 @@
import java.io.IOException;
import java.net.URI;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class InMemoryFileSystemProvider extends FileSystemProvider {
private static final String SCHEME = "memory";
private final Map<String, InMemoryFileSystem> fileSystems = new ConcurrentHashMap<>();
@Override
public String getScheme() {
return SCHEME;
}
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
String key = uri.getHost();
if (key == null)
key = "default";
InMemoryFileSystem fs = new InMemoryFileSystem(this);
fileSystems.put(key, fs);
return fs;
}
@Override
public FileSystem getFileSystem(URI uri) {
String key = uri.getHost();
if (key == null)
key = "default";
InMemoryFileSystem fs = fileSystems.get(key);
if (fs == null) {
throw new FileSystemNotFoundException();
}
return fs;
}
@Override
public Path getPath(URI uri) {
return getFileSystem(uri).getPath(uri.getPath());
}
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)
throws IOException {
return new InMemoryByteChannel(path, options);
}
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)
throws IOException {
throw new UnsupportedOperationException("Directory operations not supported");
}
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
// For simplicity, we'll just track that this directory exists
InMemoryFileSystem.getStorage().put(dir.toString() + "/", new byte[0]);
}
@Override
public void delete(Path path) throws IOException {
if (InMemoryFileSystem.getStorage().remove(path.toString()) == null) {
throw new NoSuchFileException(path.toString());
}
}
@Override
public void copy(Path source, Path target, CopyOption... options) throws IOException {
throw new UnsupportedOperationException("Copy operation not supported");
}
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
throw new UnsupportedOperationException("Move operation not supported");
}
@Override
public boolean isSameFile(Path path, Path path2) throws IOException {
throw new UnsupportedOperationException("isSameFile not supported");
}
@Override
public boolean isHidden(Path path) throws IOException {
throw new UnsupportedOperationException("Hidden file operations not supported");
}
@Override
public FileStore getFileStore(Path path) throws IOException {
throw new UnsupportedOperationException("FileStore operations not supported");
}
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
throw new UnsupportedOperationException("Check access not supported");
}
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
throw new UnsupportedOperationException("File attribute views not supported");
}
@Override
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options)
throws IOException {
throw new UnsupportedOperationException("File attributes not supported");
}
@Override
public Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
throw new UnsupportedOperationException("Reading attributes not supported");
}
@Override
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException {
throw new UnsupportedOperationException("Setting attributes not supported");
}
}