org.joe_e.charset
Class UTF8

java.lang.Object
  extended by org.joe_e.charset.UTF8

public final class UTF8
extends Object

UTF-8 I/O.


Method Summary
static String decode(byte[] buffer)
          Decodes a UTF-8 string.
static String decode(byte[] buffer, int off, int len)
          Decodes a UTF-8 string.
static byte[] encode(String text)
          Encodes a string in UTF-8.
static Reader input(InputStream in)
          Constructs a UTF-8 reader.
static Writer output(OutputStream out)
          Constructs a UTF-8 writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static byte[] encode(String text)
Encodes a string in UTF-8.

Parameters:
text - The text to encode.
Returns:
The UTF-8 bytes.

decode

public static String decode(byte[] buffer)
Decodes a UTF-8 string. Each byte not corresponding to a UTF-8 character decodes to the Unicode replacement character U+FFFD. Note that an initial byte-order mark is not stripped. This method is equivalent to decode(buffer, 0, buffer.length).

Parameters:
buffer - the ASCII-encoded string to decode
Returns:
The corresponding string
Throws:
IndexOutOfBoundsException

decode

public static String decode(byte[] buffer,
                            int off,
                            int len)
Decodes a UTF-8 string. Each byte not corresponding to a UTF-8 character decodes to the Unicode replacement character U+FFFD. Note that an initial byte-order mark is not stripped.

Parameters:
buffer - the ASCII-encoded string to decode
off - where to start decoding
len - how many bytes to decode
Returns:
The corresponding string
Throws:
IndexOutOfBoundsException

input

public static Reader input(InputStream in)
Constructs a UTF-8 reader.

Parameters:
in - The binary input stream.

output

public static Writer output(OutputStream out)
Constructs a UTF-8 writer.

Parameters:
out - The binary output stream.