mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-12-27 04:11:45 -08:00
46 lines
1.1 KiB
Java
46 lines
1.1 KiB
Java
package com.zerotier.one;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
|
|
public class JavaFileProvider implements DataStoreFileProvider {
|
|
private String _path;
|
|
|
|
public JavaFileProvider(String path) {
|
|
this._path = path;
|
|
}
|
|
|
|
@Override
|
|
public FileInputStream getInputFileStream(String name)
|
|
throws FileNotFoundException {
|
|
File f = new File(_path + File.separator + name);
|
|
return new FileInputStream(f);
|
|
}
|
|
|
|
@Override
|
|
public FileOutputStream getOutputFileStream(String name)
|
|
throws FileNotFoundException {
|
|
File f = new File(_path + File.separator + name);
|
|
if(!f.exists())
|
|
{
|
|
try {
|
|
f.createNewFile();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return new FileOutputStream(f);
|
|
}
|
|
|
|
@Override
|
|
public void deleteFile(String name) throws IOException {
|
|
File f = new File(_path + File.separator + name);
|
|
boolean success = f.delete();
|
|
if(!success) {
|
|
throw new IOException("Unable to delete file: " + _path + File.pathSeparator + name);
|
|
}
|
|
}
|
|
}
|