56 lines
1.2 KiB
Java
56 lines
1.2 KiB
Java
package ru.redguy.tftpserver.datasource;
|
|
|
|
import java.io.*;
|
|
import java.util.HashMap;
|
|
|
|
public class VirtualFileSystem implements IDataSource {
|
|
|
|
private HashMap<String, File> fileHashMap = new HashMap<>();
|
|
|
|
public VirtualFileSystem() {
|
|
|
|
}
|
|
|
|
public void addFile(String name, File file) {
|
|
fileHashMap.put(name, file);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFileExists(String file) {
|
|
return fileHashMap.containsKey(file);
|
|
}
|
|
|
|
@Override
|
|
public boolean isFile(String file) {
|
|
return fileHashMap.containsKey(file);
|
|
}
|
|
|
|
@Override
|
|
public boolean isCanRead(String file) {
|
|
return fileHashMap.containsKey(file);
|
|
}
|
|
|
|
@Override
|
|
public OutputStream getOutputStream(String file) {
|
|
try {
|
|
return new FileOutputStream(fileHashMap.get(file));
|
|
} catch (FileNotFoundException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public InputStream getInputStream(String file) {
|
|
try {
|
|
return new FileInputStream(fileHashMap.get(file));
|
|
} catch (FileNotFoundException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void delete(String file) {
|
|
fileHashMap.remove(file);
|
|
}
|
|
}
|