Files
Testate/WS2526/Testat 3b/InMemoryFileSystem.java
T

89 lines
2.2 KiB
Java

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class InMemoryFileSystem extends FileSystem {
private final String SEPARATOR = "/";
private static final Map<String, byte[]> storage = new ConcurrentHashMap<>();
private final InMemoryFileSystemProvider provider;
private boolean isOpen = true;
public InMemoryFileSystem(InMemoryFileSystemProvider provider) {
this.provider = provider;
}
public static Map<String, byte[]> getStorage() {
return storage;
}
@Override
public FileSystemProvider provider() {
return provider;
}
@Override
public void close() throws IOException {
isOpen = false;
}
@Override
public boolean isOpen() {
return isOpen;
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public String getSeparator() {
return SEPARATOR;
}
@Override
public Iterable<Path> getRootDirectories() {
return Collections.singletonList(getPath(SEPARATOR));
}
@Override
public Iterable<FileStore> getFileStores() {
return Collections.emptyList();
}
@Override
public Set<String> supportedFileAttributeViews() {
return Collections.emptySet();
}
@Override
public Path getPath(String first, String... more) {
StringBuilder sb = new StringBuilder(first);
for (String part : more) {
if (!first.endsWith(SEPARATOR) && !part.startsWith(SEPARATOR)) {
sb.append(SEPARATOR);
}
sb.append(part);
}
return new InMemoryPath(this, sb.toString());
}
@Override
public PathMatcher getPathMatcher(String syntaxAndPattern) {
throw new UnsupportedOperationException();
}
@Override
public UserPrincipalLookupService getUserPrincipalLookupService() {
throw new UnsupportedOperationException();
}
@Override
public WatchService newWatchService() throws IOException {
throw new UnsupportedOperationException();
}
}