Code example for BufferUnderflowException

0
    this.in = in;
  } 
 
  public void commit(char[] replaceWith, int startReplace, int endReplace) {
    if (startReplace < inPos) {
      throw new BufferUnderflowException();
    } 
    if (endReplace > in.length) {
      throw new BufferOverflowException();
    } 
 
    // commit any characters up to the beginning of the replacement 
    out.write(in, inPos, startReplace - inPos);
 
    // commit the replacement 
    out.write(replaceWith, 0, replaceWith.length);
 
    // skip over the replaced characters 
    inPos = endReplace;
  }