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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/list_input_stream.dart
diff --git a/runtime/bin/list_input_stream.dart b/runtime/bin/list_input_stream.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a4da847b111b2cfdf9bb1ad396fad13d83658428
--- /dev/null
+++ b/runtime/bin/list_input_stream.dart
@@ -0,0 +1,62 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class ListInputStream extends _BaseDataInputStream implements InputStream {
+ 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
+ : _buffer = buffer {
+ _streamMarkedClosed = true;
+ }
+
+ int available() => _buffer.length - _offset;
+
+ List<int> _read(int bytesToRead) {
+ if (_offset == 0 && bytesToRead == _buffer.length) {
+ _offset = _buffer.length;
+ return _buffer;
+ } else {
+ List<int> result = _buffer.getRange(_offset, bytesToRead);
+ _offset += bytesToRead;
+ return result;
+ }
+ }
+
+ int _readInto(List<int> buffer, int offset, int bytesToRead) {
+ buffer.setRange(offset, bytesToRead, _buffer, _offset);
+ _offset += bytesToRead;
+ return bytesToRead;
+ }
+
+ List<int> _buffer;
+ int _offset = 0;
+}
+
+
+class DynamicListInputStream
+ extends _BaseDataInputStream implements InputStream {
+ DynamicListInputStream() : _bufferList = new _BufferList();
+
+ int available() => _bufferList.length;
+
+ void write(List<int> data) {
+ _bufferList.add(data);
+ _checkScheduleCallbacks();
+ }
+
+ void markEndOfStream() {
+ _streamMarkedClosed = true;
+ _checkScheduleCallbacks();
+ }
+
+ List<int> _read(int bytesToRead) {
+ return _bufferList.readBytes(bytesToRead);
+ }
+
+ int _readInto(List<int> buffer, int offset, int bytesToRead) {
+ List<int> tmp = _bufferList.readBytes(byteToRead);
+ buffer.setRange(offset, bytesToRead, tmp, _offset);
+ return bytesToRead;
+ }
+
+ _BufferList _bufferList;
+}

Powered by Google App Engine
This is Rietveld 408576698