Java Array Clone cloneArray(byte[] in)

Here you can find the source of cloneArray(byte[] in)

Description

Clone a byte array.

License

Open Source License

Parameter

Parameter Description
in byte array.

Return

Copy of byte array.

Declaration

public static byte[] cloneArray(byte[] in) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w  w  w .ja va2 s .c o m
     * Clone a byte array.
     *
     * @param in byte array.
     * @return Copy of byte array.
     */
    public static byte[] cloneArray(byte[] in) {
        if (in == null) {
            throw new NullPointerException("in == null");
        }
        byte[] out = new byte[in.length];
        System.arraycopy(in, 0, out, 0, in.length);
        return out;
    }

    /**
     * Clone a 2d byte array.
     *
     * @param in 2d byte array.
     * @return Copy of 2d byte array.
     */
    public static byte[][] cloneArray(byte[][] in) {
        if (hasNullPointer(in)) {
            throw new NullPointerException("in has null pointers");
        }
        byte[][] out = new byte[in.length][];
        for (int i = 0; i < in.length; i++) {
            out[i] = new byte[in[i].length];
            System.arraycopy(in[i], 0, out[i], 0, in[i].length);
        }
        return out;
    }

    /**
     * Checks whether 2d byte array has null pointers.
     *
     * @param in 2d byte array.
     * @return true if at least one null pointer is found false else.
     */
    public static boolean hasNullPointer(byte[][] in) {
        if (in == null) {
            return true;
        }
        for (int i = 0; i < in.length; i++) {
            if (in[i] == null) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. clone2DArray(final boolean[][] array)
  2. clone_multidim_array(float[][] arr)
  3. cloneAndMultiplyArray(float[] array, float factor)
  4. cloneArray(boolean[][] src)
  5. cloneArray(byte[] bytes)
  6. cloneArray(double[][] a)
  7. cloneArray(Double[][] src)
  8. cloneArray(final String[] inputArray)
  9. cloneArray(int[] array)