DataInputStream class Null safety

A coroutines-style wrapper around a Stream<List<int>>, like you get from a socket or a file in Dart. This lets you asynchronously read a stream using an API much like java.io.DataInputStream.

Note that this class does not read all of the data into a buffer first, so it is very space-efficient. It does, however, use asynchrony at a fairly granular level. This might have performance implications, depending on how efficient async/await are in current Dart implementations. As of this writing (Jan. 2020), I have not measured.

See also ByteBufferDataInputStream.

Constructors

DataInputStream(Stream<List<int>> source, [Endian endian = Endian.big])
Create a stream that takes its data from source with the given initial endian setting. Choose Endian.big for interoperability with java.io.DataInputStream.

Properties

bytesAvailable Future<int>
Returns the number of bytes that can be read from the internal buffer. If we're at EOF, returns zero, otherwise, returns a non-zero positive integer. If the buffer is currently exhausted, this method will wait for the next block of data to come in.
read-only
endian Endian
The current endian setting, either Endian.big or Endian.little. This is used for converting numeric types. Choose Endian.big for interoperability with java.io.DataInputStream.
read / write
hashCode int
The hash code for this object.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

close() Future<void>
Cancel our underling stream.
debugStream([Random? random]) Stream<Uint8List>
Test out the buffer logic by returning randomized, smallish chunks of data at a time. The stream obtained from this method can be fed into another DataInputStream.
isEOF() Future<bool>
Check if we're at end of file.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
read() Future<int>
Returns the next unsigned byte, or -1 on EOF
readBoolean() Future<bool>
Reads a byte, and returns false if it is 0, true otherwise.
readByte() Future<int>
Reads a signed byte. Returns an int between -128 and 127, inclusive. See also readUnsignedByte.
readByteDataImmutable(int num) Future<ByteData>
Returns a potentially immutable ByteData containing the desired number of bytes.
readBytes(int num) Future<Uint8List>
Returns a new, mutable Uint8List containing the desired number of bytes.
readBytesImmutable(int num) Future<Uint8List>
Returns a potentially immutable Uint8List containing the desired number of bytes.
readDouble() Future<double>
Reads and returns an 8-byte double, using the current endian setting.
readFloat() Future<double>
Reads and returns a 4-byte float, using the current endian setting.
readInt() Future<int>
Reads and returns a 4-byte signed integer decoded with the current endian setting.
readLong() Future<int>
Reads and returns an 8-byte integer decoded with the current endian setting.
readShort() Future<int>
Reads and returns a 2-byte signed integer decoded with the current endian setting.
readUnsignedByte() Future<int>
Reads and returns an unsigned byte.
readUnsignedInt() Future<int>
Reads and returns a 4-byte unsigned integer decoded with the current endian setting.
readUnsignedLong() Future<int>
Reads and returns an 8-byte integer, converted to a Dart int according to the semantics of ByteData.getUint64 using the current endian setting.
readUnsignedShort() Future<int>
Reads and returns a 2-byte unsigned integer decoded with the current endian setting.
readUTF8() Future<String>
Reads a string encoded in UTF8. This method first reads a 2 byte unsigned integer decoded with the current endian setting, giving the number of UTF8 bytes to read. It then reads those bytes, and converts them to a string using Dart's UTF8 conversion. This may be incompatible with java.io.DataOutputStream for a string that contains nulls.
remaining() Stream<Uint8List>
Give a stream containing our as-yet-unread bytes.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited