public void write(Writer writer) throws IOException {
        for (String line : lines) {
            writer.write(line);
        }
    }
@Test
    public void testWrite() throws Exception {
        CodeBuffer buffer = new CodeBuffer();
        buffer.printf("public static void main(String[] args) throws Exception {%n");
        buffer.incrementIndent();
        buffer.printf("System.out.println(\"%s\");%n", "hello world");
        buffer.decrementIndent();
        buffer.printf("}%n");
        StringWriter stringWriter = new StringWriter();
        buffer.write(stringWriter);
        assertEquals(
            stringWriter.toString(),
            String.format("public static void main(String[] args) throws Exception {%n") +
            String.format("    System.out.println(\"hello world\");%n") +
            String.format("}%n"));
    }