com.datasalt.pangool.io
Class BytesWritable

java.lang.Object
  extended by org.apache.hadoop.io.BinaryComparable
      extended by com.datasalt.pangool.io.BytesWritable
All Implemented Interfaces:
Comparable<org.apache.hadoop.io.BinaryComparable>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<org.apache.hadoop.io.BinaryComparable>

public class BytesWritable
extends org.apache.hadoop.io.BinaryComparable
implements org.apache.hadoop.io.WritableComparable<org.apache.hadoop.io.BinaryComparable>

A byte sequence that is usable as a key or value. It is resizable and distinguishes between the size of the seqeunce and the current capacity. The hash function is the front of the md5 of the buffer. The sort order is the same as memcmp. Uses a variable length integer for serializing the size.


Nested Class Summary
static class BytesWritable.Comparator
          A Comparator optimized for BytesWritable.
 
Constructor Summary
BytesWritable()
          Create a zero-size sequence.
BytesWritable(byte[] bytes)
          Create a BytesWritable using the byte array as the initial value.
 
Method Summary
 boolean equals(Object right_obj)
          Are the two byte sequences equal?
 byte[] getBytes()
          Get the data from the BytesWritable.
 int getCapacity()
          Get the capacity, which is the maximum size that could handled without resizing the backing storage.
 int getLength()
          Get the current size of the buffer.
 int hashCode()
           
 void readFields(DataInput in)
           
 void replace(byte[] newArray, int size)
          Replaces the internal byte array by the given one.
 void set(byte[] newData, int offset, int length)
          Set the value to a copy of the given byte range
 void set(BytesWritable newData)
          Set the BytesWritable to the contents of the given newData.
 void setCapacity(int new_cap)
          Change the capacity of the backing storage.
 void setSize(int size)
          Change the size of the buffer.
 String toString()
          Generate the stream of bytes as hex pairs separated by ' '.
 void write(DataOutput out)
           
 
Methods inherited from class org.apache.hadoop.io.BinaryComparable
compareTo, compareTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

BytesWritable

public BytesWritable()
Create a zero-size sequence.


BytesWritable

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

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

getBytes

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

Specified by:
getBytes in class org.apache.hadoop.io.BinaryComparable
Returns:
The data is only valid between 0 and getLength() - 1.

getLength

public int getLength()
Get the current size of the buffer.

Specified by:
getLength in class org.apache.hadoop.io.BinaryComparable

setSize

public void setSize(int size)
Change the size of the buffer. The values in the old range are preserved and any new values are undefined. The capacity is changed if it is necessary.

Parameters:
size - The new number of bytes

getCapacity

public int getCapacity()
Get the capacity, which is the maximum size that could handled without resizing the backing storage.

Returns:
The number of bytes

setCapacity

public void setCapacity(int new_cap)
Change the capacity of the backing storage. The data is preserved.

Parameters:
new_cap - The new capacity in bytes.

set

public void set(BytesWritable newData)
Set the BytesWritable to the contents of the given newData.

Parameters:
newData - the value to set this BytesWritable to.

replace

public void replace(byte[] newArray,
                    int size)
Replaces the internal byte array by the given one. The byte array can be bigger than the given size.


set

public void set(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

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 org.apache.hadoop.io.BinaryComparable

equals

public boolean equals(Object right_obj)
Are the two byte sequences equal?

Overrides:
equals in class org.apache.hadoop.io.BinaryComparable

toString

public String toString()
Generate the stream of bytes as hex pairs separated by ' '.

Overrides:
toString in class Object


Copyright © –2014 Datasalt Systems S.L.. All rights reserved.