Here you can find the source of copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
public static int copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength)
//package com.java2s; public class Main { /**// w w w . j a v a 2s . com * Byte arrays source and dest each begin at an offset in the common space. * If there is an overlap between dest and the first sourceLength elements of * the source, the overlapping elements are copied to dest. Returns count * of copied bytes. */ public static int copyBytes(long sourceOffset, byte[] source, int sourceOff, int sourceLength, long destOffset, byte[] dest, int destLength) { if (sourceOff >= source.length) { return 0; } if (sourceOff + sourceLength > source.length) { sourceLength = source.length - sourceOff; } if (destLength > dest.length) { destLength = dest.length; } if (sourceOffset + sourceOff >= destOffset + destLength || sourceOffset + sourceOff + sourceLength <= destOffset) { return 0; } long sourceIndex = destOffset - sourceOffset; long destIndex = 0; int sourceLimit = sourceOff + sourceLength; if (sourceIndex >= 0) { if (sourceIndex < sourceOff) { sourceIndex = sourceOff; } } else { destIndex = -sourceIndex + sourceOff; sourceIndex = sourceOff; } sourceLength = sourceLimit - (int) sourceIndex; if (sourceLength > destLength - destIndex) { sourceLength = destLength - (int) destIndex; } System.arraycopy(source, (int) sourceIndex, dest, (int) destIndex, sourceLength); return sourceLength; } /** * Copy the source to dest, returning dest or an enlarged array of result is * larger than dest. */ public static byte[] copyBytes(byte[] source, byte[] dest, int destOffset) { if (source.length + destOffset > dest.length) { byte[] newDest = new byte[source.length + destOffset]; System.arraycopy(dest, 0, newDest, 0, dest.length); dest = newDest; } System.arraycopy(source, 0, dest, destOffset, source.length); return dest; } }