Package com.reve.utils.bytearray
Class ByteArray
java.lang.Object
com.reve.utils.bytearray.ByteArrayInterface
com.reve.utils.bytearray.ByteArray
- All Implemented Interfaces:
Reusable,Serializable
Traditional byte array can have three properties, byte [] data, int offset, and int length.
This class is primarily aimed to put these three parameters togather.
- See Also:
-
Field Summary
Fields inherited from class com.reve.utils.bytearray.ByteArrayInterface
data, hashBuffer, length, offset -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ByteArray(byte[] p_data) Create a byte array of specified length and provided array.ByteArray(byte[] p_data, int offset, int length) Create a byte array of specified length and provided array.ByteArray(int length) Create a byte array of specified length. -
Method Summary
Modifier and TypeMethodDescriptionappend(byte b) Append the byte value into thisByteArrayappend(byte[] data) Append the content of the given byte [] into this instance.append(byte[] a, int p_offset, int p_length) Append the given byte array data to this instance.append(char ch) append all the chars to this instance ofByteArrayappend(char... str) append all the chars to this instance ofByteArrayappend(int n) Append the integer value as printable characters into thisByteArrayCopy the content of the given parameter and append them at the end of this instance.Append the string value in thisByteArray.appendAsHexString(byte[] data, int offset, int length) Append the given byte array as hex char at the end of thisByteArrayInterface.appendRandomHexChars(int length) Append some random hex char at the end of thisByteArrayInterfacecopy(byte[] other) Copy the content from other byte [] to this instance.copy(byte[] data, int offset, int length) Copy the content from otherByteArrayto this instance.Copy the content from otherByteArrayto this instance.Copy the string data to this instance.intGet the current length of thisByteArrayinthashCode()Generate the hash code for this instance.voidreset()Reset the byte array to initial value.toString()Methods inherited from class com.reve.utils.bytearray.ByteArrayInterface
equals, equals
-
Constructor Details
-
ByteArray
public ByteArray()Default constructor. -
ByteArray
public ByteArray(int length) Create a byte array of specified length.- Parameters:
length- a byte array will be allocated for this length.
-
ByteArray
public ByteArray(byte[] p_data) Create a byte array of specified length and provided array.- Parameters:
p_data- a byte array will be allowed with this length and content will be copied.
-
ByteArray
public ByteArray(byte[] p_data, int offset, int length) Create a byte array of specified length and provided array.- Parameters:
p_data- a byte array will be allowed with thisoffset- from where the data will be copiedlength- the length of the content will be copied.
-
-
Method Details
-
reset
public void reset()Reset the byte array to initial value.- Specified by:
resetin interfaceReusable- Specified by:
resetin classByteArrayInterface
-
copy
Copy the content from otherByteArrayto this instance. Old content of this instance will be overwritten.- Parameters:
other- Content of this instance will be copied here.- Returns:
- this instance after copy is done.
-
copy
Copy the content from other byte [] to this instance. Old content of this instance will be overwritten.- Specified by:
copyin classByteArrayInterface- Parameters:
other- Content of this instance will be copied here.- Returns:
- this instance after copy is done.
-
copy
Copy the content from otherByteArrayto this instance.- Specified by:
copyin classByteArrayInterface- Parameters:
data- Content of this instance will be copied here.offset- starting index of source byte array.length- length of the source byte array.- Returns:
- this instance after copy is done.
-
copy
Copy the string data to this instance. Old content of this instance will be overwritten.- Specified by:
copyin classByteArrayInterface- Parameters:
data- Content of this instance will be copied here.- Returns:
- this instance after copy is done.
-
append
Append the content of the given byte [] into this instance. Content will be appended at the end of this instance.- Specified by:
appendin classByteArrayInterface- Parameters:
data- content of this byte [] will be copied.- Returns:
- the
-
append
Append the string value in thisByteArray. ASCII byte of each char will be added.- Specified by:
appendin classByteArrayInterface- Parameters:
str- The value to be appended.- Returns:
- the instance of this
ByteArray
-
append
append all the chars to this instance ofByteArray- Specified by:
appendin classByteArrayInterface- Parameters:
ch- char to be appended into this instance.- Returns:
- the instance of this
ByteArray
-
append
append all the chars to this instance ofByteArray- Specified by:
appendin classByteArrayInterface- Parameters:
str- multiple chars to be appended into this instance.- Returns:
- the instance of this
ByteArray
-
appendRandomHexChars
Append some random hex char at the end of thisByteArrayInterface- Specified by:
appendRandomHexCharsin classByteArrayInterface- Parameters:
length- Number of hex char to be added.- Returns:
- the instance of this
ByteArrayInterface
-
appendAsHexString
Append the given byte array as hex char at the end of thisByteArrayInterface. For example if the given byte [] contains word 'hello' into it, the byte array data = {68, 65, 6c, 6c, 6f} after calling this method it will append '68656c6f' at the end of thisByteArrayInterfaceso after adding this instance will contain data = {36 38 36 35 36 63 36 63 36 66}- Specified by:
appendAsHexStringin classByteArrayInterface- Parameters:
data- byte array whose data will be appended as hex string.offset- starting index of byte [] to be appended into thislength- length of the given byte array to be appended as hex string.- Returns:
- the instance of this
ByteArrayInterface
-
getLength
public int getLength()Get the current length of thisByteArray- Specified by:
getLengthin classByteArrayInterface- Returns:
- the current length of this
ByteArray
-
append
Append the byte value into thisByteArray- Specified by:
appendin classByteArrayInterface- Parameters:
b- byte value to be appended
-
append
Append the integer value as printable characters into thisByteArray- Specified by:
appendin classByteArrayInterface- Parameters:
n- Integer value to be appended
-
append
Append the given byte array data to this instance.- Specified by:
appendin classByteArrayInterface- Parameters:
a- byte array to be appended.p_offset- starting index of the byte array to be appended.p_length- length of the byte array to be appended.- Returns:
- the instance of this
ByteArray
-
append
Copy the content of the given parameter and append them at the end of this instance.- Specified by:
appendin classByteArrayInterface- Parameters:
p- content of this parameter will be appended here.- Returns:
- the instance of this
ByteArray
-
hashCode
public int hashCode()Generate the hash code for this instance. -
toString
- Specified by:
toStringin classByteArrayInterface
-