| 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 class ListInputStream extends _BaseDataInputStream implements InputStream { | |
| 6 ListInputStream(List<int> this._buffer) { | |
| 7 _streamMarkedClosed = true; | |
| 8 } | |
| 9 | |
| 10 int available() => _buffer.length - _offset; | |
| 11 | |
| 12 List<int> _read(int bytesToRead) { | |
| 13 if (_offset == 0 && bytesToRead == _buffer.length) { | |
| 14 _offset = _buffer.length; | |
| 15 return _buffer; | |
| 16 } else { | |
| 17 List<int> result = _buffer.getRange(_offset, bytesToRead); | |
| 18 _offset += bytesToRead; | |
| 19 return result; | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 int _readInto(List<int> buffer, int offset, int bytesToRead) { | |
| 24 buffer.setRange(offset, bytesToRead, _buffer, _offset); | |
| 25 _offset += bytesToRead; | |
| 26 return bytesToRead; | |
| 27 } | |
| 28 | |
| 29 List<int> _buffer; | |
| 30 int _offset = 0; | |
| 31 } | |
| 32 | |
| 33 | |
| 34 class DynamicListInputStream | |
| 35 extends _BaseDataInputStream implements InputStream { | |
| 36 DynamicListInputStream() : _bufferList = new _BufferList(); | |
| 37 | |
| 38 int available() => _bufferList.length; | |
| 39 | |
| 40 void write(List<int> data) { | |
| 41 _bufferList.add(data); | |
| 42 _checkScheduleCallbacks(); | |
| 43 } | |
| 44 | |
| 45 void markEndOfStream() { | |
| 46 _streamMarkedClosed = true; | |
| 47 _checkScheduleCallbacks(); | |
| 48 } | |
| 49 | |
| 50 List<int> _read(int bytesToRead) { | |
| 51 return _bufferList.readBytes(bytesToRead); | |
| 52 } | |
| 53 | |
| 54 int _readInto(List<int> buffer, int offset, int bytesToRead) { | |
| 55 List<int> tmp = _bufferList.readBytes(byteToRead); | |
| 56 buffer.setRange(offset, bytesToRead, tmp, _offset); | |
| 57 return bytesToRead; | |
| 58 } | |
| 59 | |
| 60 _BufferList _bufferList; | |
| 61 } | |
| OLD | NEW |