Java Byte Array Copy Range copyOfRange(byte[] src, int from, int to)

Here you can find the source of copyOfRange(byte[] src, int from, int to)

Description

copy Of Range

License

Open Source License

Declaration

public static byte[] copyOfRange(byte[] src, int from, int to) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class Main {
    public static byte[] copyOfRange(byte[] src, int from, int to) {
        if (from < 0 || from >= src.length || to < from || to > src.length)
            return new byte[] {};
        byte[] tmp = new byte[from];
        byte[] result = new byte[to - from];
        ByteArrayInputStream input = new ByteArrayInputStream(src);
        input.read(tmp, 0, tmp.length);/*w  w  w .j  a  va 2s. c om*/
        input.read(result, 0, result.length);
        try {
            input.close();
        } catch (IOException e) {
        }
        return result;
    }
}