com.ibm.icu.util

Class ByteArrayWrapper

public class ByteArrayWrapper extends Object implements Comparable

A simple utility class to wrap a byte array.

Generally passed as an argument object into a method. The method takes responsibility of writing into the internal byte array and increasing its size when necessary.

Author: syn wee

UNKNOWN: ICU 2.8

Field Summary
byte[]bytes
Internal byte array.
intsize
Size of the internal byte array used.
Constructor Summary
ByteArrayWrapper()
Construct a new ByteArrayWrapper with no data.
ByteArrayWrapper(byte[] bytesToAdopt, int size)
Construct a new ByteArrayWrapper from a byte array and size
ByteArrayWrapper(ByteBuffer source)
Construct a new ByteArrayWrapper from the contents of a ByteBuffer.
Method Summary
ByteArrayWrapperappend(byte[] src, int start, int limit)
Appends the internal byte array from offset size with the contents of src from offset start to limit.
intcompareTo(Object other)
Compare this object to another ByteArrayWrapper, which must not be null.
ByteArrayWrapperensureCapacity(int capacity)
Ensure that the internal byte array is at least of length capacity.
booleanequals(Object other)
Return true if the bytes in each wrapper are equal.
inthashCode()
Return the hashcode.
byte[]releaseBytes()
Releases the internal byte array to the caller, resets the internal byte array to null and its size to 0.
ByteArrayWrapperset(byte[] src, int start, int limit)
Set the internal byte array from offset 0 to (limit - start) with the contents of src from offset start to limit.
StringtoString()
Returns string value for debugging

Field Detail

bytes

public byte[] bytes
Internal byte array.

UNKNOWN: ICU 2.8

size

public int size
Size of the internal byte array used. Different from bytes.length, size will be <= bytes.length. Semantics of size is similar to java.util.Vector.size().

UNKNOWN: ICU 2.8

Constructor Detail

ByteArrayWrapper

public ByteArrayWrapper()
Construct a new ByteArrayWrapper with no data.

UNKNOWN: ICU 2.8

ByteArrayWrapper

public ByteArrayWrapper(byte[] bytesToAdopt, int size)
Construct a new ByteArrayWrapper from a byte array and size

Parameters: bytesToAdopt the byte array to adopt size the length of valid data in the byte array

Throws: IndexOutOfBoundsException if bytesToAdopt == null and size != 0, or size < 0, or size > bytesToAdopt.length.

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

ByteArrayWrapper

public ByteArrayWrapper(ByteBuffer source)
Construct a new ByteArrayWrapper from the contents of a ByteBuffer.

Parameters: source the ByteBuffer from which to get the data.

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

Method Detail

append

public final ByteArrayWrapper append(byte[] src, int start, int limit)
Appends the internal byte array from offset size with the contents of src from offset start to limit. This increases the size of the internal byte array to (size + limit - start).

Parameters: src source byte array to copy from start start offset of src to copy from limit end + 1 offset of src to copy from

Returns: this ByteArrayWrapper

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

compareTo

public int compareTo(Object other)
Compare this object to another ByteArrayWrapper, which must not be null.

Parameters: other the object to compare to.

Returns: a value <0, 0, or >0 as this compares less than, equal to, or greater than other.

Throws: ClassCastException if the other object is not a ByteArrayWrapper

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

ensureCapacity

public ByteArrayWrapper ensureCapacity(int capacity)
Ensure that the internal byte array is at least of length capacity. If the byte array is null or its length is less than capacity, a new byte array of length capacity will be allocated. The contents of the array (between 0 and size) remain unchanged.

Parameters: capacity minimum length of internal byte array.

Returns: this ByteArrayWrapper

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

equals

public boolean equals(Object other)
Return true if the bytes in each wrapper are equal.

Parameters: other the object to compare to.

Returns: true if the two objects are equal.

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

hashCode

public int hashCode()
Return the hashcode.

Returns: the hashcode.

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

releaseBytes

public final byte[] releaseBytes()
Releases the internal byte array to the caller, resets the internal byte array to null and its size to 0.

Returns: internal byte array.

UNKNOWN: ICU 2.8

set

public final ByteArrayWrapper set(byte[] src, int start, int limit)
Set the internal byte array from offset 0 to (limit - start) with the contents of src from offset start to limit. If the byte array is null or its length is less than capacity, a new byte array of length (limit - start) will be allocated. This resets the size of the internal byte array to (limit - start).

Parameters: src source byte array to copy from start start offset of src to copy from limit end + 1 offset of src to copy from

Returns: this ByteArrayWrapper

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

toString

public String toString()
Returns string value for debugging

UNKNOWN: ICU 3.2 This API might change or be removed in a future release.

Copyright (c) 2006 IBM Corporation and others.