sun.io
Class CharToByteISO8859_1

java.lang.Object
  extended by sun.io.CharToByteConverter
      extended by sun.io.CharToByteISO8859_1
Direct Known Subclasses:
PPCDefaultFontCharset

public class CharToByteISO8859_1
extends CharToByteConverter


Field Summary
 
Fields inherited from class sun.io.CharToByteConverter
badInputLength, byteOff, charOff, subBytes, subMode
 
Constructor Summary
CharToByteISO8859_1()
           
 
Method Summary
 boolean canConvert(char ch)
          This method is changed to a CNI method for performance purpose.
 int convert(char[] input, int inOff, int inEnd, byte[] output, int outOff, int outEnd)
          Converts an array of Unicode characters into an array of bytes in the target character encoding.
 int flush(byte[] output, int outStart, int outEnd)
          Writes any remaining output to the output buffer and resets the converter to its initial state.
 String getCharacterEncoding()
          Returns the character set id for the conversion.
 int getMaxBytesPerChar()
          returns the maximum number of bytes needed to convert a char
 void reset()
          Resets converter to its initial state.
 
Methods inherited from class sun.io.CharToByteConverter
convertAll, convertAny, flushAny, getBadInputLength, getConverter, getDefault, nextByteIndex, nextCharIndex, setSubstitutionBytes, setSubstitutionMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharToByteISO8859_1

public CharToByteISO8859_1()
Method Detail

getCharacterEncoding

public String getCharacterEncoding()
Description copied from class: CharToByteConverter
Returns the character set id for the conversion.

Specified by:
getCharacterEncoding in class CharToByteConverter

flush

public int flush(byte[] output,
                 int outStart,
                 int outEnd)
          throws MalformedInputException
Description copied from class: CharToByteConverter
Writes any remaining output to the output buffer and resets the converter to its initial state.

Specified by:
flush in class CharToByteConverter
Parameters:
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).
Throws:
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.

convert

public int convert(char[] input,
                   int inOff,
                   int inEnd,
                   byte[] output,
                   int outOff,
                   int outEnd)
            throws MalformedInputException,
                   UnknownCharacterException,
                   ConversionBufferFullException
Description copied from class: CharToByteConverter
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.

Specified by:
convert in class CharToByteConverter
Parameters:
input - array containing Unicode characters to be converted.
inOff - 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.
outOff - start writing to output array at this offset.
outEnd - stop writing to output array at this offset (exclusive).
Returns:
the number of bytes written to output.
Throws:
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.

canConvert

public boolean canConvert(char ch)
This method is changed to a CNI method for performance purpose. public int convert(char[] input, int inOff, int inEnd, byte[] output, int outOff, int outEnd) throws MalformedInputException, UnknownCharacterException, ConversionBufferFullException { char inputChar; // Input character to be converted int outputSize; // Size of output // Record beginning offsets charOff = inOff; byteOff = outOff; if (highHalfZoneCode != 0) { highHalfZoneCode = 0; if (input[inOff] >= 0xdc00 && input[inOff] <= 0xdfff) { // This is legal UTF16 sequence. if (subMode) { outputSize = subBytes.length; if (byteOff + outputSize > outEnd) throw new ConversionBufferFullException(); System.arraycopy(subBytes, 0, output, byteOff, outputSize); byteOff += outputSize; charOff += 1; } else { badInputLength = 1; throw new UnknownCharacterException(); } } else { // This is illegal UTF16 sequence. badInputLength = 0; throw new MalformedInputException ("Previous converted string ends with " + " of UTF16 " + ", but this string is not begin with "); } } // Loop until we hit the end of the input while(charOff < inEnd) { // Get the input character inputChar = input[charOff]; // Is this character mappable? if (inputChar <= '?') { if (byteOff + 1 > outEnd) throw new ConversionBufferFullException(); output[byteOff++] = (byte)inputChar; charOff += 1; } // Is this a high surrogate? else if(inputChar >= '?' && inputChar <= '?') { // Is this the last character in the input? if (charOff + 1 == inEnd) { highHalfZoneCode = inputChar; break; } // Is there a low surrogate following? inputChar = input[charOff + 1]; if (inputChar >= '?' && inputChar <= '?') { // We have a valid surrogate pair. Too bad we don't map // surrogates. Is substitution enabled? if (subMode) { outputSize = subBytes.length; if (byteOff + outputSize > outEnd) throw new ConversionBufferFullException(); System.arraycopy(subBytes, 0, output, byteOff, outputSize); byteOff += outputSize; charOff += 2; } else { badInputLength = 2; throw new UnknownCharacterException(); } } else { // We have a malformed surrogate pair badInputLength = 1; throw new MalformedInputException(); } } // Is this an unaccompanied low surrogate? else if (inputChar >= '?' && inputChar <= '?') { badInputLength = 1; throw new MalformedInputException(); } // Unmappable and not part of a surrogate else { // Is substitution enabled? if (subMode) { outputSize = subBytes.length; if (byteOff + outputSize > outEnd) throw new ConversionBufferFullException(); System.arraycopy(subBytes, 0, output, byteOff, outputSize); byteOff += outputSize; charOff += 1; } else { badInputLength = 1; throw new UnknownCharacterException(); } } } // Return the length written to the output buffer return byteOff-outOff; }

Overrides:
canConvert in class CharToByteConverter
Parameters:
ch - character to test
Returns:
true if given character is translatable, false otherwise.

reset

public void reset()
Description copied from class: CharToByteConverter
Resets converter to its initial state.

Specified by:
reset in class CharToByteConverter

getMaxBytesPerChar

public int getMaxBytesPerChar()
returns the maximum number of bytes needed to convert a char

Specified by:
getMaxBytesPerChar in class CharToByteConverter