mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-12-31 06:13:00 -08: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
|
||||
public int onDataStorePut(String name, byte[] buffer, boolean secure) {
|
||||
System.out.println("Writing File: " + name);
|
||||
try {
|
||||
FileOutputStream fos = _provider.getOutputFileStream(name);
|
||||
fos.write(buffer);
|
||||
fos.close();
|
||||
return buffer.length;
|
||||
} catch (FileNotFoundException fnf) {
|
||||
|
||||
fnf.printStackTrace();
|
||||
return -1;
|
||||
} catch (IOException io) {
|
||||
|
||||
io.printStackTrace();
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onDelete(String name) {
|
||||
System.out.println("Deleting File: " + name);
|
||||
try {
|
||||
_provider.deleteFile(name);
|
||||
return 0;
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +48,7 @@ public class DataStore implements DataStoreGetListener, DataStorePutListener {
|
|||
@Override
|
||||
public long onDataStoreGet(String name, byte[] out_buffer,
|
||||
long bufferIndex, long[] out_objectSize) {
|
||||
System.out.println("Reading File: " + name);
|
||||
try {
|
||||
FileInputStream fin = _provider.getInputFileStream(name);
|
||||
out_objectSize[0] = fin.getChannel().size();
|
||||
|
|
@ -55,8 +60,11 @@ public class DataStore implements DataStoreGetListener, DataStorePutListener {
|
|||
fin.close();
|
||||
return read;
|
||||
} catch (FileNotFoundException fnf) {
|
||||
return -1;
|
||||
// Can't read a file that doesn't exist!
|
||||
out_objectSize[0] = 0;
|
||||
return 0;
|
||||
} catch (IOException io) {
|
||||
io.printStackTrace();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue