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

Unified Diff: sdk/lib/io/list_stream_impl.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/list_stream.dart ('k') | sdk/lib/io/process.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/list_stream_impl.dart
diff --git a/sdk/lib/io/list_stream_impl.dart b/sdk/lib/io/list_stream_impl.dart
deleted file mode 100644
index e5933848d10113b1028da58ce985c81935fe401c..0000000000000000000000000000000000000000
--- a/sdk/lib/io/list_stream_impl.dart
+++ /dev/null
@@ -1,161 +0,0 @@
-// Copyright (c) 2012, 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.
-
-part of dart.io;
-
-/**
- * Default implementation of [ListInputStream].
- */
-class _ListInputStream extends _BaseDataInputStream implements ListInputStream {
- _ListInputStream() : _bufferList = new _BufferList();
-
- void write(List<int> data) {
- if (_streamMarkedClosed) {
- throw new StreamException.streamClosed();
- }
- _bufferList.add(data);
- _checkScheduleCallbacks();
- }
-
- void markEndOfStream() {
- _streamMarkedClosed = true;
- _checkScheduleCallbacks();
- }
-
- int available() => _bufferList.length;
-
- List<int> _read(int bytesToRead) {
- return _bufferList.readBytes(bytesToRead);
- }
-
- int _readInto(List<int> buffer, int offset, int bytesToRead) {
- List<int> tmp = _bufferList.readBytes(bytesToRead);
- buffer.setRange(offset, bytesToRead, tmp, 0);
- return bytesToRead;
- }
-
- void _close() {
- _streamMarkedClosed = true;
- _bufferList.clear();
- }
-
- _BufferList _bufferList;
-}
-
-
-class _ListOutputStream extends _BaseOutputStream implements ListOutputStream {
- _ListOutputStream() : _bufferList = new _BufferList();
-
- List<int> read() => _bufferList.readBytes(_bufferList.length);
-
- bool write(List<int> buffer, [bool copyBuffer = true]) {
- if (_streamMarkedClosed) throw new StreamException.streamClosed();
- if (copyBuffer) {
- _bufferList.add(buffer.getRange(0, buffer.length));
- } else {
- _bufferList.add(buffer);
- }
- _checkScheduleCallbacks();
- return true;
- }
-
- bool writeFrom(List<int> buffer, [int offset = 0, int len]) {
- return write(
- buffer.getRange(offset, (len == null) ? buffer.length - offset : len),
- false);
- }
-
- void flush() {
- // Nothing to do on a list output stream.
- }
-
- void close() {
- if (_streamMarkedClosed) throw new StreamException.streamClosed();
- _streamMarkedClosed = true;
- _checkScheduleCallbacks();
- }
-
- void destroy() {
- close();
- }
-
- void set onData(void callback()) {
- _clientDataHandler = callback;
- _checkScheduleCallbacks();
- }
-
- void set onNoPendingWrites(void callback()) {
- _clientNoPendingWriteHandler = callback;
- _checkScheduleCallbacks();
- }
-
- void set onClosed(void callback()) {
- _clientCloseHandler = callback;
- }
-
- void set onError(void callback(e)) {
- // No errors emitted.
- }
-
- void _checkScheduleCallbacks() {
- void issueDataCallback() {
- _scheduledDataCallback = null;
- if (_clientDataHandler != null) {
- _clientDataHandler();
- _checkScheduleCallbacks();
- }
- }
-
- void issueNoPendingWriteCallback() {
- _scheduledNoPendingWriteCallback = null;
- if (_clientNoPendingWriteHandler != null &&
- !_streamMarkedClosed) {
- _clientNoPendingWriteHandler();
- _checkScheduleCallbacks();
- }
- }
-
- void issueCloseCallback() {
- _scheduledCloseCallback = null;
- if (_clientCloseHandler != null) _clientCloseHandler();
- }
-
- // Schedule no pending callback if there is a callback set as this
- // output stream does not wait for any transmission. Schedule
- // close callback once when the stream is closed. Only schedule a
- // new callback if the previous one has actually been called.
- if (_closeCallbackCalled) return;
-
- if (!_streamMarkedClosed) {
- if (!_bufferList.isEmpty &&
- _clientDataHandler != null &&
- _scheduledDataCallback == null) {
- _scheduledDataCallback = Timer.run(issueDataCallback);
- }
-
- if (_clientNoPendingWriteHandler != null &&
- _scheduledNoPendingWriteCallback == null &&
- _scheduledDataCallback == null) {
- _scheduledNoPendingWriteCallback =
- Timer.run(issueNoPendingWriteCallback);
- }
-
- } else if (_clientCloseHandler != null) {
- _scheduledCloseCallback = Timer.run(issueCloseCallback);
- _closeCallbackCalled = true;
- }
- }
-
- bool get closed => _streamMarkedClosed;
-
- _BufferList _bufferList;
- bool _streamMarkedClosed = false;
- bool _closeCallbackCalled = false;
- Timer _scheduledDataCallback;
- Timer _scheduledNoPendingWriteCallback;
- Timer _scheduledCloseCallback;
- Function _clientDataHandler;
- Function _clientNoPendingWriteHandler;
- Function _clientCloseHandler;
-}
« no previous file with comments | « sdk/lib/io/list_stream.dart ('k') | sdk/lib/io/process.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698