|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectsun.io.CharToByteConverter
public abstract class CharToByteConverter
An abstract base class for subclasses which convert Unicode characters into an external encoding.
| Field Summary | |
|---|---|
protected int |
badInputLength
Length of bad input that caused conversion to stop. |
protected int |
byteOff
Offset of next byte to be output. |
protected int |
charOff
Offset of next character to be converted. |
protected byte[] |
subBytes
Bytes to substitute for unmappable input. |
protected boolean |
subMode
Substitution mode flag. |
| Constructor Summary | |
|---|---|
CharToByteConverter()
|
|
| Method Summary | |
|---|---|
boolean |
canConvert(char c)
Returns true if the given character can be converted to the target character encoding. |
abstract int |
convert(char[] input,
int inStart,
int inEnd,
byte[] output,
int outStart,
int outEnd)
Converts an array of Unicode characters into an array of bytes in the target character encoding. |
byte[] |
convertAll(char[] input)
Converts an array of Unicode characters into an array of bytes in the target character encoding. |
int |
convertAny(char[] input,
int inStart,
int inEnd,
byte[] output,
int outStart,
int outEnd)
|
abstract int |
flush(byte[] output,
int outStart,
int outEnd)
Writes any remaining output to the output buffer and resets the converter to its initial state. |
int |
flushAny(byte[] output,
int outStart,
int outEnd)
Writes any remaining output to the output buffer and resets the converter to its initial state. |
int |
getBadInputLength()
Returns the length, in chars, of the input which caused a MalformedInputException. |
abstract String |
getCharacterEncoding()
Returns the character set id for the conversion. |
static CharToByteConverter |
getConverter(String encoding)
Returns appropriate CharToByteConverter subclass instance. |
static CharToByteConverter |
getDefault()
Create an instance of the default CharToByteConverter subclass. |
abstract int |
getMaxBytesPerChar()
Returns the maximum number of bytes needed to convert a char. |
int |
nextByteIndex()
Returns the index of the byte just past the last byte written by the previous call to convert. |
int |
nextCharIndex()
Returns the index of the character just past the last character successfully converted by the previous call to convert. |
abstract void |
reset()
Resets converter to its initial state. |
void |
setSubstitutionBytes(byte[] newSubBytes)
Sets the substitution bytes to use when the converter is in substitution mode. |
void |
setSubstitutionMode(boolean doSub)
Sets converter into substitution mode. |
String |
toString()
Returns a string representation of the class. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected boolean subMode
protected byte[] subBytes
protected int charOff
protected int byteOff
protected int badInputLength
| Constructor Detail |
|---|
public CharToByteConverter()
| Method Detail |
|---|
public static CharToByteConverter getDefault()
public static CharToByteConverter getConverter(String encoding)
throws UnsupportedEncodingException
string - represets encoding
UnsupportedEncodingExceptionpublic abstract String getCharacterEncoding()
public abstract int convert(char[] input,
int inStart,
int inEnd,
byte[] output,
int outStart,
int outEnd)
throws MalformedInputException,
UnknownCharacterException,
ConversionBufferFullException
input - array containing Unicode characters to be converted.inStart - begin conversion at this offset in input array.inEnd - stop conversion at this offset in input array (exclusive).output - byte array to receive conversion result.outStart - start writing to output array at this offset.outEnd - stop writing to output array at this offset (exclusive).
MalformedInputException - if the input buffer contains any
sequence of chars that is illegal in Unicode (principally unpaired
surrogates and ? or ?). After this exception is thrown,
the method nextCharIndex can be called to obtain the index of the
first invalid input character. The MalformedInputException can
be queried for the length of the invalid input.
UnknownCharacterException - for any character that
that cannot be converted to the external character encoding. Thrown
only when converter is not in substitution mode.
ConversionBufferFullException - if output array is filled prior
to converting all the input.
public int convertAny(char[] input,
int inStart,
int inEnd,
byte[] output,
int outStart,
int outEnd)
throws ConversionBufferFullException
ConversionBufferFullException
public byte[] convertAll(char[] input)
throws MalformedInputException
This method uses substitution mode when performing the conversion. The method setSubstitutionBytes may be used to determine what bytes are substituted. Even though substitution mode is used, the state of the converter's substitution mode is not changed at the end of this method.
input - array containing Unicode characters to be converted.
MalformedInputException - if the input buffer contains any
sequence of chars that is illegal in Unicode (principally unpaired
surrogates and ? or ?). After this exception is thrown,
the method nextCharIndex can be called to obtain the index of the
first invalid input character and getBadInputLength can be called
to determine the length of the invalid input.nextCharIndex(),
setSubstitutionMode(boolean),
setSubstitutionBytes(byte[]),
getBadInputLength()
public abstract int flush(byte[] output,
int outStart,
int outEnd)
throws MalformedInputException,
ConversionBufferFullException
output - byte array to receive flushed output.outStart - start writing to output array at this offset.outEnd - stop writing to output array at this offset (exclusive).
MalformedInputException - if the output to be flushed contained
a partial or invalid multibyte character sequence. Will occur if the
input buffer on the last call to convert ended with the first character
of a surrogate pair. flush will write what it can to the output buffer
and reset the converter before throwing this exception. An additional
call to flush is not required.
ConversionBufferFullException - if output array is filled
before all the output can be flushed. flush will write what it can
to the output buffer and remember its state. An additional call to
flush with a new output buffer will conclude the operation.
public int flushAny(byte[] output,
int outStart,
int outEnd)
throws ConversionBufferFullException
output - byte array to receive flushed output.outStart - start writing to output array at this offset.outEnd - stop writing to output array at this offset (exclusive).
ConversionBufferFullException - if output array is filled
before all the output can be flushed. flush will write what it can
to the output buffer and remember its state. An additional call to
flush with a new output buffer will conclude the operation.public abstract void reset()
public boolean canConvert(char c)
c - character to test
public abstract int getMaxBytesPerChar()
public int getBadInputLength()
public int nextCharIndex()
public int nextByteIndex()
public void setSubstitutionMode(boolean doSub)
doSub - if true, enable substitution mode.setSubstitutionBytes(byte[])
public void setSubstitutionBytes(byte[] newSubBytes)
throws IllegalArgumentException
newSubBytes - the substitution bytes
IllegalArgumentException - if given byte array is longer than
the value returned by the method getMaxBytesPerChar.setSubstitutionMode(boolean),
getMaxBytesPerChar()public String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||