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

Unified Diff: sdk/lib/io/chunked_stream.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/_internal/dartdoc/lib/dartdoc.dart ('k') | sdk/lib/io/directory.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/chunked_stream.dart
diff --git a/sdk/lib/io/chunked_stream.dart b/sdk/lib/io/chunked_stream.dart
deleted file mode 100644
index 07fd9b46858c0f485e56847f1ac620e6a0e638af..0000000000000000000000000000000000000000
--- a/sdk/lib/io/chunked_stream.dart
+++ /dev/null
@@ -1,140 +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;
-
-class _ChunkedInputStream implements ChunkedInputStream {
- _ChunkedInputStream(InputStream this._input, int this._chunkSize)
- : _bufferList = new _BufferList() {
- _input.onClosed = _onClosed;
- }
-
- List<int> read() {
- if (_closed) return null;
- var result = _bufferList.readBytes(_chunkSize);
- if (result == null) {
- _readData();
- result = _bufferList.readBytes(_chunkSize);
- }
- if (result == null && _inputClosed) {
- if (_bufferList.length == 0) {
- result = null;
- } else {
- result = _bufferList.readBytes(_bufferList.length);
- }
- }
- _checkInstallDataHandler();
- return result;
- }
-
- int get chunkSize => _chunkSize;
-
- void set chunkSize(int chunkSize) {
- _chunkSize = chunkSize;
- _checkInstallDataHandler();
- _checkScheduleCallback();
- }
-
- bool get closed => _closed;
-
- void set onData(void callback()) {
- _clientDataHandler = callback;
- _checkInstallDataHandler();
- }
-
- void set onClosed(void callback()) {
- _clientCloseHandler = callback;
- }
-
- void set onError(void callback(e)) {
- _input.onError = callback;
- }
-
- void _onData() {
- _readData();
- if (_bufferList.length >= _chunkSize && _clientDataHandler != null) {
- _clientDataHandler();
- }
- _checkScheduleCallback();
- _checkInstallDataHandler();
- }
-
- void _readData() {
- List<int> data = _input.read();
- if (data != null) {
- _bufferList.add(data);
- }
- }
-
- void _onClosed() {
- _inputClosed = true;
- if (_bufferList.length == 0 && _clientCloseHandler != null) {
- _clientCloseHandler();
- _closed = true;
- } else {
- _checkScheduleCallback();
- }
- }
-
- void _checkInstallDataHandler() {
- if (_clientDataHandler == null) {
- _input.onData = null;
- } else {
- if (_bufferList.length < _chunkSize && !_inputClosed) {
- _input.onData = _onData;
- } else {
- _input.onData = null;
- }
- }
- }
-
- void _checkScheduleCallback() {
- // TODO(sgjesse): Find a better way of scheduling callbacks from
- // the event loop.
- void issueDataCallback() {
- _scheduledDataCallback = null;
- if (_clientDataHandler != null) {
- _clientDataHandler();
- _checkScheduleCallback();
- }
- }
-
- void issueCloseCallback() {
- _scheduledCloseCallback = null;
- if (!_closed) {
- if (_clientCloseHandler != null) _clientCloseHandler();
- _closed = true;
- }
- }
-
- // Schedule data callback if enough data in buffer.
- if ((_bufferList.length >= _chunkSize ||
- (_bufferList.length > 0 && _inputClosed)) &&
- _clientDataHandler != null &&
- _scheduledDataCallback == null) {
- _scheduledDataCallback = Timer.run(issueDataCallback);
- }
-
- // Schedule close callback if no more data and input is closed.
- if (_bufferList.length == 0 &&
- _inputClosed &&
- !_closed &&
- _scheduledCloseCallback == null) {
- if (_scheduledDataCallback != null) {
- _scheduledDataCallback.cancel();
- }
- _scheduledCloseCallback = Timer.run(issueCloseCallback);
- }
- }
-
- InputStream _input;
- _BufferList _bufferList;
- int _chunkSize;
- bool _inputClosed = false; // Is the underlying input stream closed?
- bool _closed = false; // Has the close handler been called?.
- Timer _scheduledDataCallback;
- Timer _scheduledCloseCallback;
- Function _clientDataHandler;
- Function _clientCloseHandler;
-}
« no previous file with comments | « sdk/lib/_internal/dartdoc/lib/dartdoc.dart ('k') | sdk/lib/io/directory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698