Here you can find the source of cloneArray(byte[] in)
Parameter | Description |
---|---|
in | byte array. |
public static byte[] cloneArray(byte[] in)
//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; } }