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

Unified Diff: sdk/lib/io/stream_util.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/stdio.dart ('k') | sdk/lib/io/string_stream.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/stream_util.dart
diff --git a/sdk/lib/io/stream_util.dart b/sdk/lib/io/stream_util.dart
deleted file mode 100644
index b68b8fd7c295af1ce3d9794da574177875a272b0..0000000000000000000000000000000000000000
--- a/sdk/lib/io/stream_util.dart
+++ /dev/null
@@ -1,211 +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;
-
-abstract class _BaseDataInputStream {
- int available();
-
- List<int> read([int len]) {
- if (_closeCallbackCalled || _scheduledCloseCallback != null) return null;
- int bytesToRead = available();
- if (bytesToRead == 0) {
- _checkScheduleCallbacks();
- return null;
- }
- if (len != null) {
- if (len <= 0) {
- throw new StreamException("Illegal length $len");
- } else if (bytesToRead > len) {
- bytesToRead = len;
- }
- }
- return _read(bytesToRead);
- }
-
- int readInto(List<int> buffer, [int offset = 0, int len]) {
- if (_closeCallbackCalled || _scheduledCloseCallback != null) return 0;
- if (len == null) len = buffer.length;
- if (offset < 0) throw new StreamException("Illegal offset $offset");
- if (len < 0) throw new StreamException("Illegal length $len");
- int bytesToRead = min(len, available());
- return _readInto(buffer, offset, bytesToRead);
- }
-
- void pipe(OutputStream output, {bool close: true}) {
- _pipe(this, output, close: close);
- }
-
- void close() {
- _cancelScheduledDataCallback();
- _close();
- _checkScheduleCallbacks();
- }
-
- bool get closed => _closeCallbackCalled;
-
- void set onData(void callback()) {
- _clientDataHandler = callback;
- _checkScheduleCallbacks();
- }
-
- void set onClosed(void callback()) {
- _clientCloseHandler = callback;
- _checkScheduleCallbacks();
- }
-
- void set onError(void callback(e)) {
- _clientErrorHandler = callback;
- }
-
- void _reportError(e) {
- if (_clientErrorHandler != null) {
- _clientErrorHandler(e);
- } else {
- throw e;
- }
- }
-
- List<int> _read(int bytesToRead);
-
- void _dataReceived() {
- // More data has been received asynchronously. Perform the data
- // handler callback now.
- _cancelScheduledDataCallback();
- if (_clientDataHandler != null) {
- _clientDataHandler();
- }
- _checkScheduleCallbacks();
- }
-
- void _closeReceived() {
- // Close indication has been received asynchronously. Perform the
- // close callback now if all data has been delivered.
- _streamMarkedClosed = true;
- if (available() == 0) {
- _closeCallbackCalled = true;
- if (_clientCloseHandler != null) _clientCloseHandler();
- } else {
- _checkScheduleCallbacks();
- }
- }
-
- void _cancelScheduledDataCallback() {
- if (_scheduledDataCallback != null) {
- _scheduledDataCallback.cancel();
- _scheduledDataCallback = null;
- }
- }
-
- void _checkScheduleCallbacks() {
- void issueDataCallback() {
- _scheduledDataCallback = null;
- if (_clientDataHandler != null) {
- _clientDataHandler();
- _checkScheduleCallbacks();
- }
- }
-
- void issueCloseCallback() {
- _scheduledCloseCallback = null;
- _closeCallbackCalled = true;
- if (_clientCloseHandler != null) _clientCloseHandler();
- }
-
- // Schedule data callback if there is more data to read. Schedule
- // close callback once when all data has been read. Only schedule
- // a new callback if the previous one has actually been called.
- if (!_closeCallbackCalled) {
- if (available() > 0) {
- if (_scheduledDataCallback == null) {
- _scheduledDataCallback = Timer.run(issueDataCallback);
- }
- } else if (_streamMarkedClosed && _scheduledCloseCallback == null) {
- _cancelScheduledDataCallback();
- _close();
- _scheduledCloseCallback = Timer.run(issueCloseCallback);
- }
- }
- }
-
- // When this is set to true the stream is marked closed. When a
- // stream is marked closed no more data can arrive and the value
- // from available is now all remaining data. If this is true and the
- // value of available is zero the close handler is called.
- bool _streamMarkedClosed = false;
-
- // When this is set to true the close callback has been called and
- // the stream is fully closed.
- bool _closeCallbackCalled = false;
-
- Timer _scheduledDataCallback;
- Timer _scheduledCloseCallback;
- Function _clientDataHandler;
- Function _clientCloseHandler;
- Function _clientErrorHandler;
-}
-
-
-void _pipe(InputStream input, OutputStream output, {bool close}) {
- Function pipeDataHandler;
- Function pipeCloseHandler;
- Function pipeNoPendingWriteHandler;
-
- Function _inputCloseHandler;
-
- pipeDataHandler = () {
- List<int> data;
- while ((data = input.read()) != null) {
- if (!output.write(data)) {
- input.onData = null;
- output.onNoPendingWrites = pipeNoPendingWriteHandler;
- break;
- }
- }
- };
-
- pipeCloseHandler = () {
- if (close) output.close();
- if (_inputCloseHandler != null) {
- _inputCloseHandler();
- }
- };
-
- pipeNoPendingWriteHandler = () {
- input.onData = pipeDataHandler;
- output.onNoPendingWrites = null;
- };
-
- _inputCloseHandler = input._clientCloseHandler;
- input.onData = pipeDataHandler;
- input.onClosed = pipeCloseHandler;
- output.onNoPendingWrites = null;
-}
-
-
-class _BaseOutputStream {
- bool writeString(String string, [Encoding encoding = Encoding.UTF_8]) {
- if (string.length > 0) {
- // Encode and write data.
- _StringEncoder encoder = _StringEncoders.encoder(encoding);
- List<int> data = encoder.encodeString(string);
- return write(data, false);
- }
- return true;
- }
-
- void set onError(void callback(e)) {
- _onError = callback;
- }
-
- void _reportError(e) {
- if (_onError != null) {
- _onError(e);
- } else {
- throw e;
- }
- }
-
- Function _onError;
-}
« no previous file with comments | « sdk/lib/io/stdio.dart ('k') | sdk/lib/io/string_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698