Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: runtime/bin/list_input_stream.dart

Issue 8953030: Add input streams based on supplying data from lists (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 class ListInputStream extends _BaseDataInputStream implements InputStream {
6 ListInputStream(List<int> buffer)
Mads Ager (google) 2011/12/19 15:04:18 this._buffer and remove the assignment line? Mayb
Søren Gjesse 2011/12/20 09:45:15 Why am I forgetting out good stuff? Changed to L
7 : _buffer = buffer {
8 _streamMarkedClosed = true;
9 }
10
11 int available() => _buffer.length - _offset;
12
13 List<int> _read(int bytesToRead) {
14 if (_offset == 0 && bytesToRead == _buffer.length) {
15 _offset = _buffer.length;
16 return _buffer;
17 } else {
18 List<int> result = _buffer.getRange(_offset, bytesToRead);
19 _offset += bytesToRead;
20 return result;
21 }
22 }
23
24 int _readInto(List<int> buffer, int offset, int bytesToRead) {
25 buffer.setRange(offset, bytesToRead, _buffer, _offset);
26 _offset += bytesToRead;
27 return bytesToRead;
28 }
29
30 List<int> _buffer;
31 int _offset = 0;
32 }
33
34
35 class DynamicListInputStream
36 extends _BaseDataInputStream implements InputStream {
37 DynamicListInputStream() : _bufferList = new _BufferList();
38
39 int available() => _bufferList.length;
40
41 void write(List<int> data) {
42 _bufferList.add(data);
43 _checkScheduleCallbacks();
44 }
45
46 void markEndOfStream() {
47 _streamMarkedClosed = true;
48 _checkScheduleCallbacks();
49 }
50
51 List<int> _read(int bytesToRead) {
52 return _bufferList.readBytes(bytesToRead);
53 }
54
55 int _readInto(List<int> buffer, int offset, int bytesToRead) {
56 List<int> tmp = _bufferList.readBytes(byteToRead);
57 buffer.setRange(offset, bytesToRead, tmp, _offset);
58 return bytesToRead;
59 }
60
61 _BufferList _bufferList;
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698