| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Interface for decoders decoding binary data into string data. The | 5 // Interface for decoders decoding binary data into string data. The |
| 6 // decoder keeps track of line breaks during decoding. | 6 // decoder keeps track of line breaks during decoding. |
| 7 interface _StringDecoder { | 7 abstract class _StringDecoder { |
| 8 // Add more binary data to be decoded. The ownership of the buffer | 8 // Add more binary data to be decoded. The ownership of the buffer |
| 9 // is transfered to the decoder and the caller most not modify it any more. | 9 // is transfered to the decoder and the caller most not modify it any more. |
| 10 int write(List<int> buffer); | 10 int write(List<int> buffer); |
| 11 | 11 |
| 12 // Returns whether any decoded data is available. | 12 // Returns whether any decoded data is available. |
| 13 bool isEmpty(); | 13 bool isEmpty(); |
| 14 | 14 |
| 15 // Returns the number of available decoded characters. | 15 // Returns the number of available decoded characters. |
| 16 int available(); | 16 int available(); |
| 17 | 17 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 while (_bufferList.length > 0) { | 238 while (_bufferList.length > 0) { |
| 239 int byte = _bufferList.next(); | 239 int byte = _bufferList.next(); |
| 240 addChar(byte); | 240 addChar(byte); |
| 241 } | 241 } |
| 242 return true; | 242 return true; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 | 246 |
| 247 // Interface for encoders encoding string data into binary data. | 247 // Interface for encoders encoding string data into binary data. |
| 248 interface _StringEncoder { | 248 abstract class _StringEncoder { |
| 249 List<int> encodeString(String string); | 249 List<int> encodeString(String string); |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 // Utility class for encoding a string into UTF-8 byte stream. | 253 // Utility class for encoding a string into UTF-8 byte stream. |
| 254 class _UTF8Encoder implements _StringEncoder { | 254 class _UTF8Encoder implements _StringEncoder { |
| 255 List<int> encodeString(String string) { | 255 List<int> encodeString(String string) { |
| 256 int size = _encodingSize(string); | 256 int size = _encodingSize(string); |
| 257 List<int> result = new Uint8List(size); | 257 List<int> result = new Uint8List(size); |
| 258 _encodeString(string, result); | 258 _encodeString(string, result); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 | 349 |
| 350 class EncoderException implements Exception { | 350 class EncoderException implements Exception { |
| 351 const EncoderException([String this.message]); | 351 const EncoderException([String this.message]); |
| 352 String toString() => "EncoderException: $message"; | 352 String toString() => "EncoderException: $message"; |
| 353 final String message; | 353 final String message; |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 class _StringInputStream implements StringInputStream { | 357 class _StringInputStream implements StringInputStream { |
| 358 _StringInputStream(InputStream this._input, | 358 _StringInputStream(InputStream this._input, Encoding this._encoding) { |
| 359 [Encoding encoding = Encoding.UTF_8]) | |
| 360 : _encoding = encoding { | |
| 361 _decoder = _StringDecoders.decoder(encoding); | 359 _decoder = _StringDecoders.decoder(encoding); |
| 362 _input.onData = _onData; | 360 _input.onData = _onData; |
| 363 _input.onClosed = _onClosed; | 361 _input.onClosed = _onClosed; |
| 364 } | 362 } |
| 365 | 363 |
| 366 String read([int len]) { | 364 String read([int len]) { |
| 367 String result = _decoder.decoded(len); | 365 String result = _decoder.decoded(len); |
| 368 _checkInstallDataHandler(); | 366 _checkInstallDataHandler(); |
| 369 return result; | 367 return result; |
| 370 } | 368 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 bool _inputClosed = false; // Is the underlying input stream closed? | 523 bool _inputClosed = false; // Is the underlying input stream closed? |
| 526 bool _closed = false; // Is this stream closed. | 524 bool _closed = false; // Is this stream closed. |
| 527 bool _eof = false; // Has all data been read from the decoder? | 525 bool _eof = false; // Has all data been read from the decoder? |
| 528 Timer _scheduledDataCallback; | 526 Timer _scheduledDataCallback; |
| 529 Timer _scheduledLineCallback; | 527 Timer _scheduledLineCallback; |
| 530 Timer _scheduledCloseCallback; | 528 Timer _scheduledCloseCallback; |
| 531 Function _clientDataHandler; | 529 Function _clientDataHandler; |
| 532 Function _clientLineHandler; | 530 Function _clientLineHandler; |
| 533 Function _clientCloseHandler; | 531 Function _clientCloseHandler; |
| 534 } | 532 } |
| OLD | NEW |