diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index b45a40613..cb63a80c1 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -3,9 +3,11 @@
package="net.i2p.router"
android:versionCode="1"
android:versionName="1.0.0">
+
+ android:label="@string/app_name"
+ android:launchMode="singleTask" >
diff --git a/android/build.xml b/android/build.xml
index a7b411996..5875c5fed 100644
--- a/android/build.xml
+++ b/android/build.xml
@@ -101,12 +101,15 @@
Creating output directories if needed...
+
+
+
@@ -140,7 +143,7 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
Converting compiled files and external libraries into ${outdir}/${dex-file}...
diff --git a/android/res/layout/main.xml b/android/res/layout/main.xml
index 3bfc31cff..d76411527 100644
--- a/android/res/layout/main.xml
+++ b/android/res/layout/main.xml
@@ -9,5 +9,10 @@
android:layout_height="wrap_content"
android:text="Hello World, I2PAndroid"
/>
+
diff --git a/android/res/raw/logger_config b/android/res/raw/logger_config
new file mode 100644
index 000000000..2aeabb9f6
--- /dev/null
+++ b/android/res/raw/logger_config
@@ -0,0 +1,3 @@
+logger.defaultLevel=INFO
+logger.record.net.i2p.router.transport.FIFOBandwidthRefiller=ERROR
+logger.record.net.i2p.stat.Rate=ERROR
diff --git a/android/res/raw/router_config b/android/res/raw/router_config
new file mode 100644
index 000000000..19c609542
--- /dev/null
+++ b/android/res/raw/router_config
@@ -0,0 +1,7 @@
+# initial router.config
+# save memory
+router.prng.buffers=2
+router.decayingBloomFilterM=20
+stat.full=false
+# no I2CP
+i2p.dummyClientFacade=true
diff --git a/android/src/net/i2p/router/I2PAndroid.java b/android/src/net/i2p/router/I2PAndroid.java
index 6b65bac52..c08670e36 100644
--- a/android/src/net/i2p/router/I2PAndroid.java
+++ b/android/src/net/i2p/router/I2PAndroid.java
@@ -1,18 +1,118 @@
package net.i2p.router;
import android.app.Activity;
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
import net.i2p.router.Router;
+import net.i2p.router.web.ReseedChecker;
+import net.i2p.util.I2PFile;
public class I2PAndroid extends Activity
{
+ static Context _context;
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
+
+ _context = this; // Activity extends Context
+ debugStuff();
+ initialize();
+
Router.main(null);
+ System.err.println("Router.main finished");
+
+ ReseedChecker.checkReseed();
}
+
+ public void onRestart()
+ {
+ System.err.println("onRestart called");
+ super.onRestart();
+ }
+
+ public void onResume()
+ {
+ System.err.println("onResume called");
+ super.onResume();
+ }
+
+ public void onPause()
+ {
+ System.err.println("onPause called");
+ super.onPause();
+ }
+
+ public void onStop()
+ {
+ System.err.println("onStop called");
+ super.onStop();
+ }
+
+ public void onDestroy()
+ {
+ System.err.println("onDestroy called");
+ super.onDestroy();
+ }
+
+ public static Context getContext() {
+ return _context;
+ }
+
+ private void debugStuff() {
+ System.err.println("java.vendor" + ": " + System.getProperty("java.vendor"));
+ System.err.println("java.version" + ": " + System.getProperty("java.version"));
+ System.err.println("os.arch" + ": " + System.getProperty("os.arch"));
+ System.err.println("os.name" + ": " + System.getProperty("os.name"));
+ System.err.println("os.version" + ": " + System.getProperty("os.version"));
+ System.err.println("user.dir" + ": " + System.getProperty("user.dir"));
+ System.err.println("user.home" + ": " + System.getProperty("user.home"));
+ System.err.println("user.name" + ": " + System.getProperty("user.name"));
+ }
+
+ private void initialize() {
+ // Until we can edit the router.config on the device,
+ // copy it from the resource every time.
+ // File f = new I2PFile("router.config");
+ // if (!f.exists()) {
+ copyResourceToFile(R.raw.router_config, "router.config");
+ copyResourceToFile(R.raw.logger_config, "logger.config");
+ copyResourceToFile(R.raw.blocklist_txt, "blocklist.txt");
+ // }
+ }
+
+ private void copyResourceToFile(int resID, String f) {
+ InputStream in = null;
+ FileOutputStream out = null;
+
+ System.err.println("Creating file " + f + " from resource");
+ byte buf[] = new byte[4096];
+ try {
+ // Context methods
+ in = getResources().openRawResource(resID);
+ out = openFileOutput(f, 0);
+
+ int read = 0;
+ while ( (read = in.read(buf)) != -1)
+ out.write(buf, 0, read);
+
+ } catch (IOException ioe) {
+ } catch (Resources.NotFoundException nfe) {
+ } finally {
+ if (in != null) try { in.close(); } catch (IOException ioe) {}
+ if (out != null) try { out.close(); } catch (IOException ioe) {}
+ }
+ }
+
}
diff --git a/android/src/net/i2p/router/web/ReseedChecker.java b/android/src/net/i2p/router/web/ReseedChecker.java
new file mode 100644
index 000000000..96eccce51
--- /dev/null
+++ b/android/src/net/i2p/router/web/ReseedChecker.java
@@ -0,0 +1,37 @@
+package net.i2p.router.web;
+
+import java.io.File;
+
+import net.i2p.router.web.ReseedHandler;
+import net.i2p.util.I2PFile;
+
+/**
+ * Copied from RouterConsoleRunner.java
+ */
+public class ReseedChecker {
+
+ public static void checkReseed() {
+
+ System.err.println("Checking to see if we should reseed");
+ // we check the i2p installation directory (.) for a flag telling us not to reseed,
+ // but also check the home directory for that flag too, since new users installing i2p
+ // don't have an installation directory that they can put the flag in yet.
+ File noReseedFile = new I2PFile(new I2PFile(System.getProperty("user.home")), ".i2pnoreseed");
+ File noReseedFileAlt1 = new I2PFile(new I2PFile(System.getProperty("user.home")), "noreseed.i2p");
+ File noReseedFileAlt2 = new I2PFile(".i2pnoreseed");
+ File noReseedFileAlt3 = new I2PFile("noreseed.i2p");
+ if (!noReseedFile.exists() && !noReseedFileAlt1.exists() && !noReseedFileAlt2.exists() && !noReseedFileAlt3.exists()) {
+ File netDb = new I2PFile("netDb");
+ // sure, some of them could be "my.info" or various leaseSet- files, but chances are,
+ // if someone has those files, they've already been seeded (at least enough to let them
+ // get i2p started - they can reseed later in the web console)
+ String names[] = (netDb.exists() ? netDb.list() : null);
+ if ( (names == null) || (names.length < 15) ) {
+ System.err.println("Yes, reseeding now");
+ ReseedHandler reseedHandler = new ReseedHandler();
+ reseedHandler.requestReseed();
+ }
+ }
+ }
+
+}
diff --git a/android/src/net/i2p/util/FileStreamFactory.java b/android/src/net/i2p/util/FileStreamFactory.java
new file mode 100644
index 000000000..b7a65e4f2
--- /dev/null
+++ b/android/src/net/i2p/util/FileStreamFactory.java
@@ -0,0 +1,64 @@
+/*
+ * This is free software, do as you please.
+ */
+
+package net.i2p.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+
+import net.i2p.router.I2PAndroid;
+
+/**
+ * Use android static file stream methods
+ * gaaah:
+ * 1) the CWD is /
+ * 2) we can only access /data/data/net.i2p.router/files/
+ * 3) you can't change your CWD in Java
+ * so we have this lovely and the one in I2PFile.
+ *
+ * @author zzz
+ */
+public class FileStreamFactory {
+ private static final String DIR = "/data/data/net.i2p.router/files/";
+
+ /** hopefully no path separators in string */
+ public static FileInputStream getFileInputStream(String f) throws FileNotFoundException {
+ System.err.println("Input file-s: " + I2PAndroid.getContext().getFileStreamPath(f).getAbsolutePath());
+ return I2PAndroid.getContext().openFileInput(f);
+ }
+
+ public static FileInputStream getFileInputStream(File f) throws FileNotFoundException {
+ System.err.println("Input file-f: " + getPath(f) +
+ ' ' + f.getAbsolutePath());
+ //return I2PAndroid.getContext().openFileInput(f.getName());
+ return new FileInputStream(getPath(f));
+ }
+
+ /** hopefully no path separators in string */
+ public static FileOutputStream getFileOutputStream(String f) throws FileNotFoundException {
+ System.err.println("Output file-s: " + I2PAndroid.getContext().getFileStreamPath(f).getAbsolutePath());
+ return I2PAndroid.getContext().openFileOutput(f, 0);
+ }
+
+ public static FileOutputStream getFileOutputStream(File f) throws FileNotFoundException {
+ System.err.println("Output file-f: " + getPath(f) +
+ ' ' + f.getAbsolutePath());
+ //return I2PAndroid.getContext().openFileOutput(f.getName(), 0);
+ return new FileOutputStream(getPath(f));
+ }
+
+ /**
+ * preserve path but convert /foo/blah to /data/data/net.i2p.router/files/foo/blah
+ * Although if the File arg was created with new I2PFile() then this isn't required
+ *
+ */
+ private static String getPath(File f) {
+ String abs = f.getAbsolutePath();
+ if (abs.startsWith(DIR))
+ return abs;
+ return DIR + abs.substring(1); // strip extra '/'
+ }
+}
diff --git a/android/src/net/i2p/util/I2PFile.java b/android/src/net/i2p/util/I2PFile.java
new file mode 100644
index 000000000..94bda029b
--- /dev/null
+++ b/android/src/net/i2p/util/I2PFile.java
@@ -0,0 +1,29 @@
+/*
+ * This is free software, do as you please.
+ */
+
+package net.i2p.util;
+
+import java.io.File;
+
+/**
+ * gaaah:
+ * 1) the CWD is /
+ * 2) we can only access /data/data/net.i2p.router/files/
+ * 3) you can't change your CWD in Java
+ * so we have this lovely and the one in FileStreamFactory.
+ *
+ * @author zzz
+ */
+public class I2PFile extends File {
+
+ public I2PFile (String f) {
+ super("/data/data/net.i2p.router/files/" + f);
+ }
+
+ /** one level deep only */
+ public I2PFile (File p, String f) {
+ super("/data/data/net.i2p.router/files/" + p.getName(), f);
+ }
+
+}
diff --git a/android/src/net/i2p/util/LogWriter.java b/android/src/net/i2p/util/LogWriter.java
index 847730d4f..03f5577ae 100644
--- a/android/src/net/i2p/util/LogWriter.java
+++ b/android/src/net/i2p/util/LogWriter.java
@@ -87,36 +87,44 @@ class LogWriter implements Runnable {
private void writeRecord(LogRecord rec) {
if (rec.getThrowable() == null)
- log(rec.getPriority(), rec.getSourceName(), null, rec.getThreadName(), rec.getMessage());
+ log(rec.getPriority(), rec.getSource(), rec.getSourceName(), rec.getThreadName(), rec.getMessage());
else
- log(rec.getPriority(), rec.getSourceName(), null, rec.getThreadName(), rec.getMessage(), rec.getThrowable());
+ log(rec.getPriority(), rec.getSource(), rec.getSourceName(), rec.getThreadName(), rec.getMessage(), rec.getThrowable());
}
- public void log(int priority, String className, String name, String threadName, String msg) {
- if (className != null)
+ public void log(int priority, Class src, String name, String threadName, String msg) {
+ if (src != null) {
+ String tag = src.getName();
+ int dot = tag.lastIndexOf(".");
+ if (dot >= 0)
+ tag = tag.substring(dot + 1);
android.util.Log.println(toAndroidLevel(priority),
- className,
- threadName + ' ' + msg);
- else if (name != null)
+ tag,
+ '[' + threadName + "] " + msg);
+ } else if (name != null)
android.util.Log.println(toAndroidLevel(priority),
name,
- threadName + ' ' + msg);
+ '[' + threadName + "] " + msg);
else
android.util.Log.println(toAndroidLevel(priority),
threadName, msg);
}
- public void log(int priority, String className, String name, String threadName, String msg, Throwable t) {
- if (className != null)
+ public void log(int priority, Class src, String name, String threadName, String msg, Throwable t) {
+ if (src != null) {
+ String tag = src.getName();
+ int dot = tag.lastIndexOf(".");
+ if (dot >= 0)
+ tag = tag.substring(dot + 1);
android.util.Log.println(toAndroidLevel(priority),
- className,
- threadName + ' ' + msg +
- msg + ' ' + t.toString() + ' ' + android.util.Log.getStackTraceString(t));
- else if (name != null)
+ tag,
+ '[' + threadName + "] " + msg +
+ ' ' + t.toString() + ' ' + android.util.Log.getStackTraceString(t));
+ } else if (name != null)
android.util.Log.println(toAndroidLevel(priority),
name,
- threadName + ' ' + msg +
- msg + ' ' + t.toString() + ' ' + android.util.Log.getStackTraceString(t));
+ '[' + threadName + "] " + msg +
+ ' ' + t.toString() + ' ' + android.util.Log.getStackTraceString(t));
else
android.util.Log.println(toAndroidLevel(priority),
threadName,
diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ReseedHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ReseedHandler.java
index 066cb1144..3d3d603fa 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/ReseedHandler.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/ReseedHandler.java
@@ -15,6 +15,8 @@ import java.util.StringTokenizer;
import net.i2p.I2PAppContext;
import net.i2p.router.RouterContext;
import net.i2p.util.EepGet;
+import net.i2p.util.FileStreamFactory;
+import net.i2p.util.I2PFile;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
@@ -250,11 +252,11 @@ public class ReseedHandler {
private void writeSeed(String name, byte data[]) throws Exception {
String dirName = "netDb"; // _context.getProperty("router.networkDatabase.dbDir", "netDb");
- File netDbDir = new File(dirName);
+ File netDbDir = new I2PFile(dirName);
if (!netDbDir.exists()) {
boolean ok = netDbDir.mkdirs();
}
- FileOutputStream fos = new FileOutputStream(new File(netDbDir, "routerInfo-" + name + ".dat"));
+ FileOutputStream fos = FileStreamFactory.getFileOutputStream(new I2PFile(netDbDir, "routerInfo-" + name + ".dat"));
fos.write(data);
fos.close();
}
diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java
index 53e32a347..55b424562 100644
--- a/core/java/src/net/i2p/data/DataHelper.java
+++ b/core/java/src/net/i2p/data/DataHelper.java
@@ -37,6 +37,7 @@ import java.util.TreeMap;
import java.util.zip.Deflater;
import net.i2p.util.ByteCache;
+import net.i2p.util.FileStreamFactory;
import net.i2p.util.OrderedProperties;
import net.i2p.util.ReusableGZIPInputStream;
import net.i2p.util.ReusableGZIPOutputStream;
@@ -217,7 +218,7 @@ public class DataHelper {
loadProps(props, file, false);
}
public static void loadProps(Properties props, File file, boolean forceLowerCase) throws IOException {
- loadProps(props, new FileInputStream(file), forceLowerCase);
+ loadProps(props, FileStreamFactory.getFileInputStream(file), forceLowerCase);
}
public static void loadProps(Properties props, InputStream inStr) throws IOException {
loadProps(props, inStr, false);
diff --git a/core/java/src/net/i2p/util/FileStreamFactory.java b/core/java/src/net/i2p/util/FileStreamFactory.java
new file mode 100644
index 000000000..01d505665
--- /dev/null
+++ b/core/java/src/net/i2p/util/FileStreamFactory.java
@@ -0,0 +1,36 @@
+/*
+ * public domain
+ */
+
+package net.i2p.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+
+
+/**
+ * This is pulled out and replaced in the android build.
+ *
+ * @author zzz
+ */
+public class FileStreamFactory {
+
+ public static FileInputStream getFileInputStream(String f) throws FileNotFoundException {
+ return new FileInputStream(f);
+ }
+
+ public static FileInputStream getFileInputStream(File f) throws FileNotFoundException {
+ return new FileInputStream(f);
+ }
+
+ public static FileOutputStream getFileOutputStream(String f) throws FileNotFoundException {
+ return new FileOutputStream(f);
+ }
+
+ public static FileOutputStream getFileOutputStream(File f) throws FileNotFoundException {
+ return new FileOutputStream(f);
+ }
+
+}
diff --git a/core/java/src/net/i2p/util/I2PFile.java b/core/java/src/net/i2p/util/I2PFile.java
new file mode 100644
index 000000000..107286edf
--- /dev/null
+++ b/core/java/src/net/i2p/util/I2PFile.java
@@ -0,0 +1,24 @@
+/*
+ * public domain
+ */
+
+package net.i2p.util;
+
+import java.io.File;
+
+/**
+ * This is pulled out and replaced in the android build.
+ *
+ * @author zzz
+ */
+public class I2PFile extends File {
+
+ public I2PFile (String f) {
+ super(f);
+ }
+
+ public I2PFile (File p, String f) {
+ super(p, f);
+ }
+
+}
diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java
index 1f957515c..52b828af9 100644
--- a/core/java/src/net/i2p/util/LogManager.java
+++ b/core/java/src/net/i2p/util/LogManager.java
@@ -240,7 +240,7 @@ public class LogManager {
//
private void loadConfig() {
- File cfgFile = new File(_location);
+ File cfgFile = new I2PFile(_location);
if (!cfgFile.exists()) {
if (!_alreadyNoticedMissingConfig) {
if (_log.shouldLog(Log.WARN))
@@ -268,11 +268,11 @@ public class LogManager {
Properties p = new Properties();
FileInputStream fis = null;
try {
- fis = new FileInputStream(cfgFile);
+ fis = FileStreamFactory.getFileInputStream(cfgFile);
p.load(fis);
_configLastRead = _context.clock().now();
} catch (IOException ioe) {
- System.err.println("Error loading logger config from " + new File(_location).getAbsolutePath());
+ System.err.println("Error loading logger config from " + new I2PFile(_location).getAbsolutePath());
} finally {
if (fis != null) try {
fis.close();
@@ -540,7 +540,7 @@ public class LogManager {
String config = createConfig();
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(_location);
+ fos = FileStreamFactory.getFileOutputStream(_location);
fos.write(config.getBytes());
return true;
} catch (IOException ioe) {
diff --git a/router/java/src/net/i2p/router/KeyManager.java b/router/java/src/net/i2p/router/KeyManager.java
index 4e2ed2c51..f2150b923 100644
--- a/router/java/src/net/i2p/router/KeyManager.java
+++ b/router/java/src/net/i2p/router/KeyManager.java
@@ -26,6 +26,7 @@ import net.i2p.data.PublicKey;
import net.i2p.data.SigningPrivateKey;
import net.i2p.data.SigningPublicKey;
import net.i2p.util.Clock;
+import net.i2p.util.FileStreamFactory;
import net.i2p.util.Log;
/**
@@ -205,12 +206,12 @@ public class KeyManager {
FileInputStream in = null;
try {
if (exists) {
- out = new FileOutputStream(keyFile);
+ out = FileStreamFactory.getFileOutputStream(keyFile);
structure.writeBytes(out);
return structure;
} else {
if (keyFile.exists()) {
- in = new FileInputStream(keyFile);
+ in = FileStreamFactory.getFileInputStream(keyFile);
structure.readBytes(in);
return structure;
} else {
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 13e801458..c33dc3e63 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -40,7 +40,9 @@ import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.stat.Rate;
import net.i2p.stat.RateStat;
import net.i2p.stat.StatManager;
+import net.i2p.util.FileStreamFactory;
import net.i2p.util.FileUtil;
+import net.i2p.util.I2PFile;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
@@ -292,7 +294,7 @@ public class Router {
}
Properties props = new Properties();
try {
- File f = new File(filename);
+ File f = new I2PFile(filename);
if (f.canRead()) {
DataHelper.loadProps(props, f);
// dont be a wanker
@@ -945,7 +947,7 @@ public class Router {
public boolean saveConfig() {
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(_configFilename);
+ fos = FileStreamFactory.getFileOutputStream(_configFilename);
StringBuffer buf = new StringBuffer(8*1024);
synchronized (_config) {
TreeSet ordered = new TreeSet(_config.keySet());
@@ -1331,7 +1333,7 @@ class MarkLiveliness implements Runnable {
private void ping() {
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(_pingFile);
+ fos = FileStreamFactory.getFileOutputStream(_pingFile);
fos.write(("" + System.currentTimeMillis()).getBytes());
} catch (IOException ioe) {
System.err.println("Error writing to ping file");
@@ -1378,7 +1380,7 @@ class PersistRouterInfoJob extends JobImpl {
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(infoFilename);
+ fos = FileStreamFactory.getFileOutputStream(infoFilename);
info.writeBytes(fos);
} catch (DataFormatException dfe) {
_log.error("Error rebuilding the router information", dfe);
diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java
index 5d0d219db..1d9490a33 100644
--- a/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java
+++ b/router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java
@@ -26,6 +26,8 @@ import net.i2p.data.RouterInfo;
import net.i2p.router.JobImpl;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
+import net.i2p.util.FileStreamFactory;
+import net.i2p.util.I2PFile;
import net.i2p.util.I2PThread;
import net.i2p.util.Log;
@@ -171,11 +173,11 @@ class PersistentDataStore extends TransientDataStore {
else
throw new IOException("We don't know how to write objects of type " + data.getClass().getName());
- dbFile = new File(dbDir, filename);
+ dbFile = new I2PFile(dbDir, filename);
long dataPublishDate = getPublishDate(data);
if (dbFile.lastModified() < dataPublishDate) {
// our filesystem is out of date, lets replace it
- fos = new FileOutputStream(dbFile);
+ fos = FileStreamFactory.getFileOutputStream(dbFile);
try {
data.writeBytes(fos);
fos.close();
@@ -278,7 +280,7 @@ class PersistentDataStore extends TransientDataStore {
FileInputStream fis = null;
boolean corrupt = false;
try {
- fis = new FileInputStream(_routerFile);
+ fis = FileStreamFactory.getFileInputStream(_routerFile);
RouterInfo ri = new RouterInfo();
ri.readBytes(fis);
if (ri.getNetworkId() != Router.NETWORK_ID) {
@@ -312,7 +314,7 @@ class PersistentDataStore extends TransientDataStore {
private File getDbDir() throws IOException {
- File f = new File(_dbDir);
+ File f = new I2PFile(_dbDir);
if (!f.exists()) {
boolean created = f.mkdirs();
if (!created)
@@ -362,7 +364,7 @@ class PersistentDataStore extends TransientDataStore {
private void removeFile(Hash key, File dir) throws IOException {
String riName = getRouterInfoName(key);
- File f = new File(dir, riName);
+ File f = new I2PFile(dir, riName);
if (f.exists()) {
boolean removed = f.delete();
if (!removed)
diff --git a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java
index fd88c406b..6b8e3105e 100644
--- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java
+++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java
@@ -18,6 +18,8 @@ import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
import net.i2p.router.RouterContext;
+import net.i2p.util.FileStreamFactory;
+import net.i2p.util.I2PFile;
import net.i2p.util.Log;
class ProfilePersistenceHelper {
@@ -61,7 +63,7 @@ class ProfilePersistenceHelper {
long before = _context.clock().now();
OutputStream fos = null;
try {
- fos = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(f)));
+ fos = new BufferedOutputStream(new GZIPOutputStream(FileStreamFactory.getFileOutputStream(f)));
writeProfile(profile, fos);
} catch (IOException ioe) {
_log.error("Error writing profile to " + f);
@@ -264,10 +266,10 @@ class ProfilePersistenceHelper {
private void loadProps(Properties props, File file) {
try {
- FileInputStream fin = new FileInputStream(file);
+ FileInputStream fin = FileStreamFactory.getFileInputStream(file);
int c = fin.read();
fin.close();
- fin = new FileInputStream(file); // ghetto mark+reset
+ fin = FileStreamFactory.getFileInputStream(file); // ghetto mark+reset
if (c == '#') {
// uncompressed
if (_log.shouldLog(Log.INFO))
@@ -299,7 +301,7 @@ class ProfilePersistenceHelper {
}
private File pickFile(PeerProfile profile) {
- return new File(getProfileDir(), "profile-" + profile.getPeer().toBase64() + ".dat");
+ return new I2PFile(getProfileDir(), "profile-" + profile.getPeer().toBase64() + ".dat");
}
private File getProfileDir() {
@@ -315,7 +317,7 @@ class ProfilePersistenceHelper {
dir = DEFAULT_PEER_PROFILE_DIR;
}
}
- _profileDir = new File(dir);
+ _profileDir = new I2PFile(dir);
}
return _profileDir;
}
diff --git a/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java b/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java
index 92b176c30..12c6cee6a 100644
--- a/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java
+++ b/router/java/src/net/i2p/router/startup/CreateRouterInfoJob.java
@@ -25,6 +25,7 @@ import net.i2p.router.Job;
import net.i2p.router.JobImpl;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
+import net.i2p.util.FileStreamFactory;
import net.i2p.util.Log;
public class CreateRouterInfoJob extends JobImpl {
@@ -79,13 +80,13 @@ public class CreateRouterInfoJob extends JobImpl {
String infoFilename = getContext().router().getConfigSetting(Router.PROP_INFO_FILENAME);
if (infoFilename == null)
infoFilename = Router.PROP_INFO_FILENAME_DEFAULT;
- fos1 = new FileOutputStream(infoFilename);
+ fos1 = FileStreamFactory.getFileOutputStream(infoFilename);
info.writeBytes(fos1);
String keyFilename = getContext().router().getConfigSetting(Router.PROP_KEYS_FILENAME);
if (keyFilename == null)
keyFilename = Router.PROP_KEYS_FILENAME_DEFAULT;
- fos2 = new FileOutputStream(keyFilename);
+ fos2 = FileStreamFactory.getFileOutputStream(keyFilename);
privkey.writeBytes(fos2);
signingPrivKey.writeBytes(fos2);
pubkey.writeBytes(fos2);
diff --git a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java
index 0374922af..bdd3b9867 100644
--- a/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java
+++ b/router/java/src/net/i2p/router/startup/LoadRouterInfoJob.java
@@ -21,6 +21,8 @@ import net.i2p.data.SigningPublicKey;
import net.i2p.router.JobImpl;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
+import net.i2p.util.FileStreamFactory;
+import net.i2p.util.I2PFile;
import net.i2p.util.Log;
public class LoadRouterInfoJob extends JobImpl {
@@ -62,10 +64,10 @@ public class LoadRouterInfoJob extends JobImpl {
if (keyFilename == null)
keyFilename = Router.PROP_KEYS_FILENAME_DEFAULT;
- File rif = new File(routerInfoFile);
+ File rif = new I2PFile(routerInfoFile);
if (rif.exists())
_infoExists = true;
- File rkf = new File(keyFilename);
+ File rkf = new I2PFile(keyFilename);
if (rkf.exists())
_keysExist = true;
@@ -73,14 +75,14 @@ public class LoadRouterInfoJob extends JobImpl {
FileInputStream fis2 = null;
try {
if (_infoExists) {
- fis1 = new FileInputStream(rif);
+ fis1 = FileStreamFactory.getFileInputStream(rif);
info = new RouterInfo();
info.readBytes(fis1);
_log.debug("Reading in routerInfo from " + rif.getAbsolutePath() + " and it has " + info.getAddresses().size() + " addresses");
}
if (_keysExist) {
- fis2 = new FileInputStream(rkf);
+ fis2 = FileStreamFactory.getFileInputStream(rkf);
PrivateKey privkey = new PrivateKey();
privkey.readBytes(fis2);
SigningPrivateKey signingPrivKey = new SigningPrivateKey();
diff --git a/router/java/src/net/i2p/router/startup/RebuildRouterInfoJob.java b/router/java/src/net/i2p/router/startup/RebuildRouterInfoJob.java
index 967bc7a79..f3905f89f 100644
--- a/router/java/src/net/i2p/router/startup/RebuildRouterInfoJob.java
+++ b/router/java/src/net/i2p/router/startup/RebuildRouterInfoJob.java
@@ -25,6 +25,8 @@ import net.i2p.data.SigningPublicKey;
import net.i2p.router.JobImpl;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
+import net.i2p.util.FileStreamFactory;
+import net.i2p.util.I2PFile;
import net.i2p.util.Log;
/**
@@ -93,7 +95,7 @@ public class RebuildRouterInfoJob extends JobImpl {
String keyFilename = getContext().router().getConfigSetting(Router.PROP_KEYS_FILENAME);
if (keyFilename == null)
keyFilename = Router.PROP_KEYS_FILENAME_DEFAULT;
- File keyFile = new File(keyFilename);
+ File keyFile = new I2PFile(keyFilename);
if (keyFile.exists()) {
// ok, no need to rebuild a brand new identity, just update what we can
@@ -102,7 +104,7 @@ public class RebuildRouterInfoJob extends JobImpl {
info = new RouterInfo();
FileInputStream fis = null;
try {
- fis = new FileInputStream(keyFile);
+ fis = FileStreamFactory.getFileInputStream(keyFile);
PrivateKey privkey = new PrivateKey();
privkey.readBytes(fis);
SigningPrivateKey signingPrivKey = new SigningPrivateKey();
@@ -146,7 +148,7 @@ public class RebuildRouterInfoJob extends JobImpl {
FileOutputStream fos = null;
try {
- fos = new FileOutputStream(infoFilename);
+ fos = FileStreamFactory.getFileOutputStream(infoFilename);
info.writeBytes(fos);
} catch (DataFormatException dfe) {
_log.error("Error rebuilding the router information", dfe);
diff --git a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java
index 9c75f5328..b3901f07e 100644
--- a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java
+++ b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java
@@ -81,7 +81,7 @@ public class EventPumper implements Runnable {
public void stopPumping() {
_alive = false;
- if (_selector.isOpen())
+ if (_selector != null &&_selector.isOpen())
_selector.wakeup();
}