summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/src/com/zerotier/one/DataStore.java16
-rw-r--r--java/src/com/zerotier/one/JavaFileProvider.java14
2 files changed, 23 insertions, 7 deletions
diff --git a/java/src/com/zerotier/one/DataStore.java b/java/src/com/zerotier/one/DataStore.java
index e711ab87..1604e93e 100644
--- a/java/src/com/zerotier/one/DataStore.java
+++ b/java/src/com/zerotier/one/DataStore.java
@@ -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;
}
}
diff --git a/java/src/com/zerotier/one/JavaFileProvider.java b/java/src/com/zerotier/one/JavaFileProvider.java
index 73c98a9e..41889e2f 100644
--- a/java/src/com/zerotier/one/JavaFileProvider.java
+++ b/java/src/com/zerotier/one/JavaFileProvider.java
@@ -16,20 +16,28 @@ public class JavaFileProvider implements DataStoreFileProvider {
@Override
public FileInputStream getInputFileStream(String name)
throws FileNotFoundException {
- File f = new File(_path + File.pathSeparator + name);
+ 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.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);
}
@Override
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();
if(!success) {
throw new IOException("Unable to delete file: " + _path + File.pathSeparator + name);