Bees v0.5.0 API

bees.core
Class ByteArray

java.lang.Object
  |
  +--bees.core.ByteArray
Direct Known Subclasses:
XdrByteArray

public class ByteArray
extends java.lang.Object

Wrapper for an array of Bytes. Incorporates offset and length.

Most of the methods in here are final for performance reasons.

Author:
probably David Wetherall.

Field Summary
 byte[] buf
          The actual byte array this object wraps.
 int len
          The length of the byte array in `buf' that this object wraps.
 int offset
          The start of the byte array in `buf' that this object wraps.
 
Constructor Summary
ByteArray(byte[] buf)
          Construct a new ByteArray object that wraps the given array.
ByteArray(byte[] buf, int offset)
          Construct a new ByteArray object that wraps the given array.
ByteArray(byte[] buf, int offset, int len)
          Construct a new ByteArray object that wraps the given array.
ByteArray(ByteArray parent, int offset)
          Construct a new ByteArray object that wraps the byte array encapsulated by another ByteArray object.
ByteArray(ByteArray parent, int offset, int len)
          Construct a new ByteArray object that wraps the byte array encapsulated by another ByteArray object.
ByteArray(int len)
          Construct a new ByteArray object that has the given length.
 
Method Summary
static byte[] concat(byte[][] ba)
          Concatenate an array of byte arrays together.
static byte[] concat(byte[] ba1, byte[] ba2)
          Concatenate two byte arrays together.
static byte[] fromFile(File file)
          Create a byte array from the contents of the given file.
 byte getByte(int index)
           
 void getBytes(int srcBegin, byte[] dst, int dstBegin, int length)
          Copy a range of bytes from the array into a basic byte array.
 int length()
           
 void setByte(int index, byte val)
           
 void setBytes(int dstBegin, byte[] src, int srcBegin, int length)
          Copy a range of bytes to the array from a basic byte array.
 void setBytes(int dstBegin, ByteArray src, int srcBegin, int length)
          Copy a range of bytes to the array from another byte array.
 byte[] toBytes()
          Returns a byte array exactly the right size for the valid data in the buf.
static void toFile(File file, byte[] bits)
          Write the given byte array to the given file.
static java.lang.String toPlainString(byte[] bytes)
          Convert a byte array to a string in a hexidecimal representation.
static java.lang.String toPlainString(byte[] bytes, int maxBytes)
          Convert a byte array to a string in a hexidecimal representation.
 java.lang.String toString()
           
static java.lang.String toString(byte[] bytes)
          Convert a byte array to a string in a hexidecimal representation and some extra formatting.
static java.lang.String toString(byte[] bytes, int maxBytes)
          Convert a byte array to a string in a hexidecimal representation and some extra formatting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

public byte[] buf
The actual byte array this object wraps.

offset

public int offset
The start of the byte array in `buf' that this object wraps.

len

public int len
The length of the byte array in `buf' that this object wraps.
Constructor Detail

ByteArray

public ByteArray(int len)
Construct a new ByteArray object that has the given length.
Parameters:
len - The length of the internal byte array to create.

ByteArray

public ByteArray(byte[] buf)
Construct a new ByteArray object that wraps the given array.
Parameters:
buf - The byte array to wrap.

ByteArray

public ByteArray(byte[] buf,
                 int offset)
Construct a new ByteArray object that wraps the given array.
Parameters:
buf - The byte array to wrap.
offset - The start of the byte array in `buf' that this object should wrap.

ByteArray

public ByteArray(byte[] buf,
                 int offset,
                 int len)
          throws java.lang.IndexOutOfBoundsException
Construct a new ByteArray object that wraps the given array.
Parameters:
buf - The byte array to wrap.
offset - The start of the byte array in `buf' that this object should wrap.
len - The length of the byte array in `buf' that this object should wrap.
Throws:
java.lang.IndexOutOfBoundsException - if the given range is outside the given buffer.

ByteArray

public ByteArray(ByteArray parent,
                 int offset)
Construct a new ByteArray object that wraps the byte array encapsulated by another ByteArray object.
Parameters:
parent - The ByteArray object that contains the byte array to rewrap.
offset - An extra offset to add to the parent's offset.

ByteArray

public ByteArray(ByteArray parent,
                 int offset,
                 int len)
          throws java.lang.IndexOutOfBoundsException
Construct a new ByteArray object that wraps the byte array encapsulated by another ByteArray object.
Parameters:
parent - The ByteArray object that contains the byte array to rewrap.
offset - An extra offset to add to the parent's offset.
len - The length of the wrapped byte array.
Throws:
java.lang.IndexOutOfBoundsException - if the given range is outside the given buffer.
Method Detail

length

public final int length()
Returns:
The length of the wrapped byte array.

getByte

public final byte getByte(int index)
                   throws java.lang.IndexOutOfBoundsException
Parameters:
index - The index of the byte to return.
Returns:
The byte at the given index in the array.
Throws:
java.lang.IndexOutOfBoundsException - if `index' is out of bounds of the array.

