code: public static void quoteHtmlChars(OutputStream output, byte[] buffer,
                                      int off, int len) throws IOException {
      for(int i=off; i < off+len; i++) {
        switch (buffer[i]) {
        case '&': output.write(ampBytes); break;
        case '<': output.write(ltBytes); break;
        case '>': output.write(gtBytes); break;
        case '\'': output.write(aposBytes); break;
        case '"': output.write(quotBytes); break;
        default: output.write(buffer, i, 1);
        }
      }
    }
docs: Quote all of the active HTML characters in the given string as they
  are added to the buffer.
  @param output the stream to write the output to
  @param buffer the byte array to take the characters from
  @param off the index of the first byte to quote
  @param len the number of bytes to quote