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

voidcopyBytes(byte[] source, byte[] dest, int sourceFrom, int copyLength, int destFrom)
copy Bytes
sourceFrom = sourceFrom - 1;
destFrom = destFrom - 1;
for (int i = destFrom; i < destFrom + copyLength; i++) {
    dest[i] = source[sourceFrom++];
byte[]copyBytes(byte[] src)
copy Bytes
byte[] copy = new byte[src.length];
for (int i = 0; i < src.length; i++) {
    copy[i] = src[i];
return copy;
voidcopyBytes(byte[] src, byte[] target)
Copies the contents of src into target.
System.arraycopy(src, 0, target, 0, src.length);
byte[]copyBytes(byte[] src, int start, int end)
Copy bytes from src to dest, if they are available in src
int length = end - start;
byte[] dest = new byte[length];
for (int i = 0; i < length && i < src.length; i++) {
    dest[i] = src[i - start];
return dest;
intcopyBytes(final byte[] source, final int sOffset, final byte[] destination, final int dOffset, final int length)
copy Bytes
requireSourceLength(source, sOffset, length);
requireDestinationLength(destination, dOffset, length);
for (int i = 0; i < length; ++i) {
    destination[i + dOffset] = source[i + sOffset];
return length;
byte[]copyBytes(int[] srcArray, int srcPos, byte[] destBytes)
copy Bytes
for (int k = 0; k < destBytes.length; k++) {
    destBytes[k] = (byte) (srcArray[srcPos + k] & 0xff);
return destBytes;
intcopyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
Byte arrays source and dest each begin at an offset in the common space.
if (sourceOff >= source.length) {
    return 0;
if (sourceOff + sourceLength > source.length) {
    sourceLength = source.length - sourceOff;
if (destLength > dest.length) {
    destLength = dest.length;
...
voidcopyBytesAtOffset(byte[] dst, byte[] src, int offset)
Copy src byte array to dst byte array at offset.
if (dst == null) {
    throw new NullPointerException("dst == null");
if (src == null) {
    throw new NullPointerException("src == null");
if (offset < 0) {
    throw new IllegalArgumentException("offset hast to be >= 0");
...
voidcopyBytesIntoByteArray(byte[] dest, byte[] src)
copy Bytes Into Byte Array
copyBytesIntoByteArrayAtOffset(dest, src, 0);
StringcopyBytesToString(byte[] src, int arg1, int arg2)
copy Bytes To String
char[] chrs = new char[arg2 - arg1];
for (int i = 0, j = arg1; j < arg2; i++, j++) {
    chrs[i] = (char) src[j];
String s = String.valueOf(chrs);
return s;