Package javax0.license3j.io
Class KeyPairWriter
- java.lang.Object
-
- javax0.license3j.io.KeyPairWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class KeyPairWriter extends Object implements Closeable
Class to write the key pair into two files. Key are read individually but they are written in pairs right after they are generated. This class can be used by applications that generate keys, and it is used by the repl application. Create an instance of the class using one of the constructors specifying the output files and then invoke thewrite(LicenseKeyPair, IOFormat)
method to save the keys into the files.
-
-
Constructor Summary
Constructors Constructor Description KeyPairWriter(File privateKeyFile, File publicKeyFile)
Create a target for license key pair writing specifying the outputs as files.KeyPairWriter(OutputStream privateKeyOutputStream, OutputStream publicKeyOutputStream)
Create a target for license key pair writing specifying the outputs as streams.KeyPairWriter(String privateKeyFileName, String publicKeyFileName)
Create a target for license key pair writing specifying the outputs as file names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
The class implements theCloseable
interface.void
write(LicenseKeyPair pair, IOFormat format)
Write the key pair into the output files and then close the file.
-
-
-
Constructor Detail
-
KeyPairWriter
public KeyPairWriter(OutputStream privateKeyOutputStream, OutputStream publicKeyOutputStream)
Create a target for license key pair writing specifying the outputs as streams.- Parameters:
privateKeyOutputStream
- output stream for the private keypublicKeyOutputStream
- output stream for the public key
-
KeyPairWriter
public KeyPairWriter(File privateKeyFile, File publicKeyFile) throws FileNotFoundException
Create a target for license key pair writing specifying the outputs as files.- Parameters:
privateKeyFile
- file for the private keypublicKeyFile
- file for the public key- Throws:
FileNotFoundException
- when some of the files cannot be opened to write into.
-
KeyPairWriter
public KeyPairWriter(String privateKeyFileName, String publicKeyFileName) throws FileNotFoundException
Create a target for license key pair writing specifying the outputs as file names.- Parameters:
privateKeyFileName
- the name of the file for the private keypublicKeyFileName
- the name of the file for the public key- Throws:
FileNotFoundException
- when some of the files cannot be opened to write into.
-
-
Method Detail
-
write
public void write(LicenseKeyPair pair, IOFormat format) throws IOException
Write the key pair into the output files and then close the file.- Parameters:
pair
- the key pair to write.format
- that can beIOFormat.BINARY
orIOFormat.BASE64
. UsingIOFormat.STRING
will throw exception as keys, as opposed to licenses, cannot be saved in string format.- Throws:
IOException
- when the underlying media cannot be written
-
close
public void close() throws IOException
The class implements theCloseable
interface. This method closes the license target streams.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- when some of the streams cannot be closed.
-
-