Lock changes
This commit is contained in:
parent
6575592538
commit
fcf12b8b72
@ -0,0 +1,55 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -3,14 +3,19 @@ import ru.redguy.tftpserver.TFTPServer;
|
|||||||
import ru.redguy.tftpserver.TFTPread;
|
import ru.redguy.tftpserver.TFTPread;
|
||||||
import ru.redguy.tftpserver.TFTPwrite;
|
import ru.redguy.tftpserver.TFTPwrite;
|
||||||
import ru.redguy.tftpserver.datasource.FileSystem;
|
import ru.redguy.tftpserver.datasource.FileSystem;
|
||||||
|
import ru.redguy.tftpserver.datasource.IDataSource;
|
||||||
|
import ru.redguy.tftpserver.datasource.VirtualFileSystem;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TFTPServer tftpServer = new TFTPServer();
|
TFTPServer tftpServer = new TFTPServer();
|
||||||
|
VirtualFileSystem ds = new VirtualFileSystem();
|
||||||
|
ds.addFile("a.gradle",new File("build.gradle"));
|
||||||
try {
|
try {
|
||||||
tftpServer.start(1000,false,new FileSystem("gradle"));
|
tftpServer.start(1000,false,ds);
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user