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

class _FileInputStream extends _BaseDataInputStream implements InputStream {
  _FileInputStream(String name)
      : _data = [],
        _position = 0,
        _filePosition = 0 {
    var file = new File(name);
    var future = file.open(FileMode.READ);
    future.handleException((e) {
      _reportError(e);
      return true;
    });
    future.then(_setupOpenedFile);
  }

  _FileInputStream.fromStdio(int fd)
      : _data = [],
        _position = 0,
        _filePosition = 0 {
    assert(fd == 0);
    _setupOpenedFile(_File._openStdioSync(fd));
  }

  void _setupOpenedFile(RandomAccessFile openedFile) {
    _openedFile = openedFile;
    var chained = _openedFile.length().chain((len) {
      _fileLength = len;
      return _fillBuffer();
    });
    chained.handleException((e) {
      _reportError(e);
      return true;
    });
    chained.then((ignored) => _checkScheduleCallbacks());
  }

  Future<int> _fillBuffer() {
    Expect.equals(_position, _data.length);
    Expect.isTrue(_filePosition < _fileLength);

    int size = Math.min(_bufferLength, _fileLength - _filePosition);
    if (_data.length != size) {
      _data = new Uint8List(size);
    }
    var future = _openedFile.readList(_data, 0, _data.length);
    future = future.transform((read) {
      _filePosition += read;
      if (read != _data.length) {
        _data.removeRange(read, _data.length - read);
      }
      _position = 0;

      if (_fileLength == _filePosition) {
        _streamMarkedClosed = true;
        _openedFile.close();
      }
      return read;
    });
    return future;
  }
<commit_msg>Remove erroneous assert from dart:io's File class.<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.

class _FileInputStream extends _BaseDataInputStream implements InputStream {
  _FileInputStream(String name)
      : _data = [],
        _position = 0,
        _filePosition = 0 {
    var file = new File(name);
    var future = file.open(FileMode.READ);
    future.handleException((e) {
      _reportError(e);
      return true;
    });
    future.then(_setupOpenedFile);
  }

  _FileInputStream.fromStdio(int fd)
      : _data = [],
        _position = 0,
        _filePosition = 0 {
    assert(fd == 0);
    _setupOpenedFile(_File._openStdioSync(fd));
  }

  void _setupOpenedFile(RandomAccessFile openedFile) {
    _openedFile = openedFile;
    var chained = _openedFile.length().chain((len) {
      _fileLength = len;
      return _fillBuffer();
    });
    chained.handleException((e) {
      _reportError(e);
      return true;
    });
    chained.then((ignored) => _checkScheduleCallbacks());
  }

  Future<int> _fillBuffer() {
    Expect.equals(_position, _data.length);

    int size = Math.min(_bufferLength, _fileLength - _filePosition);
    if (size == 0) {
      _streamMarkedClosed = true;
      _openedFile.close();
      return new Future.immediate(0);
    }
    if (_data.length != size) {
      _data = new Uint8List(size);
    }
    var future = _openedFile.readList(_data, 0, _data.length);
    future = future.transform((read) {
      _filePosition += read;
      if (read != _data.length) {
        _data.removeRange(read, _data.length - read);
      }
      _position = 0;

      if (_fileLength == _filePosition) {
        _streamMarkedClosed = true;
        _openedFile.close();
      }
      return read;
    });
    return future;
  }

{'fraction_non_alphanumeric': 0.115088835852559, 'fraction_numerical': 0.006894722885176346, 'mean_word_length': 2.716256157635468, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '6582282', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1144, 'n_words': 281}