Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: sdk/lib/io/string_transformer.dart

Issue 203603008: Introduce class Sink<T>. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 /// The current system encoding. 7 /// The current system encoding.
8 const SystemEncoding SYSTEM_ENCODING = const SystemEncoding(); 8 const SystemEncoding SYSTEM_ENCODING = const SystemEncoding();
9 9
10 /** 10 /**
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 List<int> encoded = _encodeString(input); 44 List<int> encoded = _encodeString(input);
45 if (encoded == null) { 45 if (encoded == null) {
46 throw new FormatException("Invalid character for encoding"); 46 throw new FormatException("Invalid character for encoding");
47 } 47 }
48 return encoded; 48 return encoded;
49 } 49 }
50 50
51 /** 51 /**
52 * Starts a chunked conversion. 52 * Starts a chunked conversion.
53 */ 53 */
54 StringConversionSink startChunkedConversion( 54 StringConversionSink startChunkedConversion(Sink<List<int>> sink) {
55 ChunkedConversionSink<List<int>> sink) {
56 return new _WindowsCodePageEncoderSink(sink); 55 return new _WindowsCodePageEncoderSink(sink);
57 } 56 }
58 57
59 // Override the base-class' bind, to provide a better type. 58 // Override the base-class' bind, to provide a better type.
60 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); 59 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream);
61 60
62 external static List<int> _encodeString(String string); 61 external static List<int> _encodeString(String string);
63 } 62 }
64 63
65 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { 64 class _WindowsCodePageEncoderSink extends StringConversionSinkBase {
66 // TODO(floitsch): provide more efficient conversions when the input is 65 // TODO(floitsch): provide more efficient conversions when the input is
67 // not a String. 66 // not a String.
68 67
69 final ChunkedConversionSink<List<int>> _sink; 68 final Sink<List<int>> _sink;
70 69
71 _WindowsCodePageEncoderSink(this._sink); 70 _WindowsCodePageEncoderSink(this._sink);
72 71
73 void close() { 72 void close() {
74 _sink.close(); 73 _sink.close();
75 } 74 }
76 75
77 void add(String string) { 76 void add(String string) {
78 List<int> encoded = _WindowsCodePageEncoder._encodeString(string); 77 List<int> encoded = _WindowsCodePageEncoder._encodeString(string);
79 if (encoded == null) { 78 if (encoded == null) {
(...skipping 16 matching lines...) Expand all
96 95
97 const _WindowsCodePageDecoder(); 96 const _WindowsCodePageDecoder();
98 97
99 String convert(List<int> input) { 98 String convert(List<int> input) {
100 return _decodeBytes(input); 99 return _decodeBytes(input);
101 } 100 }
102 101
103 /** 102 /**
104 * Starts a chunked conversion. 103 * Starts a chunked conversion.
105 */ 104 */
106 ByteConversionSink startChunkedConversion( 105 ByteConversionSink startChunkedConversion(Sink<String> sink) {
107 ChunkedConversionSink<String> sink) {
108 return new _WindowsCodePageDecoderSink(sink); 106 return new _WindowsCodePageDecoderSink(sink);
109 } 107 }
110 108
111 // Override the base-class' bind, to provide a better type. 109 // Override the base-class' bind, to provide a better type.
112 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); 110 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream);
113 111
114 external static String _decodeBytes(List<int> bytes); 112 external static String _decodeBytes(List<int> bytes);
115 } 113 }
116 114
117 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { 115 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase {
118 // TODO(floitsch): provide more efficient conversions when the input is 116 // TODO(floitsch): provide more efficient conversions when the input is
119 // a slice. 117 // a slice.
120 118
121 final ChunkedConversionSink<String> _sink; 119 final Sink<String> _sink;
122 120
123 _WindowsCodePageDecoderSink(this._sink); 121 _WindowsCodePageDecoderSink(this._sink);
124 122
125 void close() { 123 void close() {
126 _sink.close(); 124 _sink.close();
127 } 125 }
128 126
129 void add(List<int> bytes) { 127 void add(List<int> bytes) {
130 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); 128 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes));
131 } 129 }
132 } 130 }
OLDNEW
« no previous file with comments | « sdk/lib/io/data_transformer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698