| 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Utility class that holds a number of byte buffers and can deliver | 8 * Utility class that holds a number of byte buffers and can deliver |
| 9 * the bytes either one by one or in chunks. | 9 * the bytes either one by one or in chunks. |
| 10 */ | 10 */ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return value; | 62 return value; |
| 63 } | 63 } |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Read [count] bytes from the buffer list. If the number of bytes | 66 * Read [count] bytes from the buffer list. If the number of bytes |
| 67 * requested is not available null will be returned. | 67 * requested is not available null will be returned. |
| 68 */ | 68 */ |
| 69 List<int> readBytes([int count]) { | 69 List<int> readBytes([int count]) { |
| 70 if (count == null) count = length; | 70 if (count == null) count = length; |
| 71 List<int> result; | 71 List<int> result; |
| 72 if (_length == 0 || _length < count) return null; | 72 if (_length == 0) return new Uint8List(0); |
| 73 if (_length < count) return null; |
| 73 if (_index == 0 && _buffers.first.length == count) { | 74 if (_index == 0 && _buffers.first.length == count) { |
| 74 result = _buffers.first; | 75 result = _buffers.first; |
| 75 _buffers.removeFirst(); | 76 _buffers.removeFirst(); |
| 76 _index = 0; | 77 _index = 0; |
| 77 _length -= count; | 78 _length -= count; |
| 78 return result; | 79 return result; |
| 79 } else { | 80 } else { |
| 80 int firstRemaining = _buffers.first.length - _index; | 81 int firstRemaining = _buffers.first.length - _index; |
| 81 if (firstRemaining >= count) { | 82 if (firstRemaining >= count) { |
| 82 result = _buffers.first.sublist(_index, _index + count); | 83 result = _buffers.first.sublist(_index, _index + count); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void clear() { | 152 void clear() { |
| 152 _index = 0; | 153 _index = 0; |
| 153 _length = 0; | 154 _length = 0; |
| 154 _buffers = new Queue(); | 155 _buffers = new Queue(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 int _length; // Total number of bytes remaining in the buffers. | 158 int _length; // Total number of bytes remaining in the buffers. |
| 158 Queue<List<int>> _buffers; // List of data buffers. | 159 Queue<List<int>> _buffers; // List of data buffers. |
| 159 int _index; // Index of the next byte in the first buffer. | 160 int _index; // Index of the next byte in the first buffer. |
| 160 } | 161 } |
| OLD | NEW |