mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
DataStore now works
This commit is contained in:
parent
a9307693a6
commit
ad6ec22857
2 changed files with 23 additions and 7 deletions
|
@ -18,25 +18,29 @@ public class DataStore implements DataStoreGetListener, DataStorePutListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onDataStorePut(String name, byte[] buffer, boolean secure) {
|
public int onDataStorePut(String name, byte[] buffer, boolean secure) {
|
||||||
|
System.out.println("Writing File: " + name);
|
||||||
try {
|
try {
|
||||||
FileOutputStream fos = _provider.getOutputFileStream(name);
|
FileOutputStream fos = _provider.getOutputFileStream(name);
|
||||||
fos.write(buffer);
|
fos.write(buffer);
|
||||||
fos.close();
|
fos.close();
|
||||||
return buffer.length;
|
return buffer.length;
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
|
fnf.printStackTrace();
|
||||||
|
return -1;
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
|
io.printStackTrace();
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onDelete(String name) {
|
public int onDelete(String name) {
|
||||||
|
System.out.println("Deleting File: " + name);
|
||||||
try {
|
try {
|
||||||
_provider.deleteFile(name);
|
_provider.deleteFile(name);
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +48,7 @@ public class DataStore implements DataStoreGetListener, DataStorePutListener {
|
||||||
@Override
|
@Override
|
||||||
public long onDataStoreGet(String name, byte[] out_buffer,
|
public long onDataStoreGet(String name, byte[] out_buffer,
|
||||||
long bufferIndex, long[] out_objectSize) {
|
long bufferIndex, long[] out_objectSize) {
|
||||||
|
System.out.println("Reading File: " + name);
|
||||||
try {
|
try {
|
||||||
FileInputStream fin = _provider.getInputFileStream(name);
|
FileInputStream fin = _provider.getInputFileStream(name);
|
||||||
out_objectSize[0] = fin.getChannel().size();
|
out_objectSize[0] = fin.getChannel().size();
|
||||||
|
@ -55,8 +60,11 @@ public class DataStore implements DataStoreGetListener, DataStorePutListener {
|
||||||
fin.close();
|
fin.close();
|
||||||
return read;
|
return read;
|
||||||
} catch (FileNotFoundException fnf) {
|
} catch (FileNotFoundException fnf) {
|
||||||
return -1;
|
// Can't read a file that doesn't exist!
|
||||||
|
out_objectSize[0] = 0;
|
||||||
|
return 0;
|
||||||
} catch (IOException io) {
|
} catch (IOException io) {
|
||||||
|
io.printStackTrace();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,28 @@ public class JavaFileProvider implements DataStoreFileProvider {
|
||||||
@Override
|
@Override
|
||||||
public FileInputStream getInputFileStream(String name)
|
public FileInputStream getInputFileStream(String name)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
File f = new File(_path + File.pathSeparator + name);
|
File f = new File(_path + File.separator + name);
|
||||||
return new FileInputStream(f);
|
return new FileInputStream(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileOutputStream getOutputFileStream(String name)
|
public FileOutputStream getOutputFileStream(String name)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
File f = new File(_path + File.pathSeparator + name);
|
File f = new File(_path + File.separator + name);
|
||||||
|
if(!f.exists())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
f.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
return new FileOutputStream(f);
|
return new FileOutputStream(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFile(String name) throws IOException {
|
public void deleteFile(String name) throws IOException {
|
||||||
File f = new File(_path + File.pathSeparator + name);
|
File f = new File(_path + File.separator + name);
|
||||||
boolean success = f.delete();
|
boolean success = f.delete();
|
||||||
if(!success) {
|
if(!success) {
|
||||||
throw new IOException("Unable to delete file: " + _path + File.pathSeparator + name);
|
throw new IOException("Unable to delete file: " + _path + File.pathSeparator + name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue