code: 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;
    }
docs: Copies from original byte array to a new byte array. The resulting byte array is always
  "to-from" size.
  
  @param orig the original byte array
  @param from index of first byte in original byte array which will be copied
  @param to   index of last byte in original byte array which will be copied. This can be outside
  of the original byte array
  @return resulting array