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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 _buffers.removeFirst(); | 59 _buffers.removeFirst(); |
60 _index = 0; | 60 _index = 0; |
61 } | 61 } |
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 List<int> result; | 71 List<int> result; |
71 if (_length == 0 || _length < count) return null; | 72 if (_length == 0 || _length < count) return null; |
72 if (_index == 0 && _buffers.first.length == count) { | 73 if (_index == 0 && _buffers.first.length == count) { |
73 result = _buffers.first; | 74 result = _buffers.first; |
74 _buffers.removeFirst(); | 75 _buffers.removeFirst(); |
75 _index = 0; | 76 _index = 0; |
76 _length -= count; | 77 _length -= count; |
77 return result; | 78 return result; |
78 } else { | 79 } else { |
79 int firstRemaining = _buffers.first.length - _index; | 80 int firstRemaining = _buffers.first.length - _index; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 void clear() { | 151 void clear() { |
151 _index = 0; | 152 _index = 0; |
152 _length = 0; | 153 _length = 0; |
153 _buffers = new Queue(); | 154 _buffers = new Queue(); |
154 } | 155 } |
155 | 156 |
156 int _length; // Total number of bytes remaining in the buffers. | 157 int _length; // Total number of bytes remaining in the buffers. |
157 Queue<List<int>> _buffers; // List of data buffers. | 158 Queue<List<int>> _buffers; // List of data buffers. |
158 int _index; // Index of the next byte in the first buffer. | 159 int _index; // Index of the next byte in the first buffer. |
159 } | 160 } |
OLD | NEW |