Package org.rypt.f8
Class Utf8
- java.lang.Object
-
- org.rypt.f8.Utf8
-
public class Utf8 extends Object
The core UTF-8 state machine.- Author:
- Hans Brende (hansbrende@apache.org)
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intcodePoint(int b1, int b2)Returns a valid unicode code point given a valid UTF-8 2-byte sequence.static intcodePoint(int b1, int b2, int b3)Returns a valid unicode code point given a valid UTF-8 3-byte sequence.static intcodePoint(int b1, int b2, int b3, int b4)Returns a valid unicode code point given a valid UTF-8 4-byte sequence.static <X extends Exception>
voidfinish(int finalState, Utf8ByteHandler<X> handler)If the final state is incomplete, allows handler to handle final error statestatic booleanisErrorState(int s)Tests if this state corresponds to any invalid UTF-8 byte sequence.static booleanisIncompleteState(int s)Tests if at least one more continuation byte is needed to create a code pointstatic booleanisSurrogatePrefixErrorState(int s)Tests if this state corresponds to an invalid UTF-8 2-byte sequence that prefixes a surrogate code point, i.e., in the range 0xED 0xA0 to 0xED 0xBF.static intnextState(int s, byte b)Deprecated.UsenextState(int, byte, Utf8ByteHandler)instead.static <X extends Exception>
intnextState(int state, byte[] b, int from, int to, Utf8ByteHandler<X> handler)static <X extends Exception>
intnextState(int s, byte b, Utf8ByteHandler<X> handler)Returns the next UTF-8 state given a previous state, a next byte, and a code point handler.static <X extends Exception>
intnextState(int state, InputStream inputStream, Utf8ByteHandler<X> handler)static <X extends Exception>
voidtransfer(InputStream is, Utf8ByteHandler<X> handler)This method is semantically equivalent to:static Validityvalidity(byte[] b, int from, int to)Returns the validity of the specified byte array between the specified indexesstatic Validityvalidity(InputStream is)
-
-
-
Method Detail
-
nextState
@Deprecated public static int nextState(int s, byte b)
Deprecated.UsenextState(int, byte, Utf8ByteHandler)instead.Returns the next UTF-8 state given a previous state and a next byte. If the returned state is non-negative, it is a legal non-surrogate unicode code point. Otherwise, it is either an error state or an incomplete state.- Parameters:
s- the previous UTF-8 state returned from this function, or 0 for the initial stateb- the next byte- Returns:
- the next UTF-8 state
- See Also:
isErrorState(int),isIncompleteState(int)
-
nextState
public static <X extends Exception> int nextState(int s, byte b, Utf8ByteHandler<X> handler) throws X extends Exception
Returns the next UTF-8 state given a previous state, a next byte, and a code point handler.- Parameters:
s- the previous UTF-8 state returned from this function, or 0 for the initial stateb- the next bytehandler- the handler to delegate all code point and error handling to- Returns:
- the next UTF-8 state
- Throws:
X extends Exception- See Also:
isIncompleteState(int)
-
nextState
public static <X extends Exception> int nextState(int state, byte[] b, int from, int to, Utf8ByteHandler<X> handler) throws X extends Exception
- Throws:
X extends Exception
-
nextState
public static <X extends Exception> int nextState(int state, InputStream inputStream, Utf8ByteHandler<X> handler) throws IOException, X extends Exception
- Throws:
IOExceptionX extends Exception
-
finish
public static <X extends Exception> void finish(int finalState, Utf8ByteHandler<X> handler) throws X extends Exception
If the final state is incomplete, allows handler to handle final error state- Parameters:
finalState- the final statehandler- the handler- Throws:
X extends Exception
-
transfer
public static <X extends Exception> void transfer(InputStream is, Utf8ByteHandler<X> handler) throws IOException, X extends Exception
This method is semantically equivalent to:int finalState = Utf8.nextState(0, is, handler); Utf8.finish(finalState, handler);- Type Parameters:
X- the handler exception type- Parameters:
is- the input streamhandler- the handler- Throws:
IOException- if the input stream threw this exceptionX- if the handler threw this exceptionX extends Exception
-
validity
public static Validity validity(InputStream is) throws IOException
- Throws:
IOException
-
validity
public static Validity validity(byte[] b, int from, int to)
Returns the validity of the specified byte array between the specified indexes- Parameters:
b- the byte arrayfrom- the start indexto- the end index, exclusive- Returns:
- the validity
-
codePoint
public static int codePoint(int b1, int b2)Returns a valid unicode code point given a valid UTF-8 2-byte sequence. The maximum code point returned by this method is U+07FF. Results for invalid 2-byte sequences are undefined.- Parameters:
b1- a negative byte of the form(byte)0b110xxxxxb2- a negative byte of the form(byte)0b10xxxxxx- Returns:
- the code point corresponding to this valid UTF-8 2-byte sequence
-
codePoint
public static int codePoint(int b1, int b2, int b3)Returns a valid unicode code point given a valid UTF-8 3-byte sequence. The maximum code point returned by this method is U+FFFF. Results for invalid 3-byte sequences are undefined.- Parameters:
b1- a negative byte of the form(byte)0b1110xxxxb2- a negative byte of the form(byte)0b10xxxxxxb3- a negative byte of the form(byte)0b10xxxxxx- Returns:
- the code point corresponding to this valid UTF-8 3-byte sequence
-
codePoint
public static int codePoint(int b1, int b2, int b3, int b4)Returns a valid unicode code point given a valid UTF-8 4-byte sequence. The maximum code point returned by this method is U+10FFFF. Results for invalid 4-byte sequences are undefined.- Parameters:
b1- a negative byte of the form(byte)0b11110xxxb2- a negative byte of the form(byte)0b10xxxxxxb3- a negative byte of the form(byte)0b10xxxxxxb4- a negative byte of the form(byte)0b10xxxxxx- Returns:
- the code point corresponding to this valid UTF-8 4-byte sequence
-
isIncompleteState
public static boolean isIncompleteState(int s)
Tests if at least one more continuation byte is needed to create a code point- Parameters:
s- the state to test- Returns:
- true if at least one more byte is needed to create a code point
-
isErrorState
public static boolean isErrorState(int s)
Tests if this state corresponds to any invalid UTF-8 byte sequence.- Parameters:
s- the state to test- Returns:
- true if this state corresponds to an invalid UTF-8 byte sequence.
-
isSurrogatePrefixErrorState
public static boolean isSurrogatePrefixErrorState(int s)
Tests if this state corresponds to an invalid UTF-8 2-byte sequence that prefixes a surrogate code point, i.e., in the range 0xED 0xA0 to 0xED 0xBF.- Parameters:
s- the state to test- Returns:
- true if this state corresponds to an invalid surrogate code point prefix
-
-