Top Description Fields Constructors Methods
com.ibm.icu.util

public Class ByteArrayWrapper

extends Object
implements Comparable<ByteArrayWrapper>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
com.ibm.icu.text.RawCollationKey
Imports
java.nio.ByteBuffer, com.ibm.icu.impl.Utility

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
ICU Status
Stable since ICU 2.8.

Field Summary

Modifier and TypeField and Description
public byte[]
bytes

Internal byte array.

public int
size

Size of the internal byte array used.

Constructor Summary

AccessConstructor and Description
public
ByteArrayWrapper()

Construct a new ByteArrayWrapper with no data.

public
ByteArrayWrapper(byte[]
the byte array to adopt
bytesToAdopt
,
int
the length of valid data in the byte array
size
)

Construct a new ByteArrayWrapper from a byte array and size

public
ByteArrayWrapper(ByteBuffer
the ByteBuffer from which to get the data.
source
)

Construct a new ByteArrayWrapper from the contents of a ByteBuffer.

Method Summary

Modifier and TypeMethod and Description
public final ByteArrayWrapper

Returns:

this ByteArrayWrapper
append
(byte[]
source byte array to copy from
src
,
int
start offset of src to copy from
start
,
int
end + 1 offset of src to copy from
limit
)

Appends the internal byte array from offset size with the contents of src from offset start to limit.

public int

Returns:

a value <0, 0, or >0 as this compares less than, equal to, or greater than other.
compareTo
(ByteArrayWrapper
the object to compare to.
other
)

Implements java.lang.Comparable.compareTo.

Compare this object to another ByteArrayWrapper, which must not be null.
private static final void
copyBytes(byte[]
source byte array to copy from
src
,
int
start offset of src to copy from
srcoff
,
byte[]
target byte array to copy to
tgt
,
int
start offset of tgt to copy to
tgtoff
,
int
size of contents to copy
length
)

Copies the contents of src byte array from offset srcoff to the target of tgt byte array at the offset tgtoff.

public ByteArrayWrapper

Returns:

this ByteArrayWrapper
ensureCapacity
(int
minimum length of internal byte array.
capacity
)

Ensure that the internal byte array is at least of length capacity.

public boolean

Returns:

true if the two objects are equal.
equals
(Object
the object to compare to.
other
)

Overrides java.lang.Object.equals.

Return true if the bytes in each wrapper are equal.
public int

Returns:

the hashcode.
hashCode
()

Overrides java.lang.Object.hashCode.

Return the hashcode.
public final byte[]

Returns:

internal byte array.
releaseBytes
()

Releases the internal byte array to the caller, resets the internal byte array to null and its size to 0.

public final ByteArrayWrapper

Returns:

this ByteArrayWrapper
set
(byte[]
source byte array to copy from
src
,
int
start offset of src to copy from
start
,
int
end + 1 offset of src to copy from
limit
)

Set the internal byte array from offset 0 to (limit - start) with the contents of src from offset start to limit.

public String
toString()

Overrides java.lang.Object.toString.

Returns string value for debugging
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

bytesback to summary
public byte[] bytes

Internal byte array.

ICU Status
Stable since ICU 2.8.
sizeback to summary
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().

ICU Status
Stable since ICU 2.8.

Constructor Detail

ByteArrayWrapperback to summary
public ByteArrayWrapper()

Construct a new ByteArrayWrapper with no data.

ICU Status
Stable since ICU 2.8.
ByteArrayWrapperback to summary
public ByteArrayWrapper(byte[] bytesToAdopt, int size)

Construct a new ByteArrayWrapper from a byte array and size

Parameters
bytesToAdopt:byte[]

the byte array to adopt

size:int

the length of valid data in the byte array

Exceptions
IndexOutOfBoundsException:
if bytesToAdopt == null and size != 0, or size < 0, or size > bytesToAdopt.length.
ICU Status
Stable since ICU 3.2.
ByteArrayWrapperback to summary
public ByteArrayWrapper(ByteBuffer source)

Construct a new ByteArrayWrapper from the contents of a ByteBuffer.

Parameters
source:ByteBuffer

the ByteBuffer from which to get the data.

ICU Status
Stable since ICU 3.2.

Method Detail

appendback to summary
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:byte[]

source byte array to copy from

start:int

start offset of src to copy from

limit:int

end + 1 offset of src to copy from

Returns:ByteArrayWrapper

this ByteArrayWrapper

ICU Status
Stable since ICU 3.2.
compareToback to summary
public int compareTo(ByteArrayWrapper other)

Implements java.lang.Comparable.compareTo.

Compare this object to another ByteArrayWrapper, which must not be null.

Parameters
other:ByteArrayWrapper

the object to compare to.

Returns:int

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

Annotations
@Override
Exceptions
ClassCastException:
if the other object is not a ByteArrayWrapper
ICU Status
Stable since ICU 4.4.
copyBytesback to summary
private static final void copyBytes(byte[] src, int srcoff, byte[] tgt, int tgtoff, int length)

Copies the contents of src byte array from offset srcoff to the target of tgt byte array at the offset tgtoff.

Parameters
src:byte[]

source byte array to copy from

srcoff:int

start offset of src to copy from

tgt:byte[]

target byte array to copy to

tgtoff:int

start offset of tgt to copy to

length:int

size of contents to copy

ensureCapacityback to summary
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:int

minimum length of internal byte array.

Returns:ByteArrayWrapper

this ByteArrayWrapper

ICU Status
Stable since ICU 3.2.
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Return true if the bytes in each wrapper are equal.

Parameters
other:Object

the object to compare to.

Returns:boolean

true if the two objects are equal.

Annotations
@Override
ICU Status
Stable since ICU 2.8.
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Return the hashcode.

Returns:int

the hashcode.

Annotations
@Override
ICU Status
Stable since ICU 2.8.
releaseBytesback to summary
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:byte[]

internal byte array.

ICU Status
Stable since ICU 2.8.
setback to summary
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:byte[]

source byte array to copy from

start:int

start offset of src to copy from

limit:int

end + 1 offset of src to copy from

Returns:ByteArrayWrapper

this ByteArrayWrapper

ICU Status
Stable since ICU 3.2.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns string value for debugging

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
ICU Status
Stable since ICU 2.8.