bytesSkipped++;
} else if ((c & 0x60) == 0x40) { // 7th bit set, 6th bit unset
// Found char of two byte width.
if (skipPersistent(in, 1L) != 1L) {
// No second byte present.
throw new UTFDataFormatException(
"Second byte in two byte character missing; byte pos " +
bytesSkipped + " ; char pos " + charsSkipped);
}
bytesSkipped += 2;
} else if ((c & 0x70) == 0x60) { // 7th and 6th bit set, 5th unset
// Found char of three byte width.
int skipped = 0;
if (c == 0xe0) {
// Check for Derby EOF marker.
int c1 = in.read();
int c2 = in.read();
if (c1 == 0x00 && c2 == 0x00) {
// Found Derby EOF marker, exit loop.
charsSkipped--; // Compensate by subtracting one.
break;
}
// Do some rudimentary error checking.
// Allow everything except EOF, which is the same as done in
// normal processing (skipPersistent below).
if (c1 != -1 && c2 != -1) {
skipped = 2;
}
} else {
skipped = (int)skipPersistent(in, 2L);
}
if (skipped != 2) {
// No second or third byte present
throw new UTFDataFormatException(
"Second or third byte in three byte character " +
"missing; byte pos " + bytesSkipped + " ; char pos " +
charsSkipped);
}
bytesSkipped += 3;
} else {
throw new UTFDataFormatException(
"Invalid UTF-8 encoding encountered: (decimal) " + c);
}
}
// We don't close the stream, since it might be reused. One example of
// this is use of Resetable streams.