Here you can find the source of sliceBytes(byte[] bytes, int offset, int length)
Parameter | Description |
---|---|
bytes | a parameter |
offset | a parameter |
length | a parameter |
Parameter | Description |
---|---|
UtilityException | an exception |
public static byte[] sliceBytes(byte[] bytes, int offset, int length) throws Exception
//package com.java2s; //License from project: Apache License public class Main { /**// w w w . j a v a 2s .co m * * @param bytes * @param offset * @param length * @return * @throws UtilityException */ public static byte[] sliceBytes(byte[] bytes, int offset, int length) throws Exception { if (null == bytes || bytes.length <= 0) { return null; } if (bytes.length < length) { throw new Exception("Array index out of bound : " + length); } if ((offset + length) > bytes.length) { throw new Exception("Array index out of bound : " + (offset + length)); } if (offset < 0 || offset > bytes.length - 1) { throw new Exception("Array index out of bound : " + (offset + length)); } byte[] newArray = new byte[length]; for (int i = offset, j = 0; j < length; i++, j++) { newArray[j] = bytes[i]; } return newArray; } }