Package org.yamcs.utils
Class ByteArray
- java.lang.Object
-
- org.yamcs.utils.ByteArray
-
public class ByteArray extends Object
byte array which grows and also supports writing/reading int, double, etc. All non byte operations are big endian.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CAPACITY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(byte x)
add value to the arrayvoid
add(byte[] v)
void
addDouble(double x)
void
addInt(int x)
void
addLong(long x)
void
addNullTerminatedUTF(String v)
Writes a string encoded in UTF as perDataOutputStream.writeUTF(String)
terminated with a null charactervoid
addShort(short x)
void
addSizePrefixedProto(com.google.protobuf.MessageLite msg)
Writes a protobuf message to the buffer.void
addSizePrefixedUTF(String v)
Writes a string preceded by its size in two bytes big endian.byte[]
array()
get the backing arrayvoid
ensureRemaining(int size)
boolean
equals(Object obj)
byte
get()
void
get(byte[] bp)
byte
get(int pos)
get element at positiondouble
getDouble()
int
getInt()
long
getLong()
String
getNullTerminatedUTF()
short
getShort()
<T extends com.google.protobuf.MessageLite.Builder>
voidgetSizePrefixedProto(T builder)
String
getSizePrefixedUTF()
int
indexOf(byte x)
Returns the index of the first occurrence of the specified element in the array, or -1 if the array does not contain the element.void
insert(int pos, byte x)
boolean
isEmpty()
int
position()
void
reset()
void
reset(int length)
void
set(int pos, byte x)
int
size()
byte[]
toArray()
String
toString()
static ByteArray
wrap(byte... array)
Creates the ByteArray with the backing array
-
-
-
Method Detail
-
wrap
public static ByteArray wrap(byte... array)
Creates the ByteArray with the backing array- Parameters:
array
-- Returns:
- a new object containing all the values from the passed array
-
ensureRemaining
public void ensureRemaining(int size)
-
add
public void add(byte x)
add value to the array- Parameters:
x
- - value to be added
-
addShort
public void addShort(short x)
-
addInt
public void addInt(int x)
-
addLong
public void addLong(long x)
-
add
public void add(byte[] v)
-
addDouble
public void addDouble(double x)
-
addSizePrefixedProto
public void addSizePrefixedProto(com.google.protobuf.MessageLite msg)
Writes a protobuf message to the buffer. The message will be prefixed by its size in 4 bytes big endian.- Parameters:
msg
-
-
addSizePrefixedUTF
public void addSizePrefixedUTF(String v)
Writes a string preceded by its size in two bytes big endian.The encoded byte array does not contain null characters
- Parameters:
v
-- See Also:
DataOutputStream.writeUTF(String)
-
addNullTerminatedUTF
public void addNullTerminatedUTF(String v)
Writes a string encoded in UTF as perDataOutputStream.writeUTF(String)
terminated with a null character- Parameters:
v
-
-
insert
public void insert(int pos, byte x)
-
set
public void set(int pos, byte x)
-
get
public byte get()
-
getShort
public short getShort()
-
getInt
public int getInt()
-
getLong
public long getLong()
-
getDouble
public double getDouble()
-
getSizePrefixedUTF
public String getSizePrefixedUTF() throws IOException
- Throws:
IOException
-
getNullTerminatedUTF
public String getNullTerminatedUTF() throws IOException
- Throws:
IOException
-
get
public void get(byte[] bp)
-
getSizePrefixedProto
public <T extends com.google.protobuf.MessageLite.Builder> void getSizePrefixedProto(T builder)
-
get
public byte get(int pos)
get element at position- Parameters:
pos
-- Returns:
- the element at the specified position
-
isEmpty
public boolean isEmpty()
-
toArray
public byte[] toArray()
- Returns:
- a copy of the underlying byte array with the current length
-
size
public int size()
-
indexOf
public int indexOf(byte x)
Returns the index of the first occurrence of the specified element in the array, or -1 if the array does not contain the element.- Parameters:
x
- element which is searched for- Returns:
- the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
-
reset
public void reset()
-
reset
public void reset(int length)
-
array
public byte[] array()
get the backing array- Returns:
- the backing array
-
position
public int position()
-
-