InputStream class abstract
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();
}
- Implemented types
- Implementers
Constructors
- InputStream()
- This abstract class is the superclass of all classes representing an input stream of bytes.
Properties
Methods
-
available(
) → Future< int> - Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
-
checkClosed(
) → void - Checks if the stream is closed and throws an exception if it is.
-
close(
) → Future< void> -
Closes this input stream and releases any system resources associated
with the stream.
override
-
mark(
int readLimit) → void - Marks the current position in this input stream.
-
markSupported(
) → bool - Tests if this input stream supports the mark and reset methods.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
List< int> b, [int offset = 0, int? length]) → Future<int> -
Reads some number of bytes from the input stream and stores them into
the buffer array
b
. -
readAll(
) → Future< Uint8List> - Reads all remaining bytes from the input stream.
-
readByte(
) → Future< int> - Reads the next byte of data from the input stream.
-
readFully(
int length) → Future< Uint8List> -
Reads exactly
length
bytes from the input stream. -
reset(
) → Future< void> - Repositions this stream to the position at the time the mark method was last called on this input stream.
-
skip(
int n) → Future< int> -
Skips over and discards
n
bytes of data from this input stream. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited