public static byte[] copyOfRange(byte[] data,int from,int to){
  int newLength=getLength(from,to);
  byte[] tmp=new byte[newLength];
  if (data.length - from < newLength) {
    System.arraycopy(data,from,tmp,0,data.length - from);
  }
 else {
    System.arraycopy(data,from,tmp,0,newLength);
  }
  return tmp;
}

public static byte [ ] copyOfRange ( byte [ ] data , int from , int to ) { int newLength = getLength ( from , to ) ; byte [ ] tmp = new byte [ newLength ] ; if ( data . length - from < newLength ) { System . arraycopy ( data , from , tmp , 0 , data . length - from ) ; } else { System . arraycopy ( data , from , tmp , 0 , newLength ) ; } return tmp ; }
make a copy of a range of bytes from the passed in data array . the range can extend beyond the end of the input array , in which case the return array will be padded with zeroes .
