|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sourceforge.jcapi.util.ByteArray
ByteArray
encapsulates an array of bytes.
It offers several methods for byte-arrays useful to read or generate
datastreams.
© 2002 Holger Gräfe
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Contact to author: holger.graefe@gmx.de
Project website: http://jcapi.sourceforge.net
Constructor Summary | |
ByteArray()
creates an empty ByteArray. |
|
ByteArray(byte[] ba)
creates an ByteArray "around" the given array of bytes. |
|
ByteArray(ByteArray BA,
int beginIndex)
creates an ByteArray with a copy the last elements of another ByteArray. |
|
ByteArray(ByteArray BA,
int beginIndex,
int count)
creates an ByteArray with a copy of some elements of another ByteArray. |
|
ByteArray(int count)
creates an ByteArray with the specified number of elements. |
|
ByteArray(java.lang.String s)
creates an ByteArray with the byte array presentation of the given string. |
Method Summary | |
byte |
byteAt(int index)
returns the byte at the given index. |
java.lang.Object |
clone()
|
static int |
compare(byte[] ba1,
byte[] ba2)
compares two arrays of bytes. |
ByteArray |
concat(byte[] ba)
creates a new ByteArray of a copy of this and the given bytes. |
ByteArray |
concat(ByteArray BA)
creates a new ByteArray of a copy of this and the given ByteArray. |
static void |
copyBytes(byte[] source,
byte[] target)
copies all bytes from one array to another. |
static void |
copyBytes(byte[] source,
byte[] target,
int targetIndex)
copies all bytes from one array to another. |
static void |
copyBytes(byte[] source,
int srcIndex,
int count,
byte[] target)
copies selected bytes from one array to the first bytes of another. |
static void |
copyBytes(byte[] source,
int srcIndex,
int count,
byte[] target,
int targetIndex)
copies selected bytes from one array to another. |
boolean |
equals(java.lang.Object BA)
|
byte[] |
getBytes()
returns the byte array capsulated by this ByteArray (as reference). |
static byte[] |
getBytes(byte[] source,
int srcIndex)
returns a new array with selected bytes from the given array. |
static byte[] |
getBytes(byte[] source,
int srcIndex,
int count)
returns a new array with selected bytes from the given array. |
static int |
getHighOrderInt(byte[] source,
int srcIndex,
int count)
returns the numerical value of the big endian byte[] -presentation.
|
static long |
getHighOrderLong(byte[] source,
int srcIndex,
int count)
returns the numerical value of the big endian byte[] -presentation.
|
static int |
getLowOrderInt(byte[] source,
int srcIndex,
int count)
returns the numerical value of the little endian byte[] -presentation.
|
static long |
getLowOrderLong(byte[] source,
int srcIndex,
int count)
returns the numerical value of the little endian byte[] -presentation.
|
int |
hashCode()
|
static java.lang.String |
hexString(byte[] binArray)
generates an hexadecimal presentation of a byte array. |
static java.lang.String |
hexString(byte[] binArray,
int beginIndex,
int endIndex)
generates an hexadecimal presentation of a byte array. |
static java.lang.String |
hexString(byte[] binArray,
int beginIndex,
int endIndex,
java.lang.String separator)
generates an hexadecimal presentation of a byte array. |
static java.lang.String |
hexString(byte[] binArray,
java.lang.String separator)
generates an hexadecimal presentation of a byte array. |
static byte[] |
highOrderBytes(long value)
returns the big endian byte[4] -presentation of a numerical value.
|
static byte[] |
highOrderBytes(long lvalue,
int numBytes)
returns the big endian byte[] -presentation of a numerical value.
|
int |
highOrderIntAt(int beginIndex)
returns the numerical value of the big endian byte[4] -presentation.
|
int |
highOrderIntAt(int beginIndex,
int count)
returns the numerical value of the big endian byte[] -presentation.
|
int |
indexOf(byte searchByte)
searches the occurance of a byte inside this ByteArray. |
int |
indexOf(byte[] search)
searches the occurance of a byte array inside this ByteArray. |
int |
indexOf(byte[] search,
int beginIndex)
searches the occurance of a byte array inside this ByteArray. |
int |
indexOf(java.lang.String search)
searches the occurance of the bytes of the given string inside this ByteArray. |
int |
indexOf(java.lang.String search,
int beginIndex)
searches the occurance of the bytes of the given string inside this ByteArray. |
int |
lastIndexOf(byte searchByte)
searches the last occurance of a byte inside this ByteArray. |
int |
lastIndexOf(byte[] search)
searches the last occurance of a byte array inside this ByteArray. |
int |
lastIndexOf(byte[] search,
int beginIndex)
searches the last occurance of a byte array inside this ByteArray. |
int |
lastIndexOf(java.lang.String search)
searches the last occurance of the bytes of the given string inside this ByteArray. |
int |
lastIndexOf(java.lang.String search,
int beginIndex)
searches the last occurance of the bytes of the given string inside this ByteArray. |
int |
length()
returns the number of bytes in this ByteArray |
static byte[] |
lowOrderBytes(long value)
returns the little endian byte[4] -presentation of a numerical value.
|
static byte[] |
lowOrderBytes(long lvalue,
int numBytes)
returns the little endian byte[] -presentation of a numerical value.
|
int |
lowOrderIntAt(int beginIndex)
returns the numerical value of the little endian byte[4] -presentation.
|
int |
lowOrderIntAt(int beginIndex,
int count)
returns the numerical value of the little endian byte[] -presentation.
|
static java.lang.String |
octalString(byte[] binArray,
int beginIndex,
int endIndex,
java.lang.String separator)
generates an octal presentation of a byte array. |
static byte[] |
parseHex(java.lang.String hex)
parses a string of hexadecimal digits into an new byte array. |
static int |
search(byte[] byteArray,
byte[] searchArray)
searches the occurance of a byte array inside another. |
static int |
search(byte[] byteArray,
byte[] searchArray,
int beginIndex)
searches the occurance of a byte array inside another. |
static int |
search(byte[] byteArray,
byte[] searchArray,
int beginIndex,
boolean reverse)
searches the occurance of a byte array inside another. |
java.lang.String |
toHexString()
generates an hexadecimal presentation of the ByteArray. |
java.lang.String |
toHexString(java.lang.String separator)
generates an hexadecimal presentation of the ByteArray. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public ByteArray()
public ByteArray(int count)
count
- number of elementspublic ByteArray(byte[] ba)
ba
- array of bytes. This is not copied but referenced as object.public ByteArray(java.lang.String s)
s
- the string to get the bytes from.public ByteArray(ByteArray BA, int beginIndex, int count)
BA
- the ByteArray to get the bytes from.beginIndex
- the first byte to be copied.count
- the number of bytes to be copied.public ByteArray(ByteArray BA, int beginIndex)
BA
- the ByteArray to get the bytes from.beginIndex
- the first byte to be copied.Method Detail |
public static java.lang.String hexString(byte[] binArray, int beginIndex, int endIndex, java.lang.String separator)
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
binArray
- the byte arraybeginIndex
- first byte to be written to output stringendIndex
- first byte not to be writtenseparator
- string to be inserted between the hexadecimal presentation of
the bytespublic static java.lang.String octalString(byte[] binArray, int beginIndex, int endIndex, java.lang.String separator)
Integer.toOctalString()
binArray
- the byte arraybeginIndex
- first byte to be written to output stringendIndex
- first byte not to be writtenseparator
- string to be inserted between the octal presentation of
the bytespublic static java.lang.String hexString(byte[] binArray, int beginIndex, int endIndex)
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
binArray
- the byte arraybeginIndex
- first byte to be written to output stringendIndex
- first byte not to be writtenpublic static java.lang.String hexString(byte[] binArray, java.lang.String separator)
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
binArray
- the byte arrayseparator
- string to be inserted between the hexadecimal presentation of
the bytespublic static java.lang.String hexString(byte[] binArray)
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
binArray
- the byte arraypublic static byte[] lowOrderBytes(long lvalue, int numBytes)
byte[]
-presentation of a numerical value.
This means the first byte in the array to hold the bits 2^0 to 2^7 of
the value
and so on.value
- the numeric value to be splitted in bytesnumBytes
- the number of bytes in the resulting array. It is not
checked if the given value 'fits' this array.public static byte[] lowOrderBytes(long value)
byte[4]
-presentation of a numerical value.
This means the first byte in the array to hold the bits 2^0 to 2^7 of
the value
and so on.value
- the numeric value to be splitted in 4 bytespublic static byte[] highOrderBytes(long lvalue, int numBytes)
byte[]
-presentation of a numerical value.
This means the first byte in the array to hold
value>>(8*(numBytes-1))
and so on.value
- the numeric value to be splitted in bytesnumBytes
- the number of bytes in the resulting array. It is not
checked if the given value 'fits' this array.public static byte[] highOrderBytes(long value)
byte[4]
-presentation of a numerical value.
This means the first byte in the array to hold
value>>24
and so on.value
- the numeric value to be splitted in 4 bytespublic static void copyBytes(byte[] source, int srcIndex, int count, byte[] target, int targetIndex)
source
- the source arraysrcIndex
- the index of the first byte in the source arraycount
- the number of bytes to be copiedtarget
- the target arraytargetIndex
- the index where the first byte is to be placed in the target arraypublic static void copyBytes(byte[] source, byte[] target, int targetIndex)
source
- the source arraytarget
- the target arraytargetIndex
- the index where the first byte is to be placed in the target arraypublic static void copyBytes(byte[] source, int srcIndex, int count, byte[] target)
source
- the source arraysrcIndex
- the index of the first byte in the source arraycount
- the number of bytes to be copiedtarget
- the target arraypublic static void copyBytes(byte[] source, byte[] target)
source
- the source arraytarget
- the target arraypublic static byte[] getBytes(byte[] source, int srcIndex, int count)
source
- the source arraysrcIndex
- the index of the first byte in the source arraycount
- the number of bytes to be copiedpublic static byte[] getBytes(byte[] source, int srcIndex)
source
- the source arraysrcIndex
- the index of the first byte in the source arraypublic static int getHighOrderInt(byte[] source, int srcIndex, int count)
byte[]
-presentation.
This means the first byte in the array to be interpreted as
returnValue>>(8*(numBytes-1))
and so on.source
- the array containig the big endian presentationsrcIndex
- the index of the first (most significant) bytecount
- the number of bytes to be interpretedpublic static int getLowOrderInt(byte[] source, int srcIndex, int count)
byte[]
-presentation.
This means the first byte in the array to be interpreted as the bits 2^0 to 2^7 of
the return value and so on.source
- the array containig the little endian presentationsrcIndex
- the index of the first (least significant) bytecount
- the number of bytes to be interpretedpublic static long getHighOrderLong(byte[] source, int srcIndex, int count)
byte[]
-presentation.
This means the first byte in the array to be interpreted as
returnValue>>(8*(numBytes-1))
and so on.source
- the array containig the big endian presentationsrcIndex
- the index of the first (most significant) bytecount
- the number of bytes to be interpretedpublic static long getLowOrderLong(byte[] source, int srcIndex, int count)
byte[]
-presentation.
This means the first byte in the array to be interpreted as the bits 2^0 to 2^7 of
the return value and so on.source
- the array containig the little endian presentationsrcIndex
- the index of the first (least significant) bytecount
- the number of bytes to be interpretedpublic static byte[] parseHex(java.lang.String hex)
hexString
- the string of hexadecimal digitspublic static int compare(byte[] ba1, byte[] ba2)
ba1
- the first byte arrayba2
- the second byte arraypublic static int search(byte[] byteArray, byte[] searchArray, int beginIndex, boolean reverse)
byteArray
- the array to search insearchArray
- the array to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchreverse
- true
for reverse searchreverse=false
) or
last (reverse=true
) occurance of the searched bytes
or -1 for no match.public static int search(byte[] byteArray, byte[] searchArray, int beginIndex)
byteArray
- the array to search insearchArray
- the array to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchpublic static int search(byte[] byteArray, byte[] searchArray)
byteArray
- the array to search insearchArray
- the array to search for. If this is empty the result will be 0.public int length()
public java.lang.String toHexString()
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
public java.lang.String toHexString(java.lang.String separator)
Interger.valueOf(String s,int radix)
compatible).
This method uses a 'fast' implemenatation instead of calling
Integer.toHexString()
separator
- string to be inserted between the hexadecimal presentation of
the bytespublic java.lang.String toString()
toString
in class java.lang.Object
public byte[] getBytes()
public ByteArray concat(ByteArray BA)
BA
- the bytes of this ByteArray will be put at the end of the new ByteArraypublic ByteArray concat(byte[] ba)
ba
- this bytes will be put at the end of the new ByteArraypublic byte byteAt(int index)
index
- the position of the byte to be returned.public int indexOf(byte[] search)
search
- the array to search for. If this is empty the result will be 0.public int indexOf(java.lang.String search)
search
- the string to search for. If this is empty the result will be 0.public int indexOf(byte[] search, int beginIndex)
search
- the array to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchpublic int indexOf(java.lang.String search, int beginIndex)
search
- the string to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchpublic int indexOf(byte searchByte)
searchByte
- the byte to search for.public int lastIndexOf(byte[] search)
search
- the array to search for. If this is empty the result will be 0.public int lastIndexOf(java.lang.String search)
search
- the string to search for. If this is empty the result will be 0.public int lastIndexOf(byte[] search, int beginIndex)
search
- the array to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchpublic int lastIndexOf(java.lang.String search, int beginIndex)
search
- the string to search for. If this is empty the result will be
the value of beginIndex
.beginIndex
- the position in byteArray
to start searchpublic int lastIndexOf(byte searchByte)
searchByte
- the byte to search for.public int lowOrderIntAt(int beginIndex)
byte[4]
-presentation.
This means the first selected byte to be interpreted as the bits 2^0 to 2^7 of
the return value and so on.beginIndex
- the index of the first (least significant) bytepublic int lowOrderIntAt(int beginIndex, int count)
byte[]
-presentation.
This means the first selected byte to be interpreted as the bits 2^0 to 2^7 of
the return value and so on.beginIndex
- the index of the first (least significant) bytecount
- the number of bytes to be interpretedpublic int highOrderIntAt(int beginIndex)
byte[4]
-presentation.
This means the first selected byte to be interpreted as
returnValue>>(8*(numBytes-1))
and so on.beginIndex
- the index of the first (most significant) bytepublic int highOrderIntAt(int beginIndex, int count)
byte[]
-presentation.
This means the first selected byte to be interpreted as
returnValue>>(8*(numBytes-1))
and so on.beginIndex
- the index of the first (most significant) bytecount
- the number of bytes to be interpretedpublic boolean equals(java.lang.Object BA)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |