/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*/
{
private char highHalfZoneCode;
boolean flushed = true;
private static short[] index1;
private int currentState;
public CharToByteGB18030() {
subBytes = new byte[1];
}
throws MalformedInputException
{
if (highHalfZoneCode != 0) {
highHalfZoneCode = 0;
badInputLength = 0;
throw new MalformedInputException();
}
reset();
flushed = true;
return 0;
}
public void reset() {
}
public boolean canConvert(char c) {
// converts all but unpaired surrogates
// and illegal chars, U+FFFE & U+FFFF
if ((c >= 0xd800 && c <=0xdfff) || (c >= 0xfffe))
return false;
else
return true;
}
/**
* Character conversion
*/
{
int linearDiffValue = 0;
char inputChar; // Input character to be converted
int inputSize; // Size of the input
int outputSize; // Size of the output
flushed = false;
if (highHalfZoneCode != 0) {
// This is legal UTF16 sequence, so shunt in the high
// surrogate for conversion by convert() loop.
charOff -= 1;
inOff = 0;
highHalfZoneCode = 0;
} else {
// This is illegal UTF16 sequence.
badInputLength = 0;
throw new MalformedInputException();
}
}
// Main encode loop
// Is this the last character of the input?
break;
}
char previousChar = inputChar;
// Is there a low surrogate following?
inputSize = 2;
charOff++;
} else {
// We have a malformed surrogate pair
badInputLength = 1;
throw new MalformedInputException();
}
}
// Is this an unaccompanied low surrogate?
badInputLength = 1;
throw new MalformedInputException();
}
// Not part of a surrogate
throw new ConversionBufferFullException();
}
}
if (outByteVal == 0xFFFD ) {
if (subMode) {
throw new ConversionBufferFullException();
} else {
continue;
}
} else {
badInputLength = 1;
throw new UnknownCharacterException();
}
}
linearDiffValue += 0x82BD;
else if (inputChar >= 0xF900)
linearDiffValue += 0x93A9;
if (hiByte > 0x80)
else
}
}
else {
badInputLength = 1;
throw new MalformedInputException();
}
if (currentState == GB18030_SINGLE_BYTE)
continue;
if (currentState == GB18030_DOUBLE_BYTE) {
throw new ConversionBufferFullException();
}
}
else { // Four Byte encoding
throw new ConversionBufferFullException();
}
linearDiffValue /= 10;
linearDiffValue /= 126;
}
}
// Return number of bytes written to the output buffer.
}
/**
* returns the maximum number of bytes needed to convert a char
*/
public int getMaxBytesPerChar() {
return 4;
}
/**
* Return the character set ID
*/
return "GB18030";
}
}
}