org.apache.pig.data
Class DataByteArray

java.lang.Object
  extended by org.apache.pig.data.DataByteArray
All Implemented Interfaces:
Serializable, Comparable

@InterfaceAudience.Public
@InterfaceStability.Stable
public class DataByteArray
extends Object
implements Comparable, Serializable

An implementation of byte array. This is done as an object because we need to be able to implement compareTo, toString, hashCode, and some other methods.

See Also:
Serialized Form

Constructor Summary
DataByteArray()
          Default constructor.
DataByteArray(byte[] b)
          Construct a byte array using the provided bytes as the content.
DataByteArray(byte[] b, int start, int end)
          Construct a byte array using a portion of the provided bytes as content.
DataByteArray(DataByteArray b, DataByteArray c)
          Construct a byte array concatenating the two provided byte arrays as the content.
DataByteArray(String s)
          Construct a byte array from a String.
 
Method Summary
 void append(DataByteArray b)
          Append given byte array to the internal byte array.
static int compare(byte[] b1, byte[] b2)
           
 int compareTo(Object other)
          Compare two byte arrays.
 boolean equals(Object other)
           
 byte[] get()
          Get the underlying byte array.
 int hashCode()
           
 void set(byte[] b)
          Set the internal byte array.
 void set(String s)
          Set the internal byte array.
 int size()
          Find the size of the byte array.
 String toString()
          Convert the byte array to a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataByteArray

public DataByteArray()
Default constructor. The data array will not be allocated when this constructor is called.


DataByteArray

public DataByteArray(byte[] b)
Construct a byte array using the provided bytes as the content.

Parameters:
b - byte array to use as content. A reference to the bytes will be taken, the underlying bytes will not be copied.

DataByteArray

public DataByteArray(DataByteArray b,
                     DataByteArray c)
Construct a byte array concatenating the two provided byte arrays as the content.

Parameters:
b - the first byte array to use as content.
c - the other byte array to use as content.

DataByteArray

public DataByteArray(byte[] b,
                     int start,
                     int end)
Construct a byte array using a portion of the provided bytes as content.

Parameters:
b - byte array to read from. A copy of the underlying bytes will be made.
start - starting point to copy from
end - ending point to copy to, exclusive.

DataByteArray

public DataByteArray(String s)
Construct a byte array from a String. The contents of the string are copied.

Parameters:
s - String to make a byte array out of.
Method Detail

size

public int size()
Find the size of the byte array.

Returns:
number of bytes in the array.

get

public byte[] get()
Get the underlying byte array. This is the real thing, not a copy, so don't mess with it!

Returns:
underlying byte[]

set

public void set(byte[] b)
Set the internal byte array. This should not be called unless the default constructor was used.

Parameters:
b - byte array to store. The contents of the byte array are not copied.

set

public void set(String s)
Set the internal byte array. This should not be called unless the default constructor was used.

Parameters:
s - String to copy. The contents of the string are copied.

append

public void append(DataByteArray b)
Append given byte array to the internal byte array.

Parameters:
b - byte array who's contents to append. The contents of the byte array are copied.

toString

public String toString()
Convert the byte array to a string. UTF8 encoding will be assumed.

Overrides:
toString in class Object

compareTo

public int compareTo(Object other)
Compare two byte arrays. Comparison is done first using byte values then length. So "g" will be greater than "abcdefg", but "hello worlds" is greater than "hello world". If the other object is not a DataByteArray, DataType.compare(java.lang.Object, java.lang.Object) will be called.

Specified by:
compareTo in interface Comparable
Parameters:
other - Other object to compare to.
Returns:
-1 if less than, 1 if greater than, 0 if equal.

compare

public static int compare(byte[] b1,
                          byte[] b2)

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © ${year} The Apache Software Foundation