Properties instance
formatted to match the ConfigPropertyEditor
conventions.
The "set" methods return the object being modified to allow
methods to be chained. For example,
ConfigProperties props = new ConfigProperties("application/vnd.bzdev.sblauncher") .setProperty("user.description", "Example") .setProperty("user.base", "https://example.com/contents/") .setProperty("user.uri", "$(user.base)/login.html") ...;
Mostly, the methods in this class merely call the corresponding
static methods provided by ConfigPropUtilities.
-
Constructor Summary
ConstructorsConstructorDescriptionConfigProperties(File f, String mediaType) Constructor given a file.ConfigProperties(InputStream is, String mediaType) Constructor given an input stream.ConfigProperties(String mediaType) Constructor.ConfigProperties(String b64data, String mediaType) Constructor given a string containing Base64-encoded GZIPedConfigPropertiesfile. -
Method Summary
Modifier and TypeMethodDescriptionchar[]getDecryptedProperty(String key, char[] passphrase) Get the value, decrypted if necessary, stored in this object under a given key.char[]getDecryptedProperty(String key, char[] passphrase, String gpgdir) Get the value, decrypted if necessary, stored this object under a given key and a GPG home directory.getKeys()Get the current property names.getProperty(String key) Get the value stored in this object under a given key.getProperty(String key, boolean literal) Get the value stored in this object under a given key, optionally providing a literal value.String[]getRecipients(String key) Get GPG recipients that were stored using the specified key.setProperty(String key, char[] value, char[] password) Set a property for this object when symmetric* encryption is used and the value is a char array.setProperty(String key, char[] value, String gpgdir, String[] recipients) Set a property for this object when GPG encryption is used and the value of the property is a char array.setProperty(String key, String value) Set a property.setProperty(String key, String value, boolean literal) Set a property for an instance ofProperties.setProperty(String key, String value, char[] password) Set a property for this object when symmetric* encryption is used.setProperty(String key, String value, String gpgdir, String[] recipients) Set a property for this object when GPG encryption is used.setRecipients(String key, String[] recipients) Set GPG recipients that were stored using the specified key.store()Store this object as a Base-64 encoded string.Store this object, given an output file, using theConfigPropertyEditorformat The file is created by usingProperties.store(Writer,String)with a writer that uses the UTF-8 character set with CRLF line separators.store(OutputStream os) Store this object given an output stream, using theConfigPropertyEditorformat.byte[]storeBytes(boolean gzip) Store this object as a byte array.
-
Constructor Details
-
ConfigProperties
Constructor.- Parameters:
mediaType- the media (MIME) type
-
ConfigProperties
Constructor given a file. Media types are encoded in the first line of the file, which is expected to be
where MEDIATYPE is the media (or MIME type) as defined in RFC 2045 and subsequent RFCs. The mediatype is converted to lower case for testing.#(!M.T MEDIATYPE)- Parameters:
f- the file to loadmediaType- the media (MIME) type- Throws:
IOException- if an IO error occurred
-
ConfigProperties
Constructor given an input stream. Media types are encoded in the first line of the file, which is expected to be
where MEDIATYPE is the media (or MIME type) as defined in RFC 2045 and subsequent RFCs. The mediatype is converted to lower case for testing.#(!M.T MEDIATYPE)- Parameters:
is- the input streammediaType- the media (MIME) type- Throws:
IOException- if an IO error occurred
-
ConfigProperties
Constructor given a string containing Base64-encoded GZIPedConfigPropertiesfile. Media types are encoded in the first line of the file, which is expected to be
where MEDIATYPE is the media (or MIME type) as defined in RFC 2045 and subsequent RFCs. The mediatype is converted to lower case for testing.#(!M.T MEDIATYPE)- Parameters:
b64data- a Base-64 encoded string representing this object.mediaType- the media (MIME) type- Throws:
IOException- if the media type does not match that of the Base-64 encoded representation
-
-
Method Details
-
getKeys
Get the current property names.- Returns:
- the property names
-
getDecryptedProperty
Get the value, decrypted if necessary, stored in this object under a given key.- Parameters:
key- the keypassphrase- the GPG passphrase for decryption.- Returns:
- the decrypted value
- Throws:
GeneralSecurityException- if decryption failed
-
getDecryptedProperty
public char[] getDecryptedProperty(String key, char[] passphrase, String gpgdir) throws GeneralSecurityException Get the value, decrypted if necessary, stored this object under a given key and a GPG home directory. The GPG home directory is the argument for the GPG --homedir command-line option. When gpgdir is non-null, a GPG TOFU (Trust On First Use) trust model is used.- Parameters:
key- the keypassphrase- the GPG passphrase for decryptiongpgdir- the GPG 'home' directory to use- Returns:
- the decrypted value
- Throws:
GeneralSecurityException- if decryption failed
-
getProperty
Get the value stored in this object under a given key. Values whose keys start with "base64." are decoded using a Base-64 decoder. Otherwise, the sequence "$(KEY)", where KEY is some key, is replaced with the value stored for KEY in the value provided for the given key.If an error occurs due to a key recursively referencing itself, the method
ConfigPropUtilities.getCyclicKeys()can be used to help find the cycle provided that method is called immediately after the exception is thrown.- Parameters:
key- the key- Returns:
- the value for the given key; null if the key does not exist
- Throws:
IllegalStateException- if a key is part of a cyclic reference
-
getProperty
Get the value stored in this object under a given key, optionally providing a literal value.This method is provided primarily for use with
setProperty(java.lang.String,java.lang.String,boolean), and is useful when properties have to be copied "as is" between two instances of this class.- Parameters:
key- the keyliteral- true if value of the property should be returned as is; false for the behavior specified bygetProperty(String)- Returns:
- the value for the given key; null if the key does not exist
-
setProperty
Set a property. When decoded, each '$$' will be replaced with a single '$' and substrings of the form "$(KEY)" will be replaced with the value for the specified KEY, unless the key starts with "base64.", in which case the value will be base-64 encoded. for storage.- Parameters:
key- the property keyvalue- the property value- Throws:
IllegalArgumentException- if the key starts with "ebase64."- See Also:
-
setProperty
public ConfigProperties setProperty(String key, String value, boolean literal) throws IllegalArgumentException Set a property for an instance ofProperties. When the argumentliteralis false, a '$' must be escaped by replacing it with the pair "$$", and substrings of the form "$(KEY)" are replaced with the value of KEY. A check for circularity is not performed at this point. Each "$" in the value will be replaced with "$$" because ofConfigPropertyEditorconventions, unless the key starts with "base64.", in which case the value will be Base-64 encoded.- Parameters:
key- the property keyvalue- the property valueliteral- true if the value is a literal string; false if variable substitution is allowed- Throws:
IllegalArgumentException- if the key starts with "ebase64."- See Also:
-
getRecipients
Get GPG recipients that were stored using the specified key.- Parameters:
key- the property key- Returns:
- the recipients
- Throws:
IllegalStateException- if the object stored using the specified key cannot be decoded
-
setRecipients
Set GPG recipients that were stored using the specified key.- Parameters:
key- the property keyrecipients- the recipients- Returns:
- this object
-
setProperty
public ConfigProperties setProperty(String key, String value, char[] password) throws IllegalArgumentException Set a property for this object when symmetric* encryption is used.Note: When a
ConfigPropertyEditoris used, either all encrypted entries should use either symmetric encryption or public key encryption, but these should not be mixed. All encrypted entries should use the same password or passphrase.- Parameters:
key- the property keyvalue- the property valuepassword- the password for symmetric encryption- Returns:
- this object
- Throws:
IllegalArgumentException- if the password is null or empty- See Also:
-
setProperty
public ConfigProperties setProperty(String key, char[] value, char[] password) throws IllegalArgumentException Set a property for this object when symmetric* encryption is used and the value is a char array.Note: When a
ConfigPropertyEditoris used, either all encrypted entries should use either symmetric encryption or public key encryption, but these should not be mixed. All encrypted entries should use the same password or passphrase.- Parameters:
key- the property keyvalue- the property valuepassword- the password for symmetric encryption- Returns:
- this object
- Throws:
IllegalArgumentException- if the password is null or empty- See Also:
-
setProperty
Set a property for this object when GPG encryption is used. The recipient's list must contain strings that GPG can use to look up a public key.Note: When a
ConfigPropertyEditoris used, either all encrypted entries should use either symmetric encryption or public key encryption, but these should not be mixed. All encrypted entries should use the same password or passphrase.When gpgdir is non-null, a GPG TOFU (Trust On First Use) trust model is used.
- Parameters:
key- the property keyvalue- the property valuegpgdir- The GPG home directory used to store public an private keys; null for the defaultrecipients- the recipients- Throws:
IllegalArgumentException- if there are no recipients or if the key does not start with "ebase64"- See Also:
-
setProperty
Set a property for this object when GPG encryption is used and the value of the property is a char array. The recipient's list must contain strings that GPG can use to look up a public key.Note: When a
ConfigPropertyEditoris used, either all encrypted entries should use either symmetric encryption or public key encryption, but these should not be mixed. All encrypted entries should use the same password or passphrase.When gpgdir is non-null, a GPG TOFU (Trust On First Use) trust model is used.
- Parameters:
key- the property keyvalue- the property valuegpgdir- The GPG home directory used to store public an private keys; null for the defaultrecipients- the recipients- Throws:
IllegalArgumentException- if there are no recipients or if the key does not start with "ebase64"- See Also:
-
store
Store this object, given an output file, using theConfigPropertyEditorformat The file is created by usingProperties.store(Writer,String)with a writer that uses the UTF-8 character set with CRLF line separators. The file will start with a comment "#(!M.T " MEDIATYPE)" where MEDIATYPE is the media type in lower case.- Parameters:
file- the file- Throws:
IOException- if an IO error occurred
-
store
Store this object given an output stream, using theConfigPropertyEditorformat. The output is created by usingProperties.store(Writer,String)with a writer that uses the UTF-8 character set with CRLF line separators. The output will start with a comment "#(!M.T " MEDIATYPE)" where MEDIATYPE is the media type in lower case.- Parameters:
os- the output stream- Throws:
IOException- if an IO error occurred
-
store
Store this object as a Base-64 encoded string. A byte array is produced by in effect first creating a text file using the UTF-8 charset and with a CRLF sequence terminating each line, optionally compressing that file. The text-file format is that produced byProperties.store(Writer,String). This byte array is finally base-64 encoded and turned into a string using the UTF-8 character set. The properties file will start with a comment "#(!M.T " MEDIATYPE)" where MEDIATYPE is the media type in lower case.- Returns:
- the Base-64 encoded string.
-
storeBytes
public byte[] storeBytes(boolean gzip) Store this object as a byte array. The byte array is produced by in effect first creating a text file using the UTF-8 charset and with a CRLF sequence terminating each line, optionally compressing that file. The text-file format is that produced byProperties.store(Writer,String). The properties file will start with a comment "#(!M.T " MEDIATYPE)" where MEDIATYPE is the media type in lower case.- Parameters:
gzip- true if the result is compressed using GZIP- Returns:
- an array of bytes containing the properties
-