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;
}

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 .
