public class UTF8String extends ASN1String
UTF-8 (UCS transformation format 8) is an encoding format that has been developed for handling UCS-2/UCS-4 multi-octet character sets by applications that operate on 7, 8 bit characters. UTF-8 is specified by ISO 10646 in RFC 2279.
RFC 2279 gives an algorithm for transforming UCS-4/UCS-2 multi octet characters into UTF-8 octet sequences. This class can be used for UTF-8 encoding UCS-2/Unicode character strings according to the following rules:
When creating a new UTF8String object the value to be represented
has to be supplied as Java String type:
String s = ...; UTF8String UTF8String = new UTF8String(s);When calling the
getValue method for getting the inherent string
value from an ASN.1 UTF8String instance, a Java object of type String
is returned:
String s = (String)UTF8String.getValue();DER en/decoding generally is done by means of the several methods of the
DerCoder class; decoding alternatively may be performed by
using the DerInputStream utility.ASN1Object,
ASNvalueasnType, constructed, encode_listener, indefinite_length, isStringType, stream_mode| Modifier | Constructor and Description |
|---|---|
protected |
UTF8String()
Creates an empty UTF8String.
|
|
UTF8String(java.lang.String value)
Creates a new ASN.1 UTF8String object for the given String value.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getRFC2253String(char[] str)
Returns a UTF-8 String representation according to RFC 2253.
|
static java.lang.String |
getRFC2253String(java.lang.String str)
Returns a UTF-8 String representation according to RFC 2253.
|
static java.lang.String |
getRFC2253String(java.lang.String input,
boolean escapeNonPrintableAndNonAscii)
Returns a RFC 2253 representation of a string.
|
static java.lang.String |
getStringFromUTF8Encoding(byte[] enc)
Decodes the string from an UTF-8 encoded byte array.
|
static byte[] |
getUTF8EncodingFromCharArray(char[] str)
UTF-8 encodes the given char array.
|
static byte[] |
getUTF8EncodingFromString(java.lang.String str)
UTF-8 encodes the given string.
|
java.lang.Object |
getValue()
Returns the value of this UTF8String as a String object.
|
void |
setValue(java.lang.Object object)
Sets the value of this UTF8String.
|
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType, setAutomaticRepair, setAutomaticRepairRecursive, setIndefiniteLength, setIndefiniteRecursiveprotected UTF8String()
public UTF8String(java.lang.String value)
value - the String value this UTF8String object should be initialized withpublic java.lang.Object getValue()
getValue in class ASN1Objectpublic void setValue(java.lang.Object object)
The supplied value has to be a Java object of type String.
setValue in class ASN1Objectobject - the Java String value to be set for this UTF8Stringpublic static byte[] getUTF8EncodingFromString(java.lang.String str)
throws CodingException
str - the string to be encodedCodingException - if an coding error occurspublic static byte[] getUTF8EncodingFromCharArray(char[] str)
throws CodingException
str - the char array to be encodedCodingException - if an coding error occurspublic static java.lang.String getStringFromUTF8Encoding(byte[] enc)
throws CodingException
enc - the UTF-8 encoding as byte arrayCodingException - if an error occurs during the decoding processpublic static java.lang.String getRFC2253String(java.lang.String str)
throws CodingException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups.
The string representation returned by this method is based on the algorithm given in section 2.4 of RFC 2253 thereby applying the following escaping mechanisms:
str - the string to be representedCodingException - if an coding error occurspublic static java.lang.String getRFC2253String(char[] str)
throws CodingException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups.
The string representation returned by this method is based on the algorithm given in section 2.4 of RFC 2253 thereby applying the following escaping mechanisms:
str - the char array to be representedCodingException - if an coding error occurspublic static java.lang.String getRFC2253String(java.lang.String input,
boolean escapeNonPrintableAndNonAscii)
input - a stringescapeNonPrintableAndNonAscii - indicates whether or not every non-printable character and
non-ASCII character should be represented in escaped format