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

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

Issue 9289042: Minor changes to the dart:io library files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing files. Created 8 years, 11 months 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/list_stream.dart ('k') | runtime/bin/process.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, 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 class ListInputStream extends _BaseDataInputStream implements InputStream { 5 /**
6 ListInputStream(List<int> this._buffer) { 6 * Default implementation of [ListInputStream].
7 _streamMarkedClosed = true; 7 */
8 } 8 class _ListInputStream extends _BaseDataInputStream implements ListInputStream {
9 9 _ListInputStream() : _bufferList = new _BufferList();
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 void _close() {
30 _offset = _buffer.length;
31 }
32
33 List<int> _buffer;
34 int _offset = 0;
35 }
36
37
38 class DynamicListInputStream
39 extends _BaseDataInputStream implements InputStream {
40 DynamicListInputStream() : _bufferList = new _BufferList();
41
42 int available() => _bufferList.length;
43 10
44 void write(List<int> data) { 11 void write(List<int> data) {
45 if (_streamMarkedClosed) { 12 if (_streamMarkedClosed) {
46 throw new StreamException.streamClosed(); 13 throw new StreamException.streamClosed();
47 } 14 }
48 _bufferList.add(data); 15 _bufferList.add(data);
49 _checkScheduleCallbacks(); 16 _checkScheduleCallbacks();
50 } 17 }
51 18
52 void markEndOfStream() { 19 void markEndOfStream() {
53 _streamMarkedClosed = true; 20 _streamMarkedClosed = true;
54 _checkScheduleCallbacks(); 21 _checkScheduleCallbacks();
55 } 22 }
56 23
24 int available() => _bufferList.length;
25
57 List<int> _read(int bytesToRead) { 26 List<int> _read(int bytesToRead) {
58 return _bufferList.readBytes(bytesToRead); 27 return _bufferList.readBytes(bytesToRead);
59 } 28 }
60 29
61 int _readInto(List<int> buffer, int offset, int bytesToRead) { 30 int _readInto(List<int> buffer, int offset, int bytesToRead) {
62 List<int> tmp = _bufferList.readBytes(byteToRead); 31 List<int> tmp = _bufferList.readBytes(bytesToRead);
63 buffer.setRange(offset, bytesToRead, tmp, _offset); 32 buffer.setRange(offset, bytesToRead, tmp, 0);
64 return bytesToRead; 33 return bytesToRead;
65 } 34 }
66 35
67 void _close() { 36 void _close() {
68 _streamMarkedClosed = true; 37 _streamMarkedClosed = true;
69 _bufferList.clear(); 38 _bufferList.clear();
70 } 39 }
71 40
72 _BufferList _bufferList; 41 _BufferList _bufferList;
73 } 42 }
74 43
75 44
76 class ListOutputStream implements OutputStream { 45 class _ListOutputStream implements ListOutputStream {
77 ListOutputStream() : _bufferList = new _BufferList(); 46 _ListOutputStream() : _bufferList = new _BufferList();
47
48 List<int> contents() => _bufferList.readBytes(_bufferList.length);
78 49
79 bool write(List<int> buffer, [bool copyBuffer = false]) { 50 bool write(List<int> buffer, [bool copyBuffer = false]) {
80 if (_streamMarkedClosed) throw new StreamException.streamClosed(); 51 if (_streamMarkedClosed) throw new StreamException.streamClosed();
81 if (copyBuffer) { 52 if (copyBuffer) {
82 _bufferList.add(buffer.getRange(0, buffer.length)); 53 _bufferList.add(buffer.getRange(0, buffer.length));
83 } else { 54 } else {
84 _bufferList.add(buffer); 55 _bufferList.add(buffer);
85 } 56 }
86 return true; 57 return true;
87 } 58 }
(...skipping 20 matching lines...) Expand all
108 } 79 }
109 80
110 void set closeHandler(void callback()) { 81 void set closeHandler(void callback()) {
111 _clientCloseHandler = callback; 82 _clientCloseHandler = callback;
112 } 83 }
113 84
114 void set errorHandler(void callback()) { 85 void set errorHandler(void callback()) {
115 // No errors emitted. 86 // No errors emitted.
116 } 87 }
117 88
118 List<int> contents() => _bufferList.readBytes(_bufferList.length);
119
120 void _checkScheduleCallbacks() { 89 void _checkScheduleCallbacks() {
121 void issueNoPendingWriteCallback(Timer timer) { 90 void issueNoPendingWriteCallback(Timer timer) {
122 _scheduledNoPendingWriteCallback = null; 91 _scheduledNoPendingWriteCallback = null;
123 if (_clientNoPendingWriteHandler !== null) { 92 if (_clientNoPendingWriteHandler !== null) {
124 _clientNoPendingWriteHandler(); 93 _clientNoPendingWriteHandler();
125 _checkScheduleCallbacks(); 94 _checkScheduleCallbacks();
126 } 95 }
127 } 96 }
128 97
129 void issueCloseCallback(Timer timer) { 98 void issueCloseCallback(Timer timer) {
(...skipping 22 matching lines...) Expand all
152 } 121 }
153 122
154 _BufferList _bufferList; 123 _BufferList _bufferList;
155 bool _streamMarkedClosed = false; 124 bool _streamMarkedClosed = false;
156 bool _closeCallbackCalled = false; 125 bool _closeCallbackCalled = false;
157 Timer _scheduledNoPendingWriteCallback; 126 Timer _scheduledNoPendingWriteCallback;
158 Timer _scheduledCloseCallback; 127 Timer _scheduledCloseCallback;
159 Function _clientNoPendingWriteHandler; 128 Function _clientNoPendingWriteHandler;
160 Function _clientCloseHandler; 129 Function _clientCloseHandler;
161 } 130 }
OLDNEW
« no previous file with comments | « runtime/bin/list_stream.dart ('k') | runtime/bin/process.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698