setByte

public final void setByte(int index,
                          byte val)
                   throws java.lang.IndexOutOfBoundsException
Parameters:
index - The index of the byte to return.
val - The byte to put at the given index in the array.
Throws:
java.lang.IndexOutOfBoundsException - if `index' is out of bounds of the array.

getBytes

public final void getBytes(int srcBegin,
                           byte[] dst,
                           int dstBegin,
                           int length)
Copy a range of bytes from the array into a basic byte array.
Parameters:
srcBegin - The offset into the byte array to start copying bytes.
dst - The array to copy the bytes into.
dstBegin - The offset in `dst' to start copying.
length - The number of bytes to copy from the array.

setBytes

public final void setBytes(int dstBegin,
                           byte[] src,
                           int srcBegin,
                           int length)
Copy a range of bytes to the array from a basic byte array.
Parameters:
dstBegin - The offset into the byte array to start copying bytes.
src - The array to copy the bytes from.
srcBegin - The offset in `src' to start copying bytes.
length - The number of bytes to copy to the array.

setBytes

public final void setBytes(int dstBegin,
                           ByteArray src,
                           int srcBegin,
                           int length)
Copy a range of bytes to the array from another byte array.
Parameters:
dstBegin - The offset into the byte array to start copying bytes.
src - The array to copy the bytes from.
srcBegin - The offset in `src' to start copying bytes.
length - The number of bytes to copy to the array.

toBytes

public final byte[] toBytes()
Returns a byte array exactly the right size for the valid data in the buf. Note that if this.buf is the right side it is returned directly, otherwise a new array is created of the right size. (Weird.)
Returns:
array of bytes

fromFile

public static final byte[] fromFile(File file)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException
Create a byte array from the contents of the given file.
Parameters:
file - The file capability to read from.
Returns:
The byte array containing the contents of the given file.
Throws:
java.io.FileNotFoundException - if the file couldn't be found. XXX This "shouldn't" happen since we have a capability to it.
java.io.IOException - if there is an error reading the file.

toFile

public static final void toFile(File file,
                                byte[] bits)
                         throws java.io.FileNotFoundException,
                                java.io.IOException
Write the given byte array to the given file.
Parameters:
file - The file capability to write to.
bits - The byte array to write to the file.
Throws:
java.io.FileNotFoundException - if the file couldn't be found. XXX This "shouldn't" happen since we have a capability to it.
java.io.IOException - if there is an error writing the file.

concat

public static final byte[] concat(byte[][] ba)
Concatenate an array of byte arrays together.
Parameters:
ba - The array of arrays to concatenate. Any null elements will be ignored.
Returns:
A byte array consisting of the contents in ba.

concat

public static final byte[] concat(byte[] ba1,
                                  byte[] ba2)
Concatenate two byte arrays together.
Parameters:
ba1 - The first byte array.
ba2 - The second byte array.
Returns:
A byte array consisting of the contents of ba1 followed by the contents of ba2.

toPlainString

public static final java.lang.String toPlainString(byte[] bytes,
                                                   int maxBytes)
Convert a byte array to a string in a hexidecimal representation.
Parameters:
bytes - The byte array to format.
maxBytes - The maximum number of bytes to format.
Returns:
A plain hexadecimal string representing the values in bytes.

toPlainString

public static final java.lang.String toPlainString(byte[] bytes)
Convert a byte array to a string in a hexidecimal representation.
Parameters:
bytes - The byte array to format.
Returns:
A plain hexadecimal string representing the values in bytes.

toString

public static final java.lang.String toString(byte[] bytes,
                                              int maxBytes)
Convert a byte array to a string in a hexidecimal representation and some extra formatting.
Parameters:
bytes - The bytes to turn into a string.
maxBytes - The maximum number of bytes to format.
Returns:
The formatted string.

toString

public static final java.lang.String toString(byte[] bytes)
Convert a byte array to a string in a hexidecimal representation and some extra formatting.
Parameters:
bytes - The bytes to turn into a string.
Returns:
The formatted string.

toString

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

Bees v0.5.0 API

This documentation is Copyright (C) 2002 The University of Utah. All Rights Reserved. See the individual source files for distribution terms.
Documentation, software, and mailing lists for Bees v0.5.0 can be found at the Janos Project: http://www.cs.utah.edu/flux/janos/