diff --git a/core/java/src/net/i2p/data/PrivateKeyFile.java b/core/java/src/net/i2p/data/PrivateKeyFile.java new file mode 100644 index 0000000000000000000000000000000000000000..572adce17665e4e27edc664e5bde3fb982b6eeb2 --- /dev/null +++ b/core/java/src/net/i2p/data/PrivateKeyFile.java @@ -0,0 +1,59 @@ +package net.i2p.data; + + +import java.io.File; +import java.io.IOException; +import java.util.Properties; +import java.io.FileInputStream; +import java.io.FileOutputStream; + +import net.i2p.I2PException; +import net.i2p.client.I2PClient; +import net.i2p.client.I2PSession; +import net.i2p.client.I2PSessionException; + + +public class PrivateKeyFile { + public PrivateKeyFile(File file, I2PClient client) { + this.file = file; + this.client = client; + this.dest = null; + } + + + public void createIfAbsent() throws I2PException, IOException { + if(!this.file.exists()) { + FileOutputStream out = new FileOutputStream(this.file); + this.dest = this.client.createDestination(out); + out.close(); + } + } + + public Destination getDestination() { + // TODO: how to load destination if this is an old key? + return dest; + } + + public I2PSession open() throws I2PSessionException, IOException { + return this.open(new Properties()); + } + public I2PSession open(Properties opts) throws I2PSessionException, IOException { + // open input file + FileInputStream in = new FileInputStream(this.file); + + // create sesssion + I2PSession s = this.client.createSession(in, opts); + + // close file + in.close(); + + return s; + } + + + + + private File file; + private I2PClient client; + private Destination dest; +} \ No newline at end of file