ByteArrayList

public class ByteArrayList
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.ByteArrayList


A class to represent a lightweight byte array. The goal of this class is to avoid the significant space overhead of using Java classes. See, for instance: http://benjchristensen.com/2008/05/27/java-memory-usage-ints/

Summary

Public constructors

ByteArrayList()

Constructs an empty list with an initial capacity of 128 bytes and growth factor of 2.0

ByteArrayList(int defaultSize)

Constructs an empty list with the specified initial capacity, and with a growth factor of 2.0

ByteArrayList(int defaultSize, float growthFactor)

Constructs an empty list with the specified initial capacity and growth factor

Public methods

boolean add(byte b)

Appends the specified element to the end of this list

boolean addAll(byte[] src)

Appends the full contents of the supplied byte[] to the list.

boolean addAll(byte[] src, int srcOffset, int length)

Appends the specified contents of the supplied byte[] to the list.

boolean addall(ByteArrayList src)

Appends the full contents of the supplied ByteArrayList to the list.

void clear()

Removes all of the elements from this list.

void ensureCapacity(int minCapacity)

Increases the capacity of this ByteArrayList instance, if necessary, to ensure that it can hold at least the number of bytes specified by the minimum capacity argument.

boolean equals(Object other)

byte get(int idx)

Returns the element at the specified position in this list

byte[] getContents()

Returns a copy of the contents of this ByteArrayList as a byte[].

int hashCode()

boolean isEmpty()

Returns true if this list contains no bytes

byte set(int idx, byte b)

Replaces the element at the specified position in this list with the specified element

int size()

Returns the number of bytes in this list

void trimToSize()

Trims the capacity of this ByteArrayList instance to be the list's current size.

Public constructors

ByteArrayList

public ByteArrayList ()

Constructs an empty list with an initial capacity of 128 bytes and growth factor of 2.0

ByteArrayList

public ByteArrayList (int defaultSize)

Constructs an empty list with the specified initial capacity, and with a growth factor of 2.0

Parameters
defaultSize int: The initial capacity of the list, in bytes

ByteArrayList

public ByteArrayList (int defaultSize, 
                float growthFactor)

Constructs an empty list with the specified initial capacity and growth factor

Parameters
defaultSize int: The initial capacity of the list, in bytes

growthFactor float: The factor by which the capacity is multiplied when the list needs to auto-resize. Must be >= 1.1f.

Public methods

add

public boolean add (byte b)

Appends the specified element to the end of this list

Parameters
b byte: The byte to append to the list

Returns
boolean true

addAll

public boolean addAll (byte[] src)

Appends the full contents of the supplied byte[] to the list.

Parameters
src byte: The byte[] to append contents from

Returns
boolean true

addAll

public boolean addAll (byte[] src, 
                int srcOffset, 
                int length)

Appends the specified contents of the supplied byte[] to the list.

Parameters
src byte: The byte[] to append contents from

srcOffset int: The index of first element of src to append

length int: The quantity of bytes to append to the list

Returns
boolean true

addall

public boolean addall (ByteArrayList src)

Appends the full contents of the supplied ByteArrayList to the list.

Parameters
src ByteArrayList: The ByteArrayList to append contents from

Returns
boolean true

clear

public void clear ()

Removes all of the elements from this list.

ensureCapacity

public void ensureCapacity (int minCapacity)

Increases the capacity of this ByteArrayList instance, if necessary, to ensure that it can hold at least the number of bytes specified by the minimum capacity argument.

Parameters
minCapacity int: The minimum capacity to ensure storage for, in bytes

equals

public boolean equals (Object other)

Parameters
other Object

Returns
boolean

get

public byte get (int idx)

Returns the element at the specified position in this list

Parameters
idx int: The index to return

Returns
byte

getContents

public byte[] getContents ()

Returns a copy of the contents of this ByteArrayList as a byte[].

Returns
byte[] A byte[] copy of the list contents

hashCode

public int hashCode ()

Returns
int

isEmpty

public boolean isEmpty ()

Returns true if this list contains no bytes

Returns
boolean

set

public byte set (int idx, 
                byte b)

Replaces the element at the specified position in this list with the specified element

Parameters
idx int: The index to replace

b byte: The byte to replace at that index

Returns
byte

size

public int size ()

Returns the number of bytes in this list

Returns
int

trimToSize

public void trimToSize ()

Trims the capacity of this ByteArrayList instance to be the list's current size.