Class Bytes
java.lang.Object
com.pnfsoftware.jeb.util.primitives.Bytes
Utility methods for
byte.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanequals(byte[] array1, byte[] array2) Compare byte arrays for equality.static booleanequals(byte[] array1, int pos1, byte[] array2, int pos2, int size) Compare byte-array ranges for equality.static intindexOf(byte[] array, byte[] target) Find the first occurrence of a sequence of bytes.static intindexOf(byte[] array, int from, byte[] target) Find the first occurrence of a sequence of bytes.static intindexOf(byte[] array, int from, int end, byte[] target, int targetFrom, int targetEnd, byte[] targetMask) Find the first occurrence of a sequence of bytes.static intlastIndexOf(byte[] array, byte[] target) Find the last occurrence of a sequence of bytes.static intlastIndexOf(byte[] array, int from, byte[] target) Find the last occurrence of a sequence of bytes.static intlastIndexOf(byte[] array, int from, byte[] target, byte[] targetMask) Find the last occurrence of a sequence of bytes.static StringtoUnsignedString(byte value) Convert a byte to its unsigned decimal string representation.
-
Constructor Details
-
Bytes
public Bytes()
-
-
Method Details
-
toUnsignedString
Convert a byte to its unsigned decimal string representation.- Parameters:
value- byte value- Returns:
- the unsigned decimal representation of
value
-
indexOf
public static int indexOf(byte[] array, byte[] target) Find the first occurrence of a sequence of bytes.- Parameters:
array- array to be searchedtarget- bytes to be found- Returns:
- index >= 0, or -1 if not found
-
indexOf
public static int indexOf(byte[] array, int from, byte[] target) Find the first occurrence of a sequence of bytes.- Parameters:
array- array to be searchedfrom- start index in arraytarget- bytes to be found- Returns:
- index >= `from`, or -1 if not found
-
indexOf
public static int indexOf(byte[] array, int from, int end, byte[] target, int targetFrom, int targetEnd, byte[] targetMask) Find the first occurrence of a sequence of bytes.- Parameters:
array- array to be searchedfrom- start of searchend- end of search (exclusive)target- bytes to be foundtargetFrom- actual first target byte in the target arraytargetEnd- actual end (exclusive) target byte in the target arraytargetMask- optional binary mask, must be the same length as the target if present; the indicestargetFromandtargetEndapply as well- Returns:
- index
>= fromand< end, or -1 if not found
-
lastIndexOf
public static int lastIndexOf(byte[] array, byte[] target) Find the last occurrence of a sequence of bytes.- Parameters:
array- array to be searchedtarget- bytes to be found- Returns:
- index >= 0, or -1 if not found
-
lastIndexOf
public static int lastIndexOf(byte[] array, int from, byte[] target) Find the last occurrence of a sequence of bytes.- Parameters:
array- array to be searchedfrom- will search backward from this indextarget- bytes to be found- Returns:
- index
<= from, or -1 if not found
-
lastIndexOf
public static int lastIndexOf(byte[] array, int from, byte[] target, byte[] targetMask) Find the last occurrence of a sequence of bytes.- Parameters:
array- array to be searchedfrom- will search backward from this indextarget- bytes to be foundtargetMask- optional binary mask, must be the same length as the target if present- Returns:
- index
<= from, or -1 if not found
-
equals
public static boolean equals(byte[] array1, int pos1, byte[] array2, int pos2, int size) Compare byte-array ranges for equality.- Parameters:
array1- first byte arraypos1- start offset in the first arrayarray2- second byte arraypos2- start offset in the second arraysize- number of bytes to compare- Returns:
- true if the byte ranges are equal
-
equals
public static boolean equals(byte[] array1, byte[] array2) Compare byte arrays for equality.- Parameters:
array1- first byte array, may be nullarray2- second byte array, may be null- Returns:
- true if both arrays are null or contain the same bytes
-