| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 class ListInputStream extends _BaseDataInputStream implements InputStream { | 5 class ListInputStream extends _BaseDataInputStream implements InputStream { |
| 6 ListInputStream(List<int> this._buffer) { | 6 ListInputStream(List<int> this._buffer) { |
| 7 _streamMarkedClosed = true; | 7 _streamMarkedClosed = true; |
| 8 } | 8 } |
| 9 | 9 |
| 10 int available() => _buffer.length - _offset; | 10 int available() => _buffer.length - _offset; |
| 11 | 11 |
| 12 List<int> _read(int bytesToRead) { | 12 List<int> _read(int bytesToRead) { |
| 13 if (_offset == 0 && bytesToRead == _buffer.length) { | 13 if (_offset == 0 && bytesToRead == _buffer.length) { |
| 14 _offset = _buffer.length; | 14 _offset = _buffer.length; |
| 15 return _buffer; | 15 return _buffer; |
| 16 } else { | 16 } else { |
| 17 List<int> result = _buffer.getRange(_offset, bytesToRead); | 17 List<int> result = _buffer.getRange(_offset, bytesToRead); |
| 18 _offset += bytesToRead; | 18 _offset += bytesToRead; |
| 19 return result; | 19 return result; |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 int _readInto(List<int> buffer, int offset, int bytesToRead) { | 23 int _readInto(List<int> buffer, int offset, int bytesToRead) { |
| 24 buffer.setRange(offset, bytesToRead, _buffer, _offset); | 24 buffer.setRange(offset, bytesToRead, _buffer, _offset); |
| 25 _offset += bytesToRead; | 25 _offset += bytesToRead; |
| 26 return bytesToRead; | 26 return bytesToRead; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void _close() { |
| 30 _offset = _buffer.length; |
| 31 } |
| 32 |
| 29 List<int> _buffer; | 33 List<int> _buffer; |
| 30 int _offset = 0; | 34 int _offset = 0; |
| 31 } | 35 } |
| 32 | 36 |
| 33 | 37 |
| 34 class DynamicListInputStream | 38 class DynamicListInputStream |
| 35 extends _BaseDataInputStream implements InputStream { | 39 extends _BaseDataInputStream implements InputStream { |
| 36 DynamicListInputStream() : _bufferList = new _BufferList(); | 40 DynamicListInputStream() : _bufferList = new _BufferList(); |
| 37 | 41 |
| 38 int available() => _bufferList.length; | 42 int available() => _bufferList.length; |
| 39 | 43 |
| 40 void write(List<int> data) { | 44 void write(List<int> data) { |
| 45 if (_streamMarkedClosed) { |
| 46 throw new StreamException.streamClosed(); |
| 47 } |
| 41 _bufferList.add(data); | 48 _bufferList.add(data); |
| 42 _checkScheduleCallbacks(); | 49 _checkScheduleCallbacks(); |
| 43 } | 50 } |
| 44 | 51 |
| 45 void markEndOfStream() { | 52 void markEndOfStream() { |
| 46 _streamMarkedClosed = true; | 53 _streamMarkedClosed = true; |
| 47 _checkScheduleCallbacks(); | 54 _checkScheduleCallbacks(); |
| 48 } | 55 } |
| 49 | 56 |
| 50 List<int> _read(int bytesToRead) { | 57 List<int> _read(int bytesToRead) { |
| 51 return _bufferList.readBytes(bytesToRead); | 58 return _bufferList.readBytes(bytesToRead); |
| 52 } | 59 } |
| 53 | 60 |
| 54 int _readInto(List<int> buffer, int offset, int bytesToRead) { | 61 int _readInto(List<int> buffer, int offset, int bytesToRead) { |
| 55 List<int> tmp = _bufferList.readBytes(byteToRead); | 62 List<int> tmp = _bufferList.readBytes(byteToRead); |
| 56 buffer.setRange(offset, bytesToRead, tmp, _offset); | 63 buffer.setRange(offset, bytesToRead, tmp, _offset); |
| 57 return bytesToRead; | 64 return bytesToRead; |
| 58 } | 65 } |
| 59 | 66 |
| 67 void _close() { |
| 68 _streamMarkedClosed = true; |
| 69 _bufferList.clear(); |
| 70 } |
| 71 |
| 60 _BufferList _bufferList; | 72 _BufferList _bufferList; |
| 61 } | 73 } |
| 62 | 74 |
| 63 | 75 |
| 64 class ListOutputStream implements OutputStream { | 76 class ListOutputStream implements OutputStream { |
| 65 ListOutputStream() : _bufferList = new _BufferList(); | 77 ListOutputStream() : _bufferList = new _BufferList(); |
| 66 | 78 |
| 67 bool write(List<int> buffer, [bool copyBuffer = false]) { | 79 bool write(List<int> buffer, [bool copyBuffer = false]) { |
| 68 if (_streamMarkedClosed) throw new StreamException.streamClosed(); | 80 if (_streamMarkedClosed) throw new StreamException.streamClosed(); |
| 69 if (copyBuffer) { | 81 if (copyBuffer) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 152 } |
| 141 | 153 |
| 142 _BufferList _bufferList; | 154 _BufferList _bufferList; |
| 143 bool _streamMarkedClosed = false; | 155 bool _streamMarkedClosed = false; |
| 144 bool _closeCallbackCalled = false; | 156 bool _closeCallbackCalled = false; |
| 145 Timer _scheduledNoPendingWriteCallback; | 157 Timer _scheduledNoPendingWriteCallback; |
| 146 Timer _scheduledCloseCallback; | 158 Timer _scheduledCloseCallback; |
| 147 Function _clientNoPendingWriteHandler; | 159 Function _clientNoPendingWriteHandler; |
| 148 Function _clientCloseHandler; | 160 Function _clientCloseHandler; |
| 149 } | 161 } |
| OLD | NEW |