| 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 _BaseDataInputStream { | 5 class _BaseDataInputStream { |
| 6 abstract int available(); | 6 abstract int available(); |
| 7 | 7 |
| 8 List<int> read([int len]) { | 8 List<int> read([int len]) { |
| 9 if (_closeCallbackCalled) return null; | 9 if (_closeCallbackCalled) return null; |
| 10 int bytesToRead = available(); | 10 int bytesToRead = available(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 int readInto(List<int> buffer, [int offset = 0, int len]) { | 25 int readInto(List<int> buffer, [int offset = 0, int len]) { |
| 26 if (_closeCallbackCalled) return null; | 26 if (_closeCallbackCalled) return null; |
| 27 if (len === null) len = buffer.length; | 27 if (len === null) len = buffer.length; |
| 28 if (offset < 0) throw new StreamException("Illegal offset $offset"); | 28 if (offset < 0) throw new StreamException("Illegal offset $offset"); |
| 29 if (len < 0) throw new StreamException("Illegal length $len"); | 29 if (len < 0) throw new StreamException("Illegal length $len"); |
| 30 int bytesToRead = Math.min(len, available()); | 30 int bytesToRead = Math.min(len, available()); |
| 31 return _readInto(buffer, offset, bytesToRead); | 31 return _readInto(buffer, offset, bytesToRead); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void pipe(OutputStream output, [bool close = true]) { |
| 35 _pipe(this, output, close: close); |
| 36 } |
| 37 |
| 34 bool get closed() => _closeCallbackCalled; | 38 bool get closed() => _closeCallbackCalled; |
| 35 | 39 |
| 36 void set dataHandler(void callback()) { | 40 void set dataHandler(void callback()) { |
| 37 _clientDataHandler = callback; | 41 _clientDataHandler = callback; |
| 38 _checkScheduleCallbacks(); | 42 _checkScheduleCallbacks(); |
| 39 } | 43 } |
| 40 | 44 |
| 41 void set closeHandler(void callback()) { | 45 void set closeHandler(void callback()) { |
| 42 _clientCloseHandler = callback; | 46 _clientCloseHandler = callback; |
| 43 _checkScheduleCallbacks(); | 47 _checkScheduleCallbacks(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // from available is now all remaining data. If this is true and the | 87 // from available is now all remaining data. If this is true and the |
| 84 // value of available is zero the close handler is called. | 88 // value of available is zero the close handler is called. |
| 85 bool _streamMarkedClosed = false; | 89 bool _streamMarkedClosed = false; |
| 86 | 90 |
| 87 // When this is set to true the close callback has been called and | 91 // When this is set to true the close callback has been called and |
| 88 // the stream is fully closed. | 92 // the stream is fully closed. |
| 89 bool _closeCallbackCalled = false; | 93 bool _closeCallbackCalled = false; |
| 90 | 94 |
| 91 Timer _scheduledDataCallback; | 95 Timer _scheduledDataCallback; |
| 92 Timer _scheduledCloseCallback; | 96 Timer _scheduledCloseCallback; |
| 93 var _clientDataHandler; | 97 Function _clientDataHandler; |
| 94 var _clientCloseHandler; | 98 Function _clientCloseHandler; |
| 95 } | 99 } |
| 96 | 100 |
| 97 | 101 |
| 98 void _pipe(InputStream input, OutputStream output, [bool close]) { | 102 void _pipe(InputStream input, OutputStream output, [bool close]) { |
| 99 Function pipeDataHandler; | 103 Function pipeDataHandler; |
| 100 Function pipeCloseHandler; | 104 Function pipeCloseHandler; |
| 101 Function pipeNoPendingWriteHandler; | 105 Function pipeNoPendingWriteHandler; |
| 102 | 106 |
| 103 Function _inputCloseHandler; | 107 Function _inputCloseHandler; |
| 104 | 108 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 122 input.dataHandler = pipeDataHandler; | 126 input.dataHandler = pipeDataHandler; |
| 123 output.noPendingWriteHandler = null; | 127 output.noPendingWriteHandler = null; |
| 124 }; | 128 }; |
| 125 | 129 |
| 126 _inputCloseHandler = input._clientCloseHandler; | 130 _inputCloseHandler = input._clientCloseHandler; |
| 127 input.dataHandler = pipeDataHandler; | 131 input.dataHandler = pipeDataHandler; |
| 128 input.closeHandler = pipeCloseHandler; | 132 input.closeHandler = pipeCloseHandler; |
| 129 output.noPendingWriteHandler = null; | 133 output.noPendingWriteHandler = null; |
| 130 } | 134 } |
| 131 | 135 |
| OLD | NEW |