Class ByteArrayCharSequence
- java.lang.Object
-
- com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayCharSequence
-
- All Implemented Interfaces:
java.lang.CharSequence
public class ByteArrayCharSequence extends java.lang.Object implements java.lang.CharSequence
ACharSequence
view onto a byte array of UTF-8-encoded characters, with the proviso that all of the characters were encoded as a single byte in UTF-8. This uses Java's built-in casting from UTF-8 to char primitives.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ByteArrayCharSequence.IncompatibleCharacterException
-
Constructor Summary
Constructors Constructor Description ByteArrayCharSequence(byte[] bytes, int start, int end)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int index)
int
length()
ByteArrayCharSequence
subSequence(int start, int end)
static byte[]
toSingleByteUtf8Encoding(java.lang.CharSequence charSequence)
Encodes a givenCharSequence
into abyte[]
in UTF-8 encoding, with the requirement that it must be possible to represent all characters as a single byte in UTF-8.java.lang.String
toString()
-
-
-
Method Detail
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
- Specified by:
charAt
in interfacejava.lang.CharSequence
-
subSequence
public ByteArrayCharSequence subSequence(int start, int end)
- Specified by:
subSequence
in interfacejava.lang.CharSequence
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
toSingleByteUtf8Encoding
public static byte[] toSingleByteUtf8Encoding(java.lang.CharSequence charSequence)
Encodes a givenCharSequence
into abyte[]
in UTF-8 encoding, with the requirement that it must be possible to represent all characters as a single byte in UTF-8. Otherwise an exception will be thrown.- Parameters:
charSequence
- TheCharSequence
to encode- Returns:
- A new
byte[]
encoding characters from the givenCharSequence
in UTF-8 - Throws:
java.lang.IllegalStateException
- If the characters cannot be encoded as described
-
-