OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 interface Writer { |
| 6 void print(String out); |
| 7 void println([String out]); |
| 8 } |
| 9 |
| 10 class AbstractWriter { |
| 11 static String NEWLINE = "\n"; |
| 12 static List<int> NEWLINE_CHARS; |
| 13 AbstractWriter() { |
| 14 if(null === NEWLINE_CHARS) NEWLINE_CHARS = NEWLINE.charCodes(); |
| 15 } |
| 16 } |
| 17 |
| 18 class MemoryWriter extends AbstractWriter implements Writer { |
| 19 MemoryWriter(): super(), _buffer = new StringBuffer(); |
| 20 |
| 21 void print(String out) { |
| 22 _buffer.add(out); |
| 23 } |
| 24 |
| 25 void println([String out = null]) { |
| 26 _buffer.add(out); |
| 27 _buffer.add(AbstractWriter.NEWLINE); |
| 28 } |
| 29 |
| 30 String toString() { |
| 31 return _buffer.toString(); |
| 32 } |
| 33 |
| 34 StringBuffer _buffer; |
| 35 } |
| 36 |
| 37 class OutputStreamWriter extends AbstractWriter implements Writer { |
| 38 OutputStreamWriter(OutputStream this._outStream) : super(); |
| 39 void print(String str) { |
| 40 _outStream.write(str.charCodes()); |
| 41 } |
| 42 void println([String out = null]) { |
| 43 if(null !== out) print(out); |
| 44 _outStream.write(AbstractWriter.NEWLINE_CHARS); |
| 45 } |
| 46 OutputStream _outStream; |
| 47 } |
OLD | NEW |