org.apache.accumulo.core.data
Class Value

java.lang.Object
  extended by org.apache.accumulo.core.data.Value
All Implemented Interfaces:
Comparable<Object>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<Object>

public class Value
extends Object
implements org.apache.hadoop.io.WritableComparable<Object>

A byte sequence that is usable as a key or value. Based on BytesWritable only this class is NOT resizable and DOES NOT distinguish between the size of the sequence and the current capacity as BytesWritable does. Hence its comparatively 'immutable'.


Nested Class Summary
static class Value.Comparator
          A Comparator optimized for Value.
 
Field Summary
protected  byte[] value
           
 
Constructor Summary
Value()
          Create a zero-size sequence.
Value(byte[] bytes)
          Create a Value using the byte array as the initial value.
Value(byte[] bytes, boolean copy)
           
Value(byte[] newData, int offset, int length)
          Set the value to a copy of the given byte range
Value(ByteBuffer bytes)
           
Value(ByteBuffer bytes, boolean copy)
           
Value(Value ibw)
          Set the new Value to a copy of the contents of the passed ibw.
 
Method Summary
static long bytesToLong(byte[] bytes)
          Converts a byte array to a long value
static String bytesToString(byte[] bytes)
          Converts a byte array to a string in a consistent manner.
 int compareTo(byte[] that)
          Compares the bytes in this object to the specified byte array
 int compareTo(Object right_obj)
          Define the sort order of the BytesWritable.
 void copy(byte[] b)
           
 boolean equals(Object right_obj)
          
 byte[] get()
          Get the data from the BytesWritable.
static byte[] getBytes(org.apache.hadoop.io.Writable w)
           
 int getSize()
           
static org.apache.hadoop.io.Writable getWritable(byte[] bytes, org.apache.hadoop.io.Writable w)
          Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).
 int hashCode()
          
static byte[] longToBytes(long val)
          Convert a long value to a byte array
 void readFields(DataInput in)
          
 void set(byte[] b)
           
static byte[] stringToBytes(String s)
          Converts a string to a byte array in a consistent manner.
static byte[][] toArray(List<byte[]> array)
           
 String toString()
           
 void write(DataOutput out)
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected byte[] value
Constructor Detail

Value

public Value()
Create a zero-size sequence.


Value

public Value(byte[] bytes)
Create a Value using the byte array as the initial value.

Parameters:
bytes - This array becomes the backing storage for the object.

Value

public Value(ByteBuffer bytes)

Value

public Value(ByteBuffer bytes,
             boolean copy)

Value

public Value(byte[] bytes,
             boolean copy)

Value

public Value(Value ibw)
Set the new Value to a copy of the contents of the passed ibw.

Parameters:
ibw - the value to set this Value to.

Value

public Value(byte[] newData,
             int offset,
             int length)
Set the value to a copy of the given byte range

Parameters:
newData - the new values to copy in
offset - the offset in newData to start at
length - the number of bytes to copy
Method Detail

get

public byte[] get()
Get the data from the BytesWritable.

Returns:
The data is only valid between 0 and getSize() - 1.

set

public void set(byte[] b)
Parameters:
b - Use passed bytes as backing array for this instance.

copy

public void copy(byte[] b)
Parameters:
b - copy bytes

getSize

public int getSize()
Returns:
the current size of the buffer.

readFields

public void readFields(DataInput in)
                throws IOException

Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException

Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

hashCode

public int hashCode()

Overrides:
hashCode in class Object

compareTo

public int compareTo(Object right_obj)
Define the sort order of the BytesWritable.

Specified by:
compareTo in interface Comparable<Object>
Parameters:
right_obj - The other bytes writable
Returns:
Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.

compareTo

public int compareTo(byte[] that)
Compares the bytes in this object to the specified byte array

Returns:
Positive if left is bigger than right, 0 if they are equal, and negative if left is smaller than right.

equals

public boolean equals(Object right_obj)

Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

toArray

public static byte[][] toArray(List<byte[]> array)

longToBytes

public static byte[] longToBytes(long val)
                          throws IOException
Convert a long value to a byte array

Throws:
IOException

bytesToLong

public static long bytesToLong(byte[] bytes)
                        throws IOException
Converts a byte array to a long value

Throws:
IOException

stringToBytes

public static byte[] stringToBytes(String s)
                            throws UnsupportedEncodingException
Converts a string to a byte array in a consistent manner.

Throws:
UnsupportedEncodingException

bytesToString

public static String bytesToString(byte[] bytes)
                            throws UnsupportedEncodingException
Converts a byte array to a string in a consistent manner.

Throws:
UnsupportedEncodingException

getBytes

public static byte[] getBytes(org.apache.hadoop.io.Writable w)
                       throws IOException
Returns:
The bytes of w gotten by running its Writable.write(java.io.DataOutput) method.
Throws:
IOException
See Also:
getWritable(byte[], Writable)

getWritable

public static org.apache.hadoop.io.Writable getWritable(byte[] bytes,
                                                        org.apache.hadoop.io.Writable w)
                                                 throws IOException
Set bytes into the passed Writable by calling its Writable.readFields(java.io.DataInput).

Parameters:
w - An empty Writable (usually made by calling the null-arg constructor).
Returns:
The passed Writable after its readFields has been called fed by the passed bytes array or IllegalArgumentException if passed null or an empty bytes array.
Throws:
IOException


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