Package org.rypt.f8
Class Utf8Statistics
- java.lang.Object
-
- java.io.OutputStream
-
- org.rypt.f8.Utf8Statistics
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Utf8ByteHandler<RuntimeException>,Utf8Handler<RuntimeException>
- Direct Known Subclasses:
Utf8StringBuilder
public class Utf8Statistics extends OutputStream implements Utf8Handler<RuntimeException>
An implementation ofUtf8Handlerthat records statistics for valid and invalid UTF-8 byte sequences- Author:
- Hans Brende (hansbrende@apache.org)
-
-
Field Summary
-
Fields inherited from interface org.rypt.f8.Utf8ByteHandler
END_OF_STREAM
-
-
Constructor Summary
Constructors Constructor Description Utf8Statistics()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()longcount2Byte()longcount3Byte()longcount4Byte()longcountAscii()longcountCodePoints()longcountInvalid()longcountInvalidIgnoringTruncation()longcountValid()Deprecated.voidhandle1ByteCodePoint(int ascii)Called when a valid 1-byte sequence is encountered.voidhandle2ByteCodePoint(int b1, int b2)Called when a valid 2-byte sequence is encountered.voidhandle3ByteCodePoint(int b1, int b2, int b3)Called when a valid 3-byte sequence is encountered.voidhandle4ByteCodePoint(int b1, int b2, int b3, int b4)Called when a valid 4-byte sequence is encountered.voidhandleCodePoint(int codePoint)Called when a valid unicode code point is encounteredvoidhandleContinuationError(int b1, int nextByte)Called when an invalid continuation byte is encountered in a 2, 3, or 4-byte sequence.voidhandleContinuationError(int b1, int b2, int nextByte)Called when an invalid continuation byte is encountered in a 3 or 4-byte sequence.voidhandleContinuationError(int b1, int b2, int b3, int nextByte)Called when an invalid continuation byte is encountered in a 4-byte sequence.voidhandleError()Called when an invalid UTF-8 byte sequence is detectedbooleanlooksLikeUtf8()voidreset()StringtoString()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.rypt.f8.Utf8ByteHandler
handleIgnoredByte
-
Methods inherited from interface org.rypt.f8.Utf8Handler
handlePrefixError
-
-
-
-
Method Detail
-
reset
public void reset()
-
write
public void write(int b)
- Specified by:
writein classOutputStream
-
write
public void write(byte[] b, int off, int len)- Overrides:
writein classOutputStream
-
write
public void write(byte[] b)
- Overrides:
writein classOutputStream
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
handleError
public void handleError()
Description copied from interface:Utf8HandlerCalled when an invalid UTF-8 byte sequence is detected- Specified by:
handleErrorin interfaceUtf8Handler<RuntimeException>
-
handleContinuationError
public void handleContinuationError(int b1, int b2, int b3, int nextByte)Description copied from interface:Utf8ByteHandlerCalled when an invalid continuation byte is encountered in a 4-byte sequence.- Specified by:
handleContinuationErrorin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handleContinuationErrorin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix byteb2- the first continuation byteb3- the second continuation bytenextByte- the invalid third continuation byte, orUtf8ByteHandler.END_OF_STREAMto indicate the end of the byte stream
-
handleContinuationError
public void handleContinuationError(int b1, int b2, int nextByte)Description copied from interface:Utf8ByteHandlerCalled when an invalid continuation byte is encountered in a 3 or 4-byte sequence.- Specified by:
handleContinuationErrorin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handleContinuationErrorin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix byteb2- the first continuation bytenextByte- the invalid second continuation byte, orUtf8ByteHandler.END_OF_STREAMto indicate the end of the byte stream
-
handleContinuationError
public void handleContinuationError(int b1, int nextByte)Description copied from interface:Utf8ByteHandlerCalled when an invalid continuation byte is encountered in a 2, 3, or 4-byte sequence.- Specified by:
handleContinuationErrorin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handleContinuationErrorin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix bytenextByte- the invalid first continuation byte, orUtf8ByteHandler.END_OF_STREAMto indicate the end of the byte stream
-
handleCodePoint
public void handleCodePoint(int codePoint)
Description copied from interface:Utf8HandlerCalled when a valid unicode code point is encountered- Specified by:
handleCodePointin interfaceUtf8Handler<RuntimeException>- Parameters:
codePoint- the code point that was encountered
-
handle1ByteCodePoint
public void handle1ByteCodePoint(int ascii)
Description copied from interface:Utf8ByteHandlerCalled when a valid 1-byte sequence is encountered.- Specified by:
handle1ByteCodePointin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handle1ByteCodePointin interfaceUtf8Handler<RuntimeException>- Parameters:
ascii- the valid ASCII character encountered, in the range 0-0x7F
-
handle2ByteCodePoint
public void handle2ByteCodePoint(int b1, int b2)Description copied from interface:Utf8ByteHandlerCalled when a valid 2-byte sequence is encountered.- Specified by:
handle2ByteCodePointin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handle2ByteCodePointin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix byte, in the range (byte)0xC2-(byte)0xDFb2- the continuation byte, in the range (byte)0x80-(byte)0xBF- See Also:
Utf8.codePoint(int, int)
-
handle3ByteCodePoint
public void handle3ByteCodePoint(int b1, int b2, int b3)Description copied from interface:Utf8ByteHandlerCalled when a valid 3-byte sequence is encountered.- Specified by:
handle3ByteCodePointin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handle3ByteCodePointin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix byte, in the range (byte)0xE0-(byte)0xEFb2- the first continuation byte, in the range (byte)0x80-(byte)0xBF, unless the prefix byte is (byte)0xED or (byte)0xE0, in which case the range is (byte)0x80-(byte)0x9F or (byte)0xA0-(byte)0xBF, respectivelyb3- the second continuation byte, in the range (byte)0x80-(byte)0xBF- See Also:
Utf8.codePoint(int, int, int)
-
handle4ByteCodePoint
public void handle4ByteCodePoint(int b1, int b2, int b3, int b4)Description copied from interface:Utf8ByteHandlerCalled when a valid 4-byte sequence is encountered.- Specified by:
handle4ByteCodePointin interfaceUtf8ByteHandler<RuntimeException>- Specified by:
handle4ByteCodePointin interfaceUtf8Handler<RuntimeException>- Parameters:
b1- the prefix byte, in the range (byte)0xF0-(byte)0xF4b2- the first continuation byte, in the range (byte)0x80-(byte)0xBF, unless the prefix byte is (byte)0xF4 or (byte)0xF0, in which case the range is (byte)0x80-(byte)0x8F or (byte)0x90-(byte)0x9F, respectivelyb3- the second continuation byte, in the range (byte)0x80-(byte)0xBFb4- the third continuation byte, in the range (byte)0x80-(byte)0xBF- See Also:
Utf8.codePoint(int, int, int, int)
-
countCodePoints
public long countCodePoints()
- Returns:
- the total number of valid UTF-8 code points encountered
-
countValid
@Deprecated public long countValid()
Deprecated.- Returns:
- the number of valid UTF-8 multi-byte sequences encountered
-
countInvalid
public long countInvalid()
- Returns:
- the number of invalid UTF-8 byte sequences encountered
-
countInvalidIgnoringTruncation
public long countInvalidIgnoringTruncation()
- Returns:
- the number of invalid UTF-8 byte sequences encountered, ignoring a final invalid byte sequence that could have been valid given more bytes
-
countAscii
public long countAscii()
- Returns:
- the number of bytes encountered with a leading 0-bit (i.e., those in the range 0-0x7F)
-
count2Byte
public long count2Byte()
- Returns:
- the number of 2-byte UTF-8 characters encountered (i.e., those in the range 0x80-0x7FF)
-
count3Byte
public long count3Byte()
- Returns:
- the number of 3-byte UTF-8 characters encountered (i.e., those in the range 0x800-0xFFFF)
-
count4Byte
public long count4Byte()
- Returns:
- the number of 4-byte UTF-8 characters encountered (i.e., those in the range 0x10000-0x10FFFF)
-
looksLikeUtf8
public boolean looksLikeUtf8()
- Returns:
- true if the encountered byte sequence looks like UTF-8 (and not plain ASCII)
-
-