1.1 --- a/samples/delegatingwriterfinal/src-api2.0/api/Writer.java Sat Jun 14 09:53:06 2008 +0200
1.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/Writer.java Sat Jun 14 09:53:07 2008 +0200
1.3 @@ -8,7 +8,7 @@
1.4 *
1.5 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.6 */
1.7 -public final class Writer {
1.8 +public final class Writer implements Appendable {
1.9 private final Impl impl;
1.10 private final ImplSeq seq;
1.11
1.12 @@ -69,6 +69,27 @@
1.13 }
1.14 }
1.15
1.16 +
1.17 +
1.18 + public final Writer append(CharSequence csq) throws IOException {
1.19 + if (impl != null) {
1.20 + String s = csq == null ? "null" : csq.toString();
1.21 + impl.write(s, 0, s.length());
1.22 + } else {
1.23 + seq.write(csq);
1.24 + }
1.25 + return this;
1.26 + }
1.27 +
1.28 + public final Writer append(CharSequence csq, int start, int end) throws IOException {
1.29 + return append(csq.subSequence(start, end));
1.30 + }
1.31 +
1.32 + public final Writer append(char c) throws IOException {
1.33 + write(c);
1.34 + return this;
1.35 + }
1.36 +
1.37 public static Writer create(Impl impl) {
1.38 return new Writer(impl, null);
1.39 }
1.40 @@ -78,13 +99,9 @@
1.41 }
1.42
1.43 public static Writer create(final java.io.Writer w) {
1.44 - return new Writer(new Impl() {
1.45 - public void write(String str, int off, int len) throws IOException {
1.46 - w.write(str, off, len);
1.47 - }
1.48 -
1.49 - public void write(char[] arr, int off, int len) throws IOException {
1.50 - w.write(arr, off, len);
1.51 + return new Writer(null, new ImplSeq() {
1.52 + public void write(CharSequence seq) throws IOException {
1.53 + w.append(seq);
1.54 }
1.55
1.56 public void close() throws IOException {
1.57 @@ -94,28 +111,11 @@
1.58 public void flush() throws IOException {
1.59 w.flush();
1.60 }
1.61 - }, null);
1.62 + });
1.63 }
1.64
1.65 public static Writer createBuffered(final Writer out) {
1.66 - class Delegate extends java.io.Writer {
1.67 - @Override
1.68 - public void write(char[] cbuf, int off, int len) throws IOException {
1.69 - out.write(cbuf, off, len);
1.70 - }
1.71 -
1.72 - @Override
1.73 - public void flush() throws IOException {
1.74 - out.flush();
1.75 - }
1.76 -
1.77 - @Override
1.78 - public void close() throws IOException {
1.79 - out.close();
1.80 - }
1.81 -
1.82 - }
1.83 - return create(new BufferedWriter(new Delegate()));
1.84 + return create(new SimpleBuffer(out));
1.85 }
1.86
1.87