org.apache.avro.util
Class Utf8

java.lang.Object
  extended by org.apache.avro.util.Utf8
All Implemented Interfaces:
CharSequence, Comparable<Utf8>

public class Utf8
extends Object
implements Comparable<Utf8>, CharSequence

A Utf8 string. Unlike String, instances are mutable. This is more efficient than String when reading or writing a sequence of values, as a single instance may be reused.


Constructor Summary
Utf8()
           
Utf8(byte[] bytes)
           
Utf8(String string)
           
 
Method Summary
 char charAt(int index)
           
 int compareTo(Utf8 that)
           
 boolean equals(Object o)
           
 int getByteLength()
          Return length in bytes.
 byte[] getBytes()
          Return UTF-8 encoded bytes.
static byte[] getBytesFor(String str)
          Gets the UTF-8 bytes for a String
 int getLength()
          Deprecated. call getByteLength() instead.
 int hashCode()
           
 int length()
           
 Utf8 setByteLength(int newLength)
          Set length in bytes.
 Utf8 setLength(int newLength)
          Deprecated. call setByteLength(int) instead.
 CharSequence subSequence(int start, int end)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Utf8

public Utf8()

Utf8

public Utf8(String string)

Utf8

public Utf8(byte[] bytes)
Method Detail

getBytes

public byte[] getBytes()
Return UTF-8 encoded bytes. Only valid through getByteLength().


getLength

public int getLength()
Deprecated. call getByteLength() instead.

Return length in bytes.


getByteLength

public int getByteLength()
Return length in bytes.


setLength

public Utf8 setLength(int newLength)
Deprecated. call setByteLength(int) instead.

Set length in bytes. Should called whenever byte content changes, even if the length does not change, as this also clears the cached String.


setByteLength

public Utf8 setByteLength(int newLength)
Set length in bytes. Should called whenever byte content changes, even if the length does not change, as this also clears the cached String.


toString

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

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Utf8 that)
Specified by:
compareTo in interface Comparable<Utf8>

charAt

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

length

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

subSequence

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

getBytesFor

public static final byte[] getBytesFor(String str)
Gets the UTF-8 bytes for a String



Copyright © 2011 The Apache Software Foundation. All Rights Reserved.