| 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 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 || _scheduledCloseCallback != null) return null; | 9 if (_closeCallbackCalled || _scheduledCloseCallback != null) 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 || _scheduledCloseCallback != null) return 0; | 26 if (_closeCallbackCalled || _scheduledCloseCallback != null) return 0; |
| 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 = min(len, available()); | 30 int bytesToRead = 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]) { | 34 void pipe(OutputStream output, {bool close: true}) { |
| 35 _pipe(this, output, close: close); | 35 _pipe(this, output, close: close); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void close() { | 38 void close() { |
| 39 _cancelScheduledDataCallback(); | 39 _cancelScheduledDataCallback(); |
| 40 _close(); | 40 _close(); |
| 41 _checkScheduleCallbacks(); | 41 _checkScheduleCallbacks(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool get closed => _closeCallbackCalled; | 44 bool get closed => _closeCallbackCalled; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 bool _closeCallbackCalled = false; | 138 bool _closeCallbackCalled = false; |
| 139 | 139 |
| 140 Timer _scheduledDataCallback; | 140 Timer _scheduledDataCallback; |
| 141 Timer _scheduledCloseCallback; | 141 Timer _scheduledCloseCallback; |
| 142 Function _clientDataHandler; | 142 Function _clientDataHandler; |
| 143 Function _clientCloseHandler; | 143 Function _clientCloseHandler; |
| 144 Function _clientErrorHandler; | 144 Function _clientErrorHandler; |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 void _pipe(InputStream input, OutputStream output, [bool close]) { | 148 void _pipe(InputStream input, OutputStream output, {bool close}) { |
| 149 Function pipeDataHandler; | 149 Function pipeDataHandler; |
| 150 Function pipeCloseHandler; | 150 Function pipeCloseHandler; |
| 151 Function pipeNoPendingWriteHandler; | 151 Function pipeNoPendingWriteHandler; |
| 152 | 152 |
| 153 Function _inputCloseHandler; | 153 Function _inputCloseHandler; |
| 154 | 154 |
| 155 pipeDataHandler = () { | 155 pipeDataHandler = () { |
| 156 List<int> data; | 156 List<int> data; |
| 157 while ((data = input.read()) !== null) { | 157 while ((data = input.read()) !== null) { |
| 158 if (!output.write(data)) { | 158 if (!output.write(data)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 181 output.onNoPendingWrites = null; | 181 output.onNoPendingWrites = null; |
| 182 } | 182 } |
| 183 | 183 |
| 184 | 184 |
| 185 class _BaseOutputStream { | 185 class _BaseOutputStream { |
| 186 bool writeString(String string, [Encoding encoding = Encoding.UTF_8]) { | 186 bool writeString(String string, [Encoding encoding = Encoding.UTF_8]) { |
| 187 if (string.length > 0) { | 187 if (string.length > 0) { |
| 188 // Encode and write data. | 188 // Encode and write data. |
| 189 _StringEncoder encoder = _StringEncoders.encoder(encoding); | 189 _StringEncoder encoder = _StringEncoders.encoder(encoding); |
| 190 List<int> data = encoder.encodeString(string); | 190 List<int> data = encoder.encodeString(string); |
| 191 return write(data, copyBuffer: false); | 191 return write(data, false); |
| 192 } | 192 } |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void set onError(void callback(e)) { | 196 void set onError(void callback(e)) { |
| 197 _onError = callback; | 197 _onError = callback; |
| 198 } | 198 } |
| 199 | 199 |
| 200 void _reportError(e) { | 200 void _reportError(e) { |
| 201 if (_onError != null) { | 201 if (_onError != null) { |
| 202 _onError(e); | 202 _onError(e); |
| 203 } else { | 203 } else { |
| 204 throw e; | 204 throw e; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 Function _onError; | 208 Function _onError; |
| 209 } | 209 } |
| OLD | NEW |