From 5d9d82879fabf2790ce42c9d8c281ec6d1a15b3a Mon Sep 17 00:00:00 2001
From: dev <dev@welterde.de>
Date: Tue, 20 May 2008 11:30:03 +0000
Subject: [PATCH] implemented PrivateKeyFile(implements #3)

---
 .../java/src/net/i2p/data/PrivateKeyFile.java | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 core/java/src/net/i2p/data/PrivateKeyFile.java

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 0000000000..572adce176
--- /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
-- 
GitLab