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

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

Issue 8989019: Implement list based output stream and add pipe to list based input streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ 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
« no previous file with comments | « runtime/bin/input_stream.dart ('k') | runtime/bin/list_stream.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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> this._buffer) {
7 _streamMarkedClosed = true;
8 }
9
10 int available() => _buffer.length - _offset;
11
12 List<int> _read(int bytesToRead) {
13 if (_offset == 0 && bytesToRead == _buffer.length) {
14 _offset = _buffer.length;
15 return _buffer;
16 } else {
17 List<int> result = _buffer.getRange(_offset, bytesToRead);
18 _offset += bytesToRead;
19 return result;
20 }
21 }
22
23 int _readInto(List<int> buffer, int offset, int bytesToRead) {
24 buffer.setRange(offset, bytesToRead, _buffer, _offset);
25 _offset += bytesToRead;
26 return bytesToRead;
27 }
28
29 List<int> _buffer;
30 int _offset = 0;
31 }
32
33
34 class DynamicListInputStream
35 extends _BaseDataInputStream implements InputStream {
36 DynamicListInputStream() : _bufferList = new _BufferList();
37
38 int available() => _bufferList.length;
39
40 void write(List<int> data) {
41 _bufferList.add(data);
42 _checkScheduleCallbacks();
43 }
44
45 void markEndOfStream() {
46 _streamMarkedClosed = true;
47 _checkScheduleCallbacks();
48 }
49
50 List<int> _read(int bytesToRead) {
51 return _bufferList.readBytes(bytesToRead);
52 }
53
54 int _readInto(List<int> buffer, int offset, int bytesToRead) {
55 List<int> tmp = _bufferList.readBytes(byteToRead);
56 buffer.setRange(offset, bytesToRead, tmp, _offset);
57 return bytesToRead;
58 }
59
60 _BufferList _bufferList;
61 }
OLDNEW
« no previous file with comments | « runtime/bin/input_stream.dart ('k') | runtime/bin/list_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698