if (offset < 0 || offset > document.getLength()) throw new BadLocationException("Tried to write to invalid location", offset);   if (offset + len > document.getLength()) len = document.getLength() - offset;  out.write(document.getText(offset, len));
write(new OutputStreamWriter(out), document, offset, len);
  public void write(Writer out, Document document, int offset, int len)      throws BadLocationException, IOException  {    // Throw a BLE if offset is invalid    if (offset < 0 || offset > document.getLength())      throw new BadLocationException("Tried to write to invalid location",                                     offset);    // If they gave an overly large len, just adjust it    if (offset + len > document.getLength())      len = document.getLength() - offset;    out.write(document.getText(offset, len));  }