/*
* 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.
*/
/**
* Convert byte arrays containing Unicode characters into arrays of actual
* Unicode characters. This class may be used directly, in which case it
* expects the input byte array to begin with a byte-order mark, or it may be
* subclassed in order to preset the byte order and mark behavior.
*
* <p> Whether or not a mark is expected, if a mark that does not match the
* established byte order is later discovered then a
* <tt>MalformedInputException</tt> will be thrown by the <tt>convert</tt>
* method. If a correct mark is seen later in the input stream, it is passed
* through as a character.
*
* @see ByteToCharUnicodeLittle
* @see ByteToCharUnicodeLittleUnmarked
* @see ByteToCharUnicodeBig
* @see ByteToCharUnicodeBigUnmarked
*
* @author Mark Reinhold
*/
/**
* Creates a Unicode byte-to-char converter that expects the first pair of
* input bytes to be a byte-order mark, which will be interpreted and
* discarded. If the first pair of bytes is not such a mark then a
* <tt>MalformedInputException</tt> will be thrown by the convert method.
*/
public ByteToCharUnicode() {
usesMark = true;
}
/**
* Creates a Unicode byte-to-char converter that uses the given byte order
* and may or may not insist upon an initial byte-order mark.
*/
usesMark = m;
}
switch (originalByteOrder) {
case BIG:
case LITTLE:
default:
return "Unicode";
}
}
boolean started = false;
int leftOverByte;
boolean leftOver = false;
{
return 0;
int bc = 0;
if (leftOver) {
leftOver = false;
}
else {
}
bc = 1;
bc = 2;
if (c == BYTE_ORDER_MARK)
else if (c == REVERSED_MARK)
badInputLength = bc;
throw new
MalformedInputException("Missing byte-order mark");
}
bc = 1;
}
}
inI--;
bc = 1;
}
bc = 1;
}
}
else {
badInputLength = bc;
throw new
MalformedInputException("Incorrect byte-order mark");
}
started = true;
}
}
/* Loop invariant: (b1 contains the next input byte) && (bc == 1) */
bc = 2;
char c;
else
if (c == REVERSED_MARK)
throw new
MalformedInputException("Reversed byte-order mark");
throw new ConversionBufferFullException();
bc = 1;
}
}
if (bc == 1) {
leftOverByte = b1;
leftOver = true;
}
}
public void reset() {
leftOver = false;
started = false;
}
throws MalformedInputException
{
if (leftOver) {
reset();
throw new MalformedInputException();
}
return 0;
}
}