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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if (_length == 0 || _length < count) return null; | 72 if (_length == 0 || _length < count) return null; |
73 if (_index == 0 && _buffers.first.length == count) { | 73 if (_index == 0 && _buffers.first.length == count) { |
74 result = _buffers.first; | 74 result = _buffers.first; |
75 _buffers.removeFirst(); | 75 _buffers.removeFirst(); |
76 _index = 0; | 76 _index = 0; |
77 _length -= count; | 77 _length -= count; |
78 return result; | 78 return result; |
79 } else { | 79 } else { |
80 int firstRemaining = _buffers.first.length - _index; | 80 int firstRemaining = _buffers.first.length - _index; |
81 if (firstRemaining >= count) { | 81 if (firstRemaining >= count) { |
82 result = _buffers.first.getRange(_index, count); | 82 result = _buffers.first.sublist(_index, _index + count); |
83 _index += count; | 83 _index += count; |
84 _length -= count; | 84 _length -= count; |
85 if (_index == _buffers.first.length) { | 85 if (_index == _buffers.first.length) { |
86 _buffers.removeFirst(); | 86 _buffers.removeFirst(); |
87 _index = 0; | 87 _index = 0; |
88 } | 88 } |
89 return result; | 89 return result; |
90 } else { | 90 } else { |
91 result = new Uint8List(count); | 91 result = new Uint8List(count); |
92 int remaining = count; | 92 int remaining = count; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void clear() { | 151 void clear() { |
152 _index = 0; | 152 _index = 0; |
153 _length = 0; | 153 _length = 0; |
154 _buffers = new Queue(); | 154 _buffers = new Queue(); |
155 } | 155 } |
156 | 156 |
157 int _length; // Total number of bytes remaining in the buffers. | 157 int _length; // Total number of bytes remaining in the buffers. |
158 Queue<List<int>> _buffers; // List of data buffers. | 158 Queue<List<int>> _buffers; // List of data buffers. |
159 int _index; // Index of the next byte in the first buffer. | 159 int _index; // Index of the next byte in the first buffer. |
160 } | 160 } |
OLD | NEW |