implemented PrivateKeyFile(implements #3)
This commit is contained in:
59
core/java/src/net/i2p/data/PrivateKeyFile.java
Normal file
59
core/java/src/net/i2p/data/PrivateKeyFile.java
Normal file
@ -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;
|
||||
}
|
Reference in New Issue
Block a user