Java Byte Array Copy copyBytesAtOffset(byte[] dst, byte[] src, int offset)

Here you can find the source of copyBytesAtOffset(byte[] dst, byte[] src, int offset)

Description

Copy src byte array to dst byte array at offset.

License

Open Source License

Parameter

Parameter Description
dst Destination.
src Source.
offset Destination offset.

Declaration

public static void copyBytesAtOffset(byte[] dst, byte[] src, int offset) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w w  .  jav a  2  s. c o m*/
     * Copy src byte array to dst byte array at offset.
     *
     * @param dst    Destination.
     * @param src    Source.
     * @param offset Destination offset.
     */
    public static void copyBytesAtOffset(byte[] dst, byte[] src, int 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");
        }
        if ((src.length + offset) > dst.length) {
            throw new IllegalArgumentException("src length + offset must not be greater than size of destination");
        }
        for (int i = 0; i < src.length; i++) {
            dst[offset + i] = src[i];
        }
    }
}

Related

  1. copyBytes(byte[] src, byte[] target)
  2. copyBytes(byte[] src, int start, int end)
  3. copyBytes(final byte[] source, final int sOffset, final byte[] destination, final int dOffset, final int length)
  4. copyBytes(int[] srcArray, int srcPos, byte[] destBytes)
  5. copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
  6. copyBytesIntoByteArray(byte[] dest, byte[] src)
  7. copyBytesToString(byte[] src, int arg1, int arg2)
  8. copyBytesWithin(byte[] bytes, int target, int start, int end)
  9. memcpy(byte[] dest, int doff, byte[] src, int soff, int len)