public final class ByteUtils extends Object
byte
arrays.Modifier and Type | Method and Description |
---|---|
static byte[] |
concat(byte[] array1,
byte[] array2)
Concatenate the given
byte arrays into one, with overlapping array elements included twice. |
static byte[] |
concatAll(byte[]... arrays)
Concatenate the given
byte arrays into one, with overlapping array elements included twice. |
static byte[] |
extractBytes(ByteBuffer buffer)
Extract/Transfer bytes from the given
ByteBuffer into an array by duplicating the buffer and fetching its
content. |
static ByteBuffer |
getByteBuffer(String theString)
|
static ByteBuffer |
getByteBuffer(String theString,
Charset charset)
|
static byte[] |
getBytes(ByteBuffer byteBuffer)
Extract a byte array from
ByteBuffer without consuming it. |
static int |
indexOf(byte[] haystack,
byte needle)
Searches the specified array of bytes for the specified value.
|
static byte[][] |
mergeArrays(byte[] firstArray,
byte[]... additionalArrays)
Merge multiple
byte arrays into one array |
static byte[][] |
split(byte[] source,
int c)
Split
source into partitioned arrays using delimiter c . |
static boolean |
startsWith(byte[] haystack,
byte[] prefix)
Tests if the
haystack starts with the given prefix . |
static boolean |
startsWith(byte[] haystack,
byte[] prefix,
int offset)
Tests if the
haystack beginning at the specified offset starts with the given prefix . |
public static byte[] concat(byte[] array1, byte[] array2)
byte
arrays into one, with overlapping array elements included twice.
The order of elements in the original arrays is preserved.array1
- the first array.array2
- the second array.public static byte[] concatAll(byte[]... arrays)
byte
arrays into one, with overlapping array elements included twice. Returns a new,
empty array if arrays
was empty and returns the first array if arrays
contains only a single array.
The order of elements in the original arrays is preserved.arrays
- the arrays.public static byte[][] split(byte[] source, int c)
source
into partitioned arrays using delimiter c
.source
- the source array.c
- delimiter.public static byte[][] mergeArrays(byte[] firstArray, byte[]... additionalArrays)
byte
arrays into one arrayfirstArray
- must not be nulladditionalArrays
- must not be nullpublic static byte[] getBytes(ByteBuffer byteBuffer)
ByteBuffer
without consuming it.byteBuffer
- must not be null.public static boolean startsWith(byte[] haystack, byte[] prefix)
haystack
starts with the given prefix
.haystack
- the source to scan.prefix
- the prefix to find.haystack
at position offset
starts with prefix
.startsWith(byte[], byte[], int)
public static boolean startsWith(byte[] haystack, byte[] prefix, int offset)
haystack
beginning at the specified offset
starts with the given prefix
.haystack
- the source to scan.prefix
- the prefix to find.offset
- the offset to start at.haystack
at position offset
starts with prefix
.public static int indexOf(byte[] haystack, byte needle)
haystack
s natural order or -1
of needle
could not be found.haystack
- the source to scan.needle
- the value to scan for.public static ByteBuffer getByteBuffer(String theString)
theString
- must not be null.public static ByteBuffer getByteBuffer(String theString, Charset charset)
theString
- must not be null.charset
- must not be null.public static byte[] extractBytes(ByteBuffer buffer)
ByteBuffer
into an array by duplicating the buffer and fetching its
content.buffer
- must not be null.Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.