Code example for StringWriter

Methods: flush, getBuffer, write

0
    } 
 
    public abstract void writeTo(Writer writer) throws IOException;
 
    public void respond(Response response) throws Exception {
        StringWriter writer = new StringWriter();
        writeTo(writer);
        writer.write("\n\n");
        writer.flush();
        byte[] content = writer.getBuffer().toString().getBytes(characterSet);
        response.setHeader("Content-Type", mimeType + "; charset=" + characterSet);
        response.setHeader("Content-Length", content.length);
        response.writeBody().write(content);
    } 
}