org.apache.hadoop.hbase.io
Class TextSequence

java.lang.Object
  extended by org.apache.hadoop.io.Text
      extended by org.apache.hadoop.hbase.io.TextSequence
All Implemented Interfaces:
Comparable, Writable, WritableComparable

public class TextSequence
extends Text

As CharSequence is to String, so is TextSequence to Text (except a TextSequence is a Text whereas a String is a CharSequence). Use when you want to conserve on object creation.

Use with care. If danger that the passed in Text instance can change during the life of this TextSequence, concretize this TextSequence by calling toText().

Equals considers a Text equal if the TextSequence brackets the same bytes.

TextSequence will not always work as a Text. For instance, the following fails Text c = new Text(new TextSequence(new Text("some string"))); because the Text constructor accesses private Text data members making the new instance from the passed 'Text'.

TODO: Should this be an Interface as CharSequence is?


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.hadoop.io.Text
Text.Comparator
 
Constructor Summary
TextSequence()
           
TextSequence(Text d)
           
TextSequence(Text d, int s)
           
TextSequence(Text d, int s, int e)
           
 
Method Summary
 int charAt(int position)
          Returns the Unicode Scalar Value (32-bit integer value) for the character at position.
 int compareTo(Object o)
          Compare two Texts bytewise using standard UTF8 ordering.
 boolean equals(Object o)
          Returns true iff o is a Text with the same contents.
 int find(String what)
           
 int find(String what, int s)
          Finds any occurence of what in the backing buffer, starting as position start.
 byte[] getBytes()
          Retuns the raw bytes.
 int getLength()
          Returns the number of bytes in the byte array
 int hashCode()
          hash function
 void readFields(DataInput in)
          deserialize
 void set(byte[] utf8)
          Set to a utf8 byte array
 void set(byte[] utf8, int start, int len)
          Set the Text to range of bytes
 void set(String string)
          Set to contain the contents of a string.
 void set(Text other)
          copy a text.
 String toString()
          Convert text back to string
 Text toText()
           
 void write(DataOutput out)
          serialize write this object to out length uses zero-compressed encoding
 
Methods inherited from class org.apache.hadoop.io.Text
append, bytesToCodePoint, clear, decode, decode, decode, encode, encode, readString, skip, utf8Length, validateUTF8, validateUTF8, writeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextSequence

public TextSequence()

TextSequence

public TextSequence(Text d)

TextSequence

public TextSequence(Text d,
                    int s)

TextSequence

public TextSequence(Text d,
                    int s,
                    int e)
Method Detail

charAt

public int charAt(int position)
Description copied from class: Text
Returns the Unicode Scalar Value (32-bit integer value) for the character at position. Note that this method avoids using the converter or doing String instatiation

Overrides:
charAt in class Text
Returns:
the Unicode scalar value at position or -1 if the position is invalid or points to a trailing byte

compareTo

public int compareTo(Object o)
Description copied from class: Text
Compare two Texts bytewise using standard UTF8 ordering.

Specified by:
compareTo in interface Comparable
Overrides:
compareTo in class Text

equals

public boolean equals(Object o)
Description copied from class: Text
Returns true iff o is a Text with the same contents.

Overrides:
equals in class Text

find

public int find(String what,
                int s)
Description copied from class: Text
Finds any occurence of what in the backing buffer, starting as position start. The starting position is measured in bytes and the return value is in terms of byte position in the buffer. The backing buffer is not converted to a string for this operation.

Overrides:
find in class Text
Returns:
byte position of the first occurence of the search string in the UTF-8 buffer or -1 if not found

find

public int find(String what)
Overrides:
find in class Text

getBytes

public byte[] getBytes()
Description copied from class: Text
Retuns the raw bytes.

Overrides:
getBytes in class Text

toText

public Text toText()
Returns:
A new Text instance made from the bytes this TextSequence covers.

getLength

public int getLength()
Description copied from class: Text
Returns the number of bytes in the byte array

Overrides:
getLength in class Text

hashCode

public int hashCode()
Description copied from class: Text
hash function

Overrides:
hashCode in class Text

set

public void set(byte[] utf8,
                int start,
                int len)
Description copied from class: Text
Set the Text to range of bytes

Overrides:
set in class Text
Parameters:
utf8 - the data to copy from
start - the first position of the new string
len - the number of bytes of the new string

set

public void set(byte[] utf8)
Description copied from class: Text
Set to a utf8 byte array

Overrides:
set in class Text

set

public void set(String string)
Description copied from class: Text
Set to contain the contents of a string.

Overrides:
set in class Text

set

public void set(Text other)
Description copied from class: Text
copy a text.

Overrides:
set in class Text

toString

public String toString()
Description copied from class: Text
Convert text back to string

Overrides:
toString in class Text
See Also:
Object.toString()

readFields

public void readFields(DataInput in)
                throws IOException
Description copied from class: Text
deserialize

Specified by:
readFields in interface Writable
Overrides:
readFields in class Text
Parameters:
in - DataInput to deseriablize this object from.
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Description copied from class: Text
serialize write this object to out length uses zero-compressed encoding

Specified by:
write in interface Writable
Overrides:
write in class Text
Parameters:
out - DataOuput to serialize this object into.
Throws:
IOException
See Also:
Writable.write(DataOutput)


Copyright © 2006 The Apache Software Foundation