org.apache.accumulo.core.data
Class Value

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

public class Value
extends java.lang.Object
implements org.apache.hadoop.io.WritableComparable<java.lang.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(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 java.lang.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(java.lang.Object right_obj)
          Define the sort order of the BytesWritable.
 void copy(byte[] b)
           
 boolean equals(java.lang.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(java.io.DataInput in)
          
 void set(byte[] b)
           
static byte[] stringToBytes(java.lang.String s)
          Converts a string to a byte array in a consistent manner.
static byte[][] toArray(java.util.List<byte[]> array)
           
 java.lang.String toString()
           
 void write(java.io.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(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(java.io.DataInput in)
                throws java.io.IOException

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

write

public void write(java.io.DataOutput out)
           throws java.io.IOException

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

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

compareTo

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

Specified by:
compareTo in interface java.lang.Comparable<java.lang.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(java.lang.Object right_obj)

Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toArray

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

longToBytes

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

Throws:
java.io.IOException

bytesToLong

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

Throws:
java.io.IOException

stringToBytes

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

Throws:
java.io.UnsupportedEncodingException

bytesToString

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

Throws:
java.io.UnsupportedEncodingException

getBytes

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

getWritable

public static org.apache.hadoop.io.Writable getWritable(byte[] bytes,
                                                        org.apache.hadoop.io.Writable w)
                                                 throws java.io.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:
java.io.IOException


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