3 import java.io.IOException;
5 /** Fixing the problem caused by mixing subclassing and delegation in
6 * the <code>java.io.BufferedWriter</code>
8 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10 // BEGIN: writer.final.1.0
11 public final class Writer {
12 private final Impl impl;
14 private Writer(Impl impl) {
17 public final void write(int c) throws IOException {
18 char[] arr = { (char)c };
19 impl.write(arr, 0, 1);
22 public final void write(char cbuf[]) throws IOException {
23 impl.write(cbuf, 0, cbuf.length);
25 public final void write(char cbuf[], int off, int len) throws IOException {
26 impl.write(cbuf, off, len);
28 public final void write(String str) throws IOException {
29 impl.write(str, 0, str.length());
31 public final void write(String str, int off, int len) throws IOException {
32 impl.write(str, off, len);
34 public final void flush() throws IOException {
37 public final void close() throws IOException {
41 public static Writer create(Impl impl) {
42 return new Writer(impl);
45 public static Writer create(final java.io.Writer w) {
46 return new Writer(new Impl() {
47 public void write(String str, int off, int len) throws IOException {
48 w.write(str, off, len);
51 public void write(char[] arr, int off, int len) throws IOException {
52 w.write(arr, off, len);
55 public void close() throws IOException {
59 public void flush() throws IOException {
65 public static Writer createBuffered(final Writer out) {
66 return create(new SimpleBuffer(out));
70 public static interface Impl {
71 public void close() throws IOException;
72 public void flush() throws IOException;
73 public void write(String str, int off, int len) throws IOException;
74 public void write(char[] arr, int off, int len) throws IOException;
77 // END: writer.final.1.0