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 3629.
RFC 2279, RFC 3629 give an algorithm for transforming UCS multi octet characters into UTF-8 octet sequences. This class can be used for UTF-8 encoding 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
,
ASN
value
asnType, 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 char[] |
getCharsFromUTF8Encoding(byte[] enc)
Decodes an UTF-8 encoded byte array and returns the result as char array.
|
static char[] |
getCharsFromUTF8Encoding(byte[] enc,
boolean skipInvalidCharacters)
Decodes an UTF-8 encoded byte array and returns the result as char array.
|
static java.lang.String |
getRFC2253String(char[] str)
Returns a UTF-8 String representation according to RFC 2253.
|
static java.lang.String |
getRFC2253String(char[] str,
boolean strictEscaping)
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 str,
boolean strictEscaping)
Returns a UTF-8 String representation according to RFC 2253.
|
static java.lang.String |
getStringFromUTF8Encoding(byte[] enc)
Decodes an UTF-8 encoded byte array and returns the result as string.
|
static java.lang.String |
getStringFromUTF8Encoding(byte[] enc,
boolean skipInvalidCharacters)
Decodes an UTF-8 encoded byte array and returns the result as string.
|
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.
|
static void |
setSkipInvalidEncodedUTF8Characters(boolean skip)
Decides whether to skip invalid encoded characters when
decoding an UTF-8 encoded byte array to a String (default:
false ; invalid UTF-8 encoded characters cause a
CodingException). |
void |
setValue(java.lang.Object object)
Sets the value of this UTF8String.
|
clone, decode, encode, equals, getByteValue, hashCode, setIgnoreConstructedEncodingForSimpleTypes, setIndefiniteLength, toString
addComponent, addEncodeListener, countComponents, encodeObject, getAsnType, getComponentAt, indefiniteLength, isA, isConstructed, isStringType
protected UTF8String()
public UTF8String(java.lang.String value)
value
- the String value this UTF8String object should be initialized withpublic static void setSkipInvalidEncodedUTF8Characters(boolean skip)
decoding
an UTF-8 encoded byte array to a String (default:
false
; invalid UTF-8 encoded characters cause a
CodingException). skip
- whether to skip invalid encoded characters when
decoding
an UTF-8 encoded String (default:
false
; invalid UTF-8 encoded characters cause a
CodingException).public java.lang.Object getValue()
getValue
in class ASN1Object
public void setValue(java.lang.Object object)
The supplied value has to be a Java object of type String
.
setValue
in class ASN1Object
object
- 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 char[] getCharsFromUTF8Encoding(byte[] enc) throws CodingException
enc
- the UTF-8 encoding as byte arrayCodingException
- if an error occurs during the decoding processpublic static char[] getCharsFromUTF8Encoding(byte[] enc, boolean skipInvalidCharacters) throws CodingException
enc
- the UTF-8 encoding as byte arrayskipInvalidCharacters
- whether to skip invalid encoded characters (default:
false
; invalid characters
cause a CodingException)CodingException
- if an error occurs during the decoding processpublic 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 getStringFromUTF8Encoding(byte[] enc, boolean skipInvalidCharacters) throws CodingException
enc
- the UTF-8 encoding as byte arrayskipInvalidCharacters
- whether to skip invalid encoded characters (default:
false; invalid characters
cause a CodingException)
CodingException
- 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. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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(java.lang.String str, boolean strictEscaping) throws CodingException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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:
strictEscaping
is set to true
str
- the string to be representedstrictEscaping
- whether to escape non printable ASCII (< 0x21 or > 0x7e) and
non-ASCII characters by an hexadecimal representation of their
UTF-8 encodingCodingException
- 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. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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(char[] str, boolean strictEscaping) throws CodingException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups. This implementation is also compliant with the updated standard RFC 4514, which obsoleted RFC 2253.
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:
strictEscaping
is set to true
str
- the char array to be representedstrictEscaping
- whether to escape non printable ASCII (< 0x21 or > 0x7e) and
non-ASCII characters by an hexadecimal representation of their
UTF-8 encodingCodingException
- if an coding error occurs