public static byte [ ] copyRange ( byte [ ] orig , int from , int to ) { int length = to - from ; byte [ ] result = new byte [ length ] ; int howMuchToCopy = orig . length - from < length ? orig . length - from : length ; System . arraycopy ( orig , from , result , 0 , howMuchToCopy ) ; return result ; }
Copies from original byte array to a new byte array . The resulting byte array is always to - from size .