public class Key extends BinaryProperty<KeyType>
Defines a public encryption key.
Code sample (creating)
VCard vcard = new VCard(); //URL Key key = new Key("http://www.mywebsite.com/my-public-key.pgp", KeyType.PGP); vcard.addKey(key); //URI Key key = new Key("OPENPGP4FPR:ABAF11C65A2970B130ABE3C479BE3E4300411886", null); vcard.addKey(key); //binary data byte data[] = ... key = new Key(data, KeyType.PGP); vcard.addKey(key); //plain text value key = new Key(); key.setText("...", KeyType.PGP); vcard.addKey(key);
Code sample (retrieving)
VCard vcard = ... for (Key key : vcard.getKeys()) { KeyType contentType = key.getContentType(); //e.g. "application/pgp-keys" String url = key.getUrl(); if (url != null) { //property value is a URL continue; } byte[] data = key.getData(); if (data != null) { //property value is binary data continue; } String text = key.getText(); if (text != null) { //property value is plain-text continue; } }
Property name: KEY
Supported versions: 2.1, 3.0, 4.0
contentType, data, url
group, parameters
Constructor and Description |
---|
Key()
Creates an empty key property.
|
Key(byte[] data,
KeyType type)
Creates a key property.
|
Key(InputStream in,
KeyType type)
Creates a key property.
|
Key(Key original)
Copy constructor.
|
Key(Path file,
KeyType type)
Creates a key property.
|
Key(String url,
KeyType type)
Creates a key property.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_validate(List<ValidationWarning> warnings,
VCardVersion version,
VCard vcard)
Checks the property for data consistency problems or deviations from the
spec.
|
Key |
copy()
Creates a copy of this property object.
|
boolean |
equals(Object obj) |
String |
getText()
Gets the plain text representation of the key.
|
String |
getUrl()
Gets the URL or URI of the key.
|
int |
hashCode() |
void |
setData(byte[] data,
KeyType type)
Sets the binary data of the resource.
|
void |
setText(String text,
KeyType type)
Sets a plain text representation of the key.
|
void |
setUrl(String url,
KeyType type)
Sets the URL or URI of the key.
|
protected Map<String,Object> |
toStringValues()
Gets string representations of the class's fields for the
VCardProperty.toString() method. |
getAltId, getContentType, getData, getPids, getPref, getType, setAltId, setContentType, setPref, setType
addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, isSupportedBy, removeParameter, setGroup, setParameter, setParameters, toString, validate
public Key()
public Key(byte[] data, KeyType type)
data
- the binary datatype
- the type of key (e.g. PGP)public Key(String url, KeyType type)
url
- the URI or URL to the keytype
- the type of key (e.g. PGP) or null if the type can be
identified from the URIpublic Key(InputStream in, KeyType type) throws IOException
in
- an input stream to the binary data (will be closed)type
- the content type (e.g. PGP)IOException
- if there's a problem reading from the input streampublic Key(Path file, KeyType type) throws IOException
file
- the key filetype
- the content type (e.g. PGP)IOException
- if there's a problem reading from the filepublic void setText(String text, KeyType type)
text
- the key in plain texttype
- the key typepublic String getText()
public void setUrl(String url, KeyType type)
setUrl
in class BinaryProperty<KeyType>
url
- the URL or URI of the keytype
- the type of key (e.g. PGP) or null if the type can be
identified from the URIpublic String getUrl()
getUrl
in class BinaryProperty<KeyType>
public void setData(byte[] data, KeyType type)
BinaryProperty
setData
in class BinaryProperty<KeyType>
data
- the binary datatype
- the content type (e.g. "JPEG image")protected void _validate(List<ValidationWarning> warnings, VCardVersion version, VCard vcard)
VCardProperty
_validate
in class BinaryProperty<KeyType>
warnings
- the list to add the warnings toversion
- the version to check the property againstvcard
- the vCard this property belongs toprotected Map<String,Object> toStringValues()
VCardProperty
Gets string representations of the class's fields for the
VCardProperty.toString()
method.
Meant to be overridden by child classes. The default implementation returns an empty map.
toStringValues
in class BinaryProperty<KeyType>
public Key copy()
VCardProperty
Creates a copy of this property object.
The default implementation of this method uses reflection to look for a copy constructor. Child classes SHOULD override this method to avoid the performance overhead involved in using reflection.
The child class's copy constructor, if present, MUST invoke the
VCardProperty.VCardProperty(VCardProperty)
super constructor to ensure that
the group name and parameters are also copied.
This method MUST be overridden by the child class if the child class does
not have a copy constructor. Otherwise, an
UnsupportedOperationException
will be thrown when an attempt is
made to copy the property (such as in the VCard
class's copy constructor
).
copy
in class VCardProperty
public int hashCode()
hashCode
in class BinaryProperty<KeyType>
public boolean equals(Object obj)
equals
in class BinaryProperty<KeyType>
Copyright © 2012–2023 Michael Angstadt. All rights reserved.