Android Byte Array Copy copy(byte[] source, byte[] target)

Here you can find the source of copy(byte[] source, byte[] target)

Description

Copy the contents of the source array to the target array.

License

Open Source License

Parameter

Parameter Description
source the source array
target the target array

Return

the target array or a new one if the target array was too small

Declaration

public static byte[] copy(byte[] source, byte[] target) 

Method Source Code

//package com.java2s;
/*//from   w ww. ja  v a  2 s  .co m
 * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group
 */

public class Main {
    /**
     * Copy the contents of the source array to the target array. If the size if the target array is too small, a larger array is created.
     * 
     * @param source
     *          the source array
     * @param target
     *          the target array
     * @return the target array or a new one if the target array was too small
     */
    public static byte[] copy(byte[] source, byte[] target) {
        int len = source.length;
        if (len > target.length) {
            target = new byte[len];
        }
        System.arraycopy(source, 0, target, 0, len);
        return target;
    }
}

Related

  1. copy(byte[] from)
  2. copy(byte[] rSource)
  3. copyByteArray(byte[] source)
  4. getCopyByteArray(byte[] src, int start, int length)
  5. getCopyByteArrayArray(byte[] src, int start, int length, int subArrayLength)