com.nhncorp.neptune.common.io
Class NUTF8

java.lang.Object
  extended by com.nhncorp.neptune.common.io.NUTF8
All Implemented Interfaces:
NWritable, NWritableComparable, java.lang.Comparable

public class NUTF8
extends java.lang.Object
implements NWritableComparable

A WritableComparable for strings that uses the UTF8 encoding.

Also includes utilities for efficiently reading and writing UTF-8.

Author:
Doug Cutting

Nested Class Summary
static class NUTF8.Comparator
          A WritableComparator optimized for UTF8 keys.
 
Constructor Summary
NUTF8()
           
NUTF8(NUTF8 utf8)
          Construct from a given string.
NUTF8(java.lang.String string)
          Construct from a given string.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compare two UTF8s.
 boolean equals(java.lang.Object o)
          Returns true iff o is a UTF8 with the same contents.
 byte[] getBytes()
          The raw bytes.
static byte[] getBytes(java.lang.String string)
          Convert a string to a UTF-8 encoded byte array.
 int getLength()
          The number of bytes in the encoded string.
 int hashCode()
           
 void readFields(java.io.DataInput in)
          Reads the fields of this object from in.
static java.lang.String readString(java.io.DataInput in)
          Read a UTF-8 encoded string.
 void set(NUTF8 other)
          Set to contain the contents of a string.
 void set(java.lang.String string)
          Set to contain the contents of a string.
static void skip(java.io.DataInput in)
          Skips over one UTF8 in the input.
 java.lang.String toString()
          Convert to a String.
 void write(java.io.DataOutput out)
          Writes the fields of this object to out.
static int writeString(java.io.DataOutput out, java.lang.String s)
          Write a UTF-8 encoded string.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NUTF8

public NUTF8()

NUTF8

public NUTF8(java.lang.String string)
Construct from a given string.


NUTF8

public NUTF8(NUTF8 utf8)
Construct from a given string.

Method Detail

getBytes

public byte[] getBytes()
The raw bytes.


getLength

public int getLength()
The number of bytes in the encoded string.


set

public void set(java.lang.String string)
Set to contain the contents of a string.


set

public void set(NUTF8 other)
Set to contain the contents of a string.


readFields

public void readFields(java.io.DataInput in)
                throws java.io.IOException
Description copied from interface: NWritable
Reads the fields of this object from in. For efficiency, implementations should attempt to re-use storage in the existing object where possible.

Specified by:
readFields in interface NWritable
Throws:
java.io.IOException

skip

public static void skip(java.io.DataInput in)
                 throws java.io.IOException
Skips over one UTF8 in the input.

Throws:
java.io.IOException

write

public void write(java.io.DataOutput out)
           throws java.io.IOException
Description copied from interface: NWritable
Writes the fields of this object to out.

Specified by:
write in interface NWritable
Throws:
java.io.IOException

compareTo

public int compareTo(java.lang.Object o)
Compare two UTF8s.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Convert to a String.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Returns true iff o is a UTF8 with the same contents.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getBytes

public static byte[] getBytes(java.lang.String string)
Convert a string to a UTF-8 encoded byte array.

See Also:
String.getBytes(String)

readString

public static java.lang.String readString(java.io.DataInput in)
                                   throws java.io.IOException
Read a UTF-8 encoded string.

Throws:
java.io.IOException
See Also:
DataInput.readUTF()

writeString

public static int writeString(java.io.DataOutput out,
                              java.lang.String s)
                       throws java.io.IOException
Write a UTF-8 encoded string.

Throws:
java.io.IOException
See Also:
DataOutput.writeUTF(String)