InputStream constructor

InputStream()

This abstract class is the superclass of all classes representing an input stream of bytes.

Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input.

Design Philosophy

The InputStream class provides a uniform interface for reading data from various sources such as files, network connections, or memory buffers. It follows the decorator pattern, allowing streams to be wrapped with additional functionality like buffering or filtering.

Example Usage

// Reading from a file
final input = FileInputStream('data.bin');
try {
  final buffer = Uint8List(1024);
  int bytesRead;
  while ((bytesRead = await input.read(buffer)) != -1) {
    // Process the data in buffer[0..bytesRead-1]
    processData(buffer.sublist(0, bytesRead));
  }
} finally {
  await input.close();
}

// Reading with buffering for better performance
final bufferedInput = BufferedInputStream(FileInputStream('large_file.bin'));
try {
  final data = await bufferedInput.readFully(1024);
  processData(data);
} finally {
  await bufferedInput.close();
}

Implementation

InputStream();