File, ByteStream & Network

ByteOutStream

Base class for writing binary data.

Cache:

ByteInStream

Base class for reading binary data.

Cache:

ByteStream

Base class for input and output of binary data, derived from BasicStream, ByteInStream, and ByteOutStream.

File IO

RandomAccessByteStream

Abstract base class derived from ByteStream, with additional functions to access/modify the size and current position (e.g. seeking):

File

Class derived from RandomAccessByteStream:

MemoryStream

Class derived from RandomAccessByteStream:

Network & Device IO

NetworkConnection

Abstract base class derived from ByteStream, a base class for TCP/IP, Bluetooth RFCOMM, infrared, …

TcpConnection

Class derived from NetworkConnection:

TcpConnectionListener

Listens for incoming TCP connections.

LocalConnection

A byte stream for local inter-process communication. Derived from ByteStream, base class for Pipe and UnixDomainConnection in stream configuration:

LocalConnectionListener

Listens for local inter-process connections.

SerialPort

Class for RS-232/UART:

MessageChannel

Interface for message/packet/frame/datagram-based protocols, preserving message boundaries (i.e. not only a stream of bytes).

Is implemented by:

High Performance I/O

The stream interface combines a simple, convenient API with high performance: frequently used operations such as write(Byte/Int/Float/...) and read(...) are implemented as inline and buffered functions, so the common path stays cheap. Data is transferred between user-level buffers and the underlying file/pipe/socket/etc. in larger blocks through a small set of virtual writeRaw() / readRaw() operations, minimizing function calls, system calls, and memory allocations.

For bulk transfers, Span<Byte> allows callers to operate directly on existing memory without additional allocations or copies. readInto() is particularly efficient because the caller-provided buffer is reused.

Class Hierarchy

ByteStream is implemented by:

flowchart LR
    BasicStream[BasicStream]

    TextStream([TextStream])
    TextInStream([TextInStream])
    TextOutStream([TextOutStream])

    TextFile[TextFile]
    StringStream[StringStream]

    ByteStream[ByteStream]
    ByteInStream[ByteInStream]
    ByteOutStream[ByteOutStream]
    
    RandomAccessByteStream([RandomAccessByteStream])
    File[File]
    MemoryStream[MemoryStream]

    NetworkConnection([NetworkConnection])
    TcpConnection[TcpConnection]
    TlsConnection[TlsConnection]
    SshConnection[SshConnection]
    LocalConnection([LocalConnection])
    Pipe[Pipe]
    UnixDomainConnection[UnixDomainConnection]
    DeviceConnection([DeviceConnection])
    SerialPort[SerialPort]
    UsbConnection[UsbConnection]
    BluetoothRfcommConnection[BluetoothRfcommConnection]
    
    TextFile -..-> TextStream
    StringStream -..-> TextStream

    TextStream --> TextInStream
    TextStream --> TextOutStream

    TextInStream --> BasicStream
    TextOutStream --> BasicStream

    File -.-> RandomAccessByteStream
    MemoryStream -.-> RandomAccessByteStream
    RandomAccessByteStream -.-> ByteStream

    NetworkConnection --> ByteStream
    LocalConnection --> ByteStream
    DeviceConnection --> ByteStream
    BluetoothRfcommConnection -..-> ByteStream
    
    TcpConnection -.-> NetworkConnection
    TlsConnection -.-> TcpConnection
    SshConnection -.-> NetworkConnection
    
    Pipe -.-> LocalConnection
    UnixDomainConnection -.-> LocalConnection
    
    SerialPort -.-> DeviceConnection
    UsbConnection -.-> DeviceConnection
    
    ByteStream --> ByteInStream
    ByteStream --> ByteOutStream

    ByteInStream --> BasicStream
    ByteOutStream --> BasicStream