1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/Writer.java Sat Jun 14 09:53:06 2008 +0200
1.3 @@ -0,0 +1,41 @@
1.4 +package api;
1.5 +
1.6 +import java.io.IOException;
1.7 +
1.8 +/** Fixing the problem caused by mixing subclassing and delegation in
1.9 + * the <code>java.io.BufferedWriter</code>
1.10 + *
1.11 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.12 + */
1.13 +public final class Writer {
1.14 + private final Impl impl;
1.15 +
1.16 + private Writer(Impl impl) {
1.17 + this.impl = impl;
1.18 + }
1.19 + public final void write(int c) throws IOException {
1.20 + impl.write(new CharSeq(c));
1.21 + }
1.22 +
1.23 + public final void write(char cbuf[]) throws IOException {
1.24 + impl.write(new CharSeq(cbuf, 0, cbuf.length));
1.25 + }
1.26 + public final void write(char cbuf[], int off, int len) throws IOException {
1.27 + impl.write(new CharSeq(cbuf, off, len));
1.28 + }
1.29 + public final void write(String str) throws IOException {
1.30 + impl.write(str);
1.31 + }
1.32 + public final void write(String str, int off, int len) throws IOException {
1.33 + impl.write(str.subSequence(off, off + len));
1.34 + }
1.35 +
1.36 +
1.37 +
1.38 + public static interface Impl {
1.39 + public void write(CharSequence seq) throws IOException;
1.40 + }
1.41 +
1.42 +
1.43 +
1.44 +}