net.kano.joscar
Class MinimalEncoder

java.lang.Object
  extended bynet.kano.joscar.MinimalEncoder

public final class MinimalEncoder
extends java.lang.Object

Provides a means of encoding a set of strings in the "smallest" encoding possible. This is useful when a set of data needs to have each member encoded using the same charset, as in DirInfo.


Field Summary
static java.lang.String ENCODING_ASCII
          US-ASCII encoding.
static java.lang.String ENCODING_ISO
          ISO-8859-1 encoding.
static java.lang.String ENCODING_UTF16
          UTF-16BE encoding.
static java.lang.String ENCODING_UTF8
          UTF-8 encoding.
 
Constructor Summary
MinimalEncoder()
           
 
Method Summary
 EncodedStringInfo encode(java.lang.String str)
          Encodes the given string using the minimal encoding computed from previous calls to update.
static EncodedStringInfo encodeMinimally(java.lang.String str)
          Encodes a string minimally.
 java.lang.String getCharset()
          Returns the current minimal charset that can be used to encode all strings that have been passed to update thus far.
 void update(java.lang.String str)
          Updates the current minimum charset to accommodate the given string.
 void updateAll(java.lang.String[] strings)
          Simply a utility method for calling update on an entire array of strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_ASCII

public static final java.lang.String ENCODING_ASCII
US-ASCII encoding.

See Also:
Constant Field Values

ENCODING_ISO

public static final java.lang.String ENCODING_ISO
ISO-8859-1 encoding.

See Also:
Constant Field Values

ENCODING_UTF16

public static final java.lang.String ENCODING_UTF16
UTF-16BE encoding.

See Also:
Constant Field Values

ENCODING_UTF8

public static final java.lang.String ENCODING_UTF8
UTF-8 encoding.

See Also:
Constant Field Values
Constructor Detail

MinimalEncoder

public MinimalEncoder()
Method Detail

encodeMinimally

public static EncodedStringInfo encodeMinimally(java.lang.String str)
Encodes a string minimally. Simply a shortcut for new MinimalEncoder().encode(str).

Parameters:
str - the string to minimally encode
Returns:
an object describing the encoded string and the charset used to encode it

update

public final void update(java.lang.String str)
Updates the current minimum charset to accommodate the given string. For example, if the current minimum charset were ENCODING_ASCII, after calling update(hebrew text) the minimum charset would probably be ENCODING_UTF16.

Parameters:
str - the string to accommodate

updateAll

public final void updateAll(java.lang.String[] strings)
Simply a utility method for calling update on an entire array of strings.

Parameters:
strings - the strings to accommodate

getCharset

public final java.lang.String getCharset()
Returns the current minimal charset that can be used to encode all strings that have been passed to update thus far. Will always be one of ENCODING_ASCII, ENCODING_ISO, ENCODING_UTF16, or in very rare cases (namely, a VM without UTF-16BE encoding) ENCODING_UTF8.

Returns:
the current minimal charset

encode

public final EncodedStringInfo encode(java.lang.String str)
Encodes the given string using the minimal encoding computed from previous calls to update. See getCharset() for details on possible values of the returned EncodedStringInfo's charset field.

Parameters:
str - the string to encode
Returns:
an object describing the encoded string and the charset with which it was encoded