public static byte [ ] safeCopy ( byte [ ] source , int offset , int length ) { if ( length < 0 || source . length < offset + length ) { return null ; } byte [ ] copy = new byte [ length ] ; System . arraycopy ( source , offset , copy , 0 , length ) ; return copy ; }
Returns a copy of the source byte array starting at offset for the given length . If the offset + length is out of bounds for the array returns null .