<commit_before>// 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.

library streamed_request;

import 'dart:io';
import 'dart:uri';

import 'base_request.dart';

/// An HTTP request where the request body is sent asynchronously after the
/// connection has been established and the headers have been sent.
///
/// When the request is sent via [BaseClient.send], only the headers and
/// whatever data has already been written to [StreamedRequest.stream] will be
/// sent immediately. More data will be sent as soon as it's written to
/// [StreamedRequest.stream], and when the stream is closed the request will
/// end.
class StreamedRequest extends BaseRequest {
  /// The stream to which to write data that will be sent as the request body.
  /// This may be safely written to before the request is sent; the data will be
  /// buffered.
  ///
  /// Closing this signals the end of the request.
  OutputStream get stream => _outputStream;

  /// [stream], stored as a [ListOutputStream].
  final ListOutputStream _outputStream;

  /// The stream from which the [BaseClient] will read the data in [stream] once
  /// the request has been finalized.
  final ListInputStream _inputStream;

  /// Creates a new streaming request.
  StreamedRequest(String method, Uri url)
    : super(method, url),
      _outputStream = new ListOutputStream(),
      _inputStream = new ListInputStream() {
    // TODO(nweiz): pipe errors from the output stream to the input stream once
    // issue 3657 is fixed
    _outputStream.onData = () => _inputStream.write(_outputStream.read());
    _outputStream.onClosed = _inputStream.markEndOfStream;
  }

  /// Freezes all mutable fields other than [stream] and returns an [InputStream]
  /// that emits the data being written to [stream].
  InputStream finalize() {
    super.finalize();<commit_msg>Code review change for r16238.<commit_after>// 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.

library streamed_request;

import 'dart:io';
import 'dart:uri';

import 'base_request.dart';

/// An HTTP request where the request body is sent asynchronously after the
/// connection has been established and the headers have been sent.
///
/// When the request is sent via [BaseClient.send], only the headers and
/// whatever data has already been written to [StreamedRequest.stream] will be
/// sent immediately. More data will be sent as soon as it's written to
/// [StreamedRequest.stream], and when the stream is closed the request will
/// end.
class StreamedRequest extends BaseRequest {
  /// The stream to which to write data that will be sent as the request body.
  /// This may be safely written to before the request is sent; the data will be
  /// buffered.
  ///
  /// Closing this signals the end of the request.
  final OutputStream stream;

  /// The stream from which the [BaseClient] will read the data in [stream] once
  /// the request has been finalized.
  final ListInputStream _inputStream;

  /// Creates a new streaming request.
  StreamedRequest(String method, Uri url)
    : super(method, url),
      stream = new ListOutputStream(),
      _inputStream = new ListInputStream() {
    ListOutputStream outputStream = stream;
    // TODO(nweiz): pipe errors from the output stream to the input stream once
    // issue 3657 is fixed
    outputStream.onData = () => _inputStream.write(outputStream.read());
    outputStream.onClosed = _inputStream.markEndOfStream;
  }

  /// Freezes all mutable fields other than [stream] and returns an [InputStream]
  /// that emits the data being written to [stream].
  InputStream finalize() {
    super.finalize();
{'fraction_non_alphanumeric': 0.08878148053930297, 'fraction_numerical': 0.0053421521241414395, 'mean_word_length': 3.378619153674833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4026778', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1010, 'n_words': 491}