| java.lang.Object sun.io.CharToByteConverter
All known Subclasses: sun.io.CharToByteDBCS_EBCDIC, sun.io.CharToByteSingleByte, sun.io.CharToByteASCII, sun.io.CharToByteUnicode, sun.io.CharToByteDoubleByte, sun.io.CharToByteEUC_TW, sun.io.CharToByteUTF8, sun.io.CharToByteISO8859_1, sun.io.CharToByteCp949C, sun.io.CharToByteDBCS_ASCII, sun.io.CharToByteCp949, sun.io.CharToByteCp970, sun.io.CharToByteEUC, sun.io.CharToByteISO2022, sun.io.CharToByteCp933,
CharToByteConverter | abstract public class CharToByteConverter (Code) | | An abstract base class for subclasses which convert Unicode
characters into an external encoding.
author: Asmus Freytag author: Lloyd Honomichl, Novell, Inc. |
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. |
Method Summary | |
public boolean | canConvert(char c) Returns true if the given character can be converted to the
target character encoding. | abstract public 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. | public byte[] | convertAll(char input) Converts an array of Unicode characters into an array of bytes
in the target character encoding. | public int | convertAny(char[] input, int inStart, int inEnd, byte[] output, int outStart, int outEnd) | abstract public int | flush(byte[] output, int outStart, int outEnd) Writes any remaining output to the output buffer and resets the
converter to its initial state. | public int | flushAny(byte[] output, int outStart, int outEnd) Writes any remaining output to the output buffer and resets the
converter to its initial state. | public int | getBadInputLength() Returns the length, in chars, of the input which caused a
MalformedInputException. | abstract public String | getCharacterEncoding() Returns the character set id for the conversion. | public static CharToByteConverter | getConverter(String encoding) Returns appropriate CharToByteConverter subclass instance. | public static CharToByteConverter | getDefault() Create an instance of the default CharToByteConverter subclass. | abstract public int | getMaxBytesPerChar() Returns the maximum number of bytes needed to convert a char. | public int | nextByteIndex() Returns the index of the byte just past the last byte written by
the previous call to convert. | public int | nextCharIndex() Returns the index of the character just past
the last character successfully converted by the previous call
to convert. | abstract public void | reset() Resets converter to its initial state. | public void | setSubstitutionBytes(byte[] newSubBytes) Sets the substitution bytes to use when the converter is in
substitution mode. | public void | setSubstitutionMode(boolean doSub) Sets converter into substitution mode. | public String | toString() Returns a string representation of the class. |
badInputLength | protected int badInputLength(Code) | | Length of bad input that caused conversion to stop.
|
byteOff | protected int byteOff(Code) | | Offset of next byte to be output.
|
charOff | protected int charOff(Code) | | Offset of next character to be converted.
|
subBytes | protected byte[] subBytes(Code) | | Bytes to substitute for unmappable input.
|
subMode | protected boolean subMode(Code) | | Substitution mode flag.
|
canConvert | public boolean canConvert(char c)(Code) | | Returns true if the given character can be converted to the
target character encoding.
true if given character is translatable, false otherwise. Parameters: c - character to test |
convert | abstract public int convert(char[] input, int inStart, int inEnd, byte[] output, int outStart, int outEnd) throws MalformedInputException, UnknownCharacterException, ConversionBufferFullException(Code) | | Converts an array of Unicode characters into an array of bytes
in the target character encoding. This method allows a buffer by
buffer conversion of a data stream. The state of the conversion is
saved between calls to convert. If a call to convert results in
an exception, the conversion may be continued by calling convert again
with suitably modified parameters. All conversions should be finished
with a call to the flush method.
the number of bytes written to output. Parameters: input - array containing Unicode characters to be converted. Parameters: inStart - begin conversion at this offset in input array. Parameters: inEnd - stop conversion at this offset in input array (exclusive). Parameters: output - byte array to receive conversion result. Parameters: outStart - start writing to output array at this offset. Parameters: outEnd - stop writing to output array at this offset (exclusive). exception: MalformedInputException - if the input buffer contains anysequence of chars that is illegal in Unicode (principally unpairedsurrogates and \uFFFF or \uFFFE). After this exception is thrown,the method nextCharIndex can be called to obtain the index of thefirst invalid input character. The MalformedInputException canbe queried for the length of the invalid input. exception: UnknownCharacterException - for any character thatthat cannot be converted to the external character encoding. Thrownonly when converter is not in substitution mode. exception: ConversionBufferFullException - if output array is filled priorto converting all the input. |
convertAll | public byte[] convertAll(char input) throws MalformedInputException(Code) | | Converts an array of Unicode characters into an array of bytes
in the target character encoding. Unlike convert, this method
does not do incremental conversion. It assumes that the given
input array contains all the characters to be converted. The
state of the converter is reset at the beginning of this method
and is left in the reset state on successful termination.
The converter is not reset if an exception is thrown.
This allows the caller to determine where the bad input
was encountered by calling nextCharIndex.
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.
an array of bytes containing the converted characters. Parameters: input - array containing Unicode characters to be converted. exception: MalformedInputException - if the input buffer contains anysequence of chars that is illegal in Unicode (principally unpairedsurrogates and \uFFFF or \uFFFE). After this exception is thrown,the method nextCharIndex can be called to obtain the index of thefirst invalid input character and getBadInputLength can be calledto determine the length of the invalid input. See Also: CharToByteConverter.nextCharIndex See Also: CharToByteConverter.setSubstitutionMode See Also: CharToByteConverter.setSubstitutionBytes See Also: CharToByteConverter.getBadInputLength |
flush | abstract public int flush(byte[] output, int outStart, int outEnd) throws MalformedInputException, ConversionBufferFullException(Code) | | Writes any remaining output to the output buffer and resets the
converter to its initial state.
Parameters: output - byte array to receive flushed output. Parameters: outStart - start writing to output array at this offset. Parameters: outEnd - stop writing to output array at this offset (exclusive). exception: MalformedInputException - if the output to be flushed containeda partial or invalid multibyte character sequence. Will occur if theinput buffer on the last call to convert ended with the first characterof a surrogate pair. flush will write what it can to the output bufferand reset the converter before throwing this exception. An additionalcall to flush is not required. exception: ConversionBufferFullException - if output array is filled before all the output can be flushed. flush will write what it canto the output buffer and remember its state. An additional call toflush with a new output buffer will conclude the operation. |
flushAny | public int flushAny(byte[] output, int outStart, int outEnd) throws ConversionBufferFullException(Code) | | Writes any remaining output to the output buffer and resets the
converter to its initial state. May only be called when substitution
mode is turned on, and never complains about malformed input (always
substitutes).
Parameters: output - byte array to receive flushed output. Parameters: outStart - start writing to output array at this offset. Parameters: outEnd - stop writing to output array at this offset (exclusive). number of bytes writter into output. exception: ConversionBufferFullException - if output array is filled before all the output can be flushed. flush will write what it canto the output buffer and remember its state. An additional call toflush with a new output buffer will conclude the operation. |
getBadInputLength | public int getBadInputLength()(Code) | | Returns the length, in chars, of the input which caused a
MalformedInputException. Always refers to the last
MalformedInputException thrown by the converter. If none have
ever been thrown, returns 0.
|
getCharacterEncoding | abstract public String getCharacterEncoding()(Code) | | Returns the character set id for the conversion.
|
getDefault | public static CharToByteConverter getDefault()(Code) | | Create an instance of the default CharToByteConverter subclass.
|
getMaxBytesPerChar | abstract public int getMaxBytesPerChar()(Code) | | Returns the maximum number of bytes needed to convert a char. Useful
for calculating the maximum output buffer size needed for a particular
input buffer.
|
nextByteIndex | public int nextByteIndex()(Code) | | Returns the index of the byte just past the last byte written by
the previous call to convert.
|
nextCharIndex | public int nextCharIndex()(Code) | | Returns the index of the character just past
the last character successfully converted by the previous call
to convert.
|
reset | abstract public void reset()(Code) | | Resets converter to its initial state.
|
setSubstitutionMode | public void setSubstitutionMode(boolean doSub)(Code) | | Sets converter into substitution mode. In substitution mode,
the converter will replace untranslatable characters in the source
encoding with the substitution character set by setSubstitutionBytes.
When not in substitution mode, the converter will throw an
UnknownCharacterException when it encounters untranslatable input.
Parameters: doSub - if true, enable substitution mode. See Also: CharToByteConverter.setSubstitutionBytes |
toString | public String toString()(Code) | | Returns a string representation of the class.
|
|
|