com.googlecode.concurrenttrees.radix.node.concrete.bytearray
Class ByteArrayCharSequence

java.lang.Object
  extended by com.googlecode.concurrenttrees.radix.node.concrete.bytearray.ByteArrayCharSequence
All Implemented Interfaces:
CharSequence

public class ByteArrayCharSequence
extends Object
implements CharSequence

A CharSequence 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.

Author:
Niall Gallagher

Nested Class Summary
static class ByteArrayCharSequence.IncompatibleCharacterException
           
 
Constructor Summary
ByteArrayCharSequence(byte[] bytes, int start, int end)
           
 
Method Summary
 char charAt(int index)
           
 int length()
           
 ByteArrayCharSequence subSequence(int start, int end)
           
static byte[] toSingleByteUtf8Encoding(CharSequence charSequence)
          Encodes a given CharSequence into a byte[] in UTF-8 encoding, with the requirement that it must be possible to represent all characters as a single byte in UTF-8.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteArrayCharSequence

public ByteArrayCharSequence(byte[] bytes,
                             int start,
                             int end)
Method Detail

length

public int length()
Specified by:
length in interface CharSequence

charAt

public char charAt(int index)
Specified by:
charAt in interface CharSequence

subSequence

public ByteArrayCharSequence subSequence(int start,
                                         int end)
Specified by:
subSequence in interface CharSequence

toString

public String toString()
Specified by:
toString in interface CharSequence
Overrides:
toString in class Object

toSingleByteUtf8Encoding

public static byte[] toSingleByteUtf8Encoding(CharSequence charSequence)
Encodes a given CharSequence into a byte[] 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 - The CharSequence to encode
Returns:
A new byte[] encoding characters from the given CharSequence in UTF-8
Throws:
IllegalStateException - If the characters cannot be encoded as described


Copyright © 2013. All Rights Reserved.