PgInputStream

internal class PgInputStream(inputStream: InputStream)

A highly optimized, buffered input stream tailored for the PostgreSQL wire protocol.

It provides specialized methods for efficiently reading protocol primitives like bytes, integers, shorts, and null-terminated C-style strings. Internal buffering is used to minimize network reads and object allocations.

Constructors

Link copied to clipboard
constructor(inputStream: InputStream)

Functions

Link copied to clipboard
fun changeStream(newStream: InputStream)

Swaps the underlying stream, discarding whatever is still buffered from the old one.

Link copied to clipboard

Whether a read would find something without waiting: bytes left in the buffer, or bytes the underlying stream already holds.

Link copied to clipboard
fun readByte(): Byte

Reads one byte, refilling the buffer if it is spent.

Link copied to clipboard
fun readBytes(length: Int): ByteArray

Returns exactly the specified number of bytes.

Link copied to clipboard

Reads a null-terminated string.

Link copied to clipboard
fun readFully(bytes: ByteArray, length: Int = bytes.size)

Fills bytes with exactly length bytes, reading as many times as it takes.

Link copied to clipboard
fun readInt(): Int

Reads a 32-bit integer, most significant byte first.

Link copied to clipboard

Reads a 16-bit integer, most significant byte first.

Link copied to clipboard
fun skip(length: Int)

Advances past exactly length bytes without materializing them.