Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.novell.io
Class CharEncoder

    java.lang.Object
      com.novell.io.CharEncoder

Direct Known Subclasses:
  ASCIIEncoder, ISO88591Encoder, ISO8859Encoder, UTF16Encoder, UTF8Encoder

    public abstract class CharEncoder

extends Object

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

### CharEncoder

    public CharEncoder()

Method Detail

### getEncoder

    public static CharEncoder getEncoder(String encoding)
                                  throws UnsupportedEncodingException

  Create an encoder based on the specified encoding string.

  Parameters:
    `encoding` - The name of the encoding ("ASCII", "UTF-8", "UTF-16", etc.)
  Returns:
    A `CharEncoder` object for the specified encoding
  Throws:
    `UnsupportedEncodingException` - If an encoder isn't available for the specified encoding scheme.

### encodeChars

    public int encodeChars(char[] chars,
                           int off,
                           int len,
                           byte[] buffer,
                           int outputIndex)
                    throws CharEncodingException,
                           EncodingBufferFullException

  Encode some number of characters into bytes in a buffer. Derived classes may want to override this for better performance.

  Parameters:
    `chars` - The array of characters to convert
    `off` - The offset into the array of the first character to convert
    `len` - The number of characters to convert
    `buffer` - The byte array in which to store the encoded bytes
    `outputIndex` - The offset into buffer at which to store the encoded bytes
  Returns:
    The number of bytes stored in the buffer
  Throws:
    `CharEncodingException` - If a character could not be encoded
    `CharEncoderBufferFull` - If the passed buffer is too small
    `EncodingBufferFullException`

### reset

    public void reset()

  Call to reset the encoder before outputting a new stream.

### encodeChar

    public abstract int encodeChar(int c,
                                   byte[] buffer,
                                   int off)
                            throws CharEncodingException,
                                   EncodingBufferFullException

  Implementation of character encoding

  Parameters:
    `c` - The 32-bit character value to encode
    `buffer` - The byte buffer in which to placed encoded bytes
    `off` - The offset at which to place bytes into the buffer
  Returns:
    The number of bytes placed in the buffer
  Throws:
    `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.

### getEncoding

    public abstract String getEncoding()

  Return the string identifier for this encoding scheme.

  Returns:
    The string identifier for this encoding scheme.

### registerEncoder

    protected static void registerEncoder(String encoding,
                                          Class encoderClass)

  Register a `CharEncoder`-derived class for use with `CharEncoder.getEncoder()`.

  Parameters:
    `encoding` - The encoding that the encoder supports ("UTF-8", "ISO-8859-1", etc.)
    `encoderClass` - `Class` object for the `CharEncoder`-derived class.
  See Also:
    `doGetClass(java.lang.String)`

### doGetClass

    protected static Class doGetClass(String className)

  Utility method for derived classes to get their `Class` object for use with `registerEncoder()`.

  Parameters:
    `className` - The name of the `Class` to return.
  Returns:
    The `Class` object, or `null` if the class is not found.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD