|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.novell.io.CharEncoder
A simple character encoder class for use
with the class EncodingStreamWriter
. This exists because
with JDK 1.2, there is no way to intercept unencodable characters
An encoding is implemented by deriving a class from CharEncoder
, and calling
CharEncoder.registerEncoder()
at some point before using the encoder.
This class handles unicode surrogate pairs. Derived classes must also.
This class has been updated to use Java 1.4 and later java.nio.charset.CharSetEncoder for encodings not supported by this package.
Constructor Summary | |
CharEncoder()
|
Method Summary | |
protected static Class |
doGetClass(String className)
Utility method for derived classes to get their Class object
for use with registerEncoder() . |
abstract int |
encodeChar(int c,
byte[] buffer,
int off)
Implementation of character encoding |
int |
encodeChars(char[] chars,
int off,
int len,
byte[] buffer,
int outputIndex)
Encode some number of characters into bytes in a buffer. |
static CharEncoder |
getEncoder(String encoding)
Create an encoder based on the specified encoding string. |
abstract String |
getEncoding()
Return the string identifier for this encoding scheme. |
protected static void |
registerEncoder(String encoding,
Class encoderClass)
Register a CharEncoder -derived class for use with CharEncoder.getEncoder() . |
void |
reset()
Call to reset the encoder before outputting a new stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CharEncoder()
Method Detail |
public static CharEncoder getEncoder(String encoding) throws UnsupportedEncodingException
encoding
- The name of the encoding ("ASCII", "UTF-8", "UTF-16", etc.)
CharEncoder
object for the specified encoding
UnsupportedEncodingException
- If an encoder isn't available for
the specified encoding scheme.public int encodeChars(char[] chars, int off, int len, byte[] buffer, int outputIndex) throws CharEncodingException, EncodingBufferFullException
chars
- The array of characters to convertoff
- The offset into the array of the first character to convertlen
- The number of characters to convertbuffer
- The byte array in which to store the encoded bytesoutputIndex
- The offset into buffer at which to store the encoded bytes
CharEncodingException
- If a character could not be encoded
CharEncoderBufferFull
- If the passed buffer is too small
EncodingBufferFullException
public void reset()
public abstract int encodeChar(int c, byte[] buffer, int off) throws CharEncodingException, EncodingBufferFullException
c
- The 32-bit character value to encodebuffer
- The byte buffer in which to placed encoded bytesoff
- The offset at which to place bytes into the buffer
CharEncodingException
- The character could not be encoded
in the implemented encoding scheme.
EncodingBufferFullException
- There is not enough room in buffer
for all the bytes needed to encode the character.public abstract String getEncoding()
protected static void registerEncoder(String encoding, Class encoderClass)
CharEncoder
-derived class for use with CharEncoder.getEncoder()
.
encoding
- The encoding that the encoder supports ("UTF-8", "ISO-8859-1", etc.)encoderClass
- Class
object for the CharEncoder
-derived class.doGetClass(java.lang.String)
protected static Class doGetClass(String className)
Class
object
for use with registerEncoder()
.
className
- The name of the Class
to return.
Class
object, or null
if the
class is not found.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |