Java Array Copy arrayCopy(byte[] source, byte[] dest)

Here you can find the source of arrayCopy(byte[] source, byte[] dest)

Description

array Copy

License

Open Source License

Declaration

public static byte[] arrayCopy(byte[] source, byte[] dest) 

Method Source Code

//package com.java2s;
/*-// w  ww  . java 2  s  . com
 * Copyright (C) 2006-2008 Erik Larsson
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

public class Main {
    public static byte[] arrayCopy(byte[] source, byte[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static byte[] arrayCopy(byte[] source, int sourcePos, byte[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static byte[] arrayCopy(byte[] source, byte[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static byte[] arrayCopy(byte[] source, int sourcePos, byte[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static byte[] arrayCopy(byte[] source, int sourcePos, byte[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static boolean[] arrayCopy(boolean[] source, boolean[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static boolean[] arrayCopy(boolean[] source, int sourcePos, boolean[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static boolean[] arrayCopy(boolean[] source, boolean[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static boolean[] arrayCopy(boolean[] source, int sourcePos, boolean[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static boolean[] arrayCopy(boolean[] source, int sourcePos, boolean[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static short[] arrayCopy(short[] source, short[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static short[] arrayCopy(short[] source, int sourcePos, short[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static short[] arrayCopy(short[] source, short[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static short[] arrayCopy(short[] source, int sourcePos, short[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static short[] arrayCopy(short[] source, int sourcePos, short[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static char[] arrayCopy(char[] source, char[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static char[] arrayCopy(char[] source, int sourcePos, char[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static char[] arrayCopy(char[] source, char[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static char[] arrayCopy(char[] source, int sourcePos, char[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static char[] arrayCopy(char[] source, int sourcePos, char[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static int[] arrayCopy(int[] source, int[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static int[] arrayCopy(int[] source, int sourcePos, int[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static int[] arrayCopy(int[] source, int[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static int[] arrayCopy(int[] source, int sourcePos, int[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static int[] arrayCopy(int[] source, int sourcePos, int[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static long[] arrayCopy(long[] source, long[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static long[] arrayCopy(long[] source, int sourcePos, long[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static long[] arrayCopy(long[] source, long[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static long[] arrayCopy(long[] source, int sourcePos, long[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static long[] arrayCopy(long[] source, int sourcePos, long[] dest, int destPos, int length) {
        if (source.length - sourcePos < length) {
            throw new RuntimeException("Source array not large enough.");
        }

        if (dest.length - destPos < length) {
            throw new RuntimeException("Destination array not large enough.");
        }

        System.arraycopy(source, sourcePos, dest, destPos, length);

        return dest;
    }

    public static <T> T[] arrayCopy(T[] source, T[] dest) {
        return arrayCopy(source, 0, dest, 0);
    }

    public static <T> T[] arrayCopy(T[] source, int sourcePos, T[] dest) {
        return arrayCopy(source, sourcePos, dest, 0);
    }

    public static <T> T[] arrayCopy(T[] source, T[] dest, int destPos) {
        return arrayCopy(source, 0, dest, destPos);
    }

    public static <T> T[] arrayCopy(T[] source, int sourcePos, T[] dest, int destPos) {
        return arrayCopy(source, sourcePos, dest, destPos, source.length - sourcePos);
    }

    public static <T> T[] arrayCopy(T[] source, int sourcePos, T[] dest, int destPos, int length) {
        if (source.length - sourcePos < length)
            throw new RuntimeException("Source array not large enough.");
        if (dest.length - destPos < length)
            throw new RuntimeException("Destination array not large enough.");
        System.arraycopy(source, sourcePos, dest, destPos, length);
        return dest;
    }
}

Related

  1. arrayBig2Small(int[] big, int bigWidth, int[][] small, int startRow, int startCol, int endRow, int endCol)
  2. arrayCopy(byte[] dest, int offset, byte[] in)
  3. arrayCopy(byte[] in, int inOff, int length, byte[] out, int outOff)
  4. arrayCopy(byte[] source, byte[] dest)
  5. arraycopy(byte[] src, int destLen, int len)
  6. arraycopy(byte[] src, int src_position, byte[] dst, int dst_position, int length)
  7. arrayCopy(byte[] src, int srcOffset, byte[] target, int targetOffset, int length)
  8. arrayCopy(byte[] src, int srcStart, byte[] dest, int destStart, int destBitOffset, int lengthInBits)