Java Array Sub Array subset(int start, int count, byte[] source)

Here you can find the source of subset(int start, int count, byte[] source)

Description

This is a quick method to get a subset of a byte array as a new array

License

Open Source License

Parameter

Parameter Description
start index of the source to begin reading from
count number of bytes to copy
source byte array to read from

Return

byte array of size count

Declaration

public static byte[] subset(int start, int count, byte[] source) 

Method Source Code

//package com.java2s;
/*//from   ww  w .j  av  a2  s .  c o  m
 * StreamUtility.java
 *
 * Created on October 26, 2002, 4:05 PM
 *
 * Copyright (C) 2002  Robert Cooper, Temple of the Screaming Penguin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class Main {
    /**
     * This is a quick method to get a subset of a byte array as a new array
     * @param start index of the source to begin reading from
     * @param count number of bytes to copy
     * @param source byte array to read from
     * @return byte array of size <code>count</code>
     */
    public static byte[] subset(int start, int count, byte[] source) {
        byte[] ret = new byte[count];

        for (int i = 0; i < count; i++) {
            ret[i] = source[start + i];
        }

        return ret;
    }
}

Related

  1. subByteArray(byte[] array, int offset, int length)
  2. subset(boolean[] array, int start, int end)
  3. subset(byte[] a, int begin_index, int len)
  4. subset(byte[] array, int start, int length)
  5. subset(final char[] array, final int start, final int length)
  6. subset(String[] array, int starting, int width)
  7. subset(String[] in, int begin)
  8. subset(String[] tokens, int offset)
  9. substr(byte[] array, int start, int count)