Java Utililty Methods Byte Array Copy

List of utility methods to do Byte Array Copy

Description

The list of methods to do Byte Array Copy are organized into topic(s).

Method

byte[]copyByte(byte[] ASource, int nFrom, int nEnd)
copy Byte
if (nEnd < nFrom) {
    return null;
if (nEnd >= ASource.length) {
    nEnd = ASource.length - 1;
int j = 0;
byte[] sResult = new byte[nEnd - nFrom + 1];
...
byte[]copyByteArray(byte[] array2Copy)
copy Byte Array
if (array2Copy == null) {
    throw new IllegalArgumentException("Argument 'array2Copy' cannot be null");
return copyByteArray(array2Copy, 0, array2Copy.length);
byte[]copyByteArray(byte[] source)
copy Byte Array
byte[] buf = new byte[source.length];
System.arraycopy(source, 0, buf, 0, buf.length);
return buf;
voidcopyByteArray(final byte[] src, byte[] dest, int length)
Same as System.arraycopy(src, 0, dest, 0, length) .
System.arraycopy(src, 0, dest, 0, length);
byte[]copyBytes(byte[] arr, int length)
copy Bytes
byte[] newArr = null;
if (arr == null || arr.length == length) {
    newArr = arr;
} else {
    newArr = new byte[length];
    for (int i = 0; i < length; i++) {
        newArr[i] = (byte) arr[i];
return newArr;
voidcopyBytes(byte[] dst, int dstPos, int value)
copy Bytes
byte[] valueBytes = toByteArray(value);
System.arraycopy(valueBytes, 0, dst, dstPos, valueBytes.length);
voidcopyBytes(byte[] dstBytes, int dstFrom, byte[] srcBytes, int srcFrom, int len)
copy Bytes
for (int i = 0; i < len; i++) {
    dstBytes[dstFrom + i] = srcBytes[srcFrom + i];
byte[]copyBytes(byte[] from, byte[] to, int fromIndex)
Copy bytes completely from a source byte array to a destination byte array starting at the destination index
int counter = 0;
for (byte b : from) {
    to[fromIndex + counter] = b;
    ++counter;
return to;
byte[]copyBytes(byte[] from, int offset, int len)
Copy given length of bytes from a byte array to another byte array
byte[] to = new byte[len];
for (int i = 0; i < len; i++) {
    to[i] = from[offset + i];
return to;
voidcopyBytes(byte[] results, int offset, int int32)
copy Bytes
byte[] src = new byte[4];
src[0] = (byte) (int32 & 0xff);
src[1] = (byte) ((int32 >> 8) & 0xff);
src[2] = (byte) ((int32 >> 16) & 0xff);
src[3] = (byte) ((int32 >> 24) & 0xff);
copyBytes(results, offset, src, 4, 0);