Here you can find the source of subArray(final byte[] source, final int start, final int length)
Parameter | Description |
---|---|
source | Source of the byte array |
start | starting byte |
length | length of the array to return |
public static byte[] subArray(final byte[] source, final int start, final int length)
//package com.java2s; /*//ww w .j a v a 2 s . c om * Copyright (c) 2014 Stephan D. Cote' - All rights reserved. * * This program and the accompanying materials are made available under the * terms of the MIT License which accompanies this distribution, and is * available at http://creativecommons.org/licenses/MIT/ * * Contributors: * Stephan D. Cote * - Initial API and implementation */ public class Main { /** * Works like String.substring() * * @param source Source of the byte array * @param start starting byte * @param length length of the array to return * * @return the portion of the byte array specified. */ public static byte[] subArray(final byte[] source, final int start, final int length) { if (start < 0) { throw new ArrayIndexOutOfBoundsException("Start index: " + start); } if (source == null) { throw new IllegalArgumentException("Source array was null"); } if ((start + length) > source.length) { throw new ArrayIndexOutOfBoundsException("length index: " + length); } final byte[] retval = new byte[length]; System.arraycopy(source, start, retval, 0, length); return retval; } }