Here you can find the source of copyBytes(final byte[] source, final int sOffset, final byte[] destination, final int dOffset, final int length)
Parameter | Description |
---|---|
source | the byte array to copy from |
sOffset | offset in the source array (ie first byte copied is source[sOffset] |
destination | the array to copy into |
dOffset | offset in the destination array (ie first byte overwritten is destination[dOffset] |
length | the number of bytes to copy |
public static int copyBytes(final byte[] source, final int sOffset, final byte[] destination, final int dOffset, final int length)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w . ja va 2 s .co m*/ * @param source the byte array to copy from * @param sOffset offset in the source array (ie first byte copied is source[sOffset] * @param destination the array to copy into * @param dOffset offset in the destination array (ie first byte overwritten is destination[dOffset] * @param length the number of bytes to copy * @return the number of bytes copied */ public static int copyBytes(final byte[] source, final int sOffset, final byte[] destination, final int dOffset, final int length) { requireSourceLength(source, sOffset, length); requireDestinationLength(destination, dOffset, length); for (int i = 0; i < length; ++i) { destination[i + dOffset] = source[i + sOffset]; } return length; } /** * Helper method to check the Contract precondition of read methods */ private static void requireSourceLength(final byte[] source, final int offset, final int length) { if (source.length < offset + length - 1) { throw new IllegalArgumentException("Not enough data available in source array:\n have " + source.length + " bytes, need " + (offset + length)); } } /** * Helper method to check the Contract precondition of write methods */ private static void requireDestinationLength(final byte[] destination, final int offset, final int length) { if (destination.length < offset + length - 1) { throw new IllegalArgumentException("Not enough room available in destination array:\n have " + destination.length + " bytes, need " + (offset + length)); } } }