PgOutputStream

internal class PgOutputStream(outputStream: OutputStream)

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

It provides specialized methods for efficiently writing protocol primitives like bytes, integers, shorts, and null-terminated C-style strings. Internal buffering minimizes the number of underlying network write operations.

Constructors

Link copied to clipboard
constructor(outputStream: OutputStream)

Functions

Link copied to clipboard
fun changeStream(newStream: OutputStream)

Swaps the underlying stream, flushing what is buffered first so nothing written before the swap is lost. The read side discards instead; see PgInputStream.changeStream.

Link copied to clipboard
fun flush()

Empties the buffer into the underlying stream and flushes that too.

Link copied to clipboard
fun writeByte(b: Byte)

Buffers one byte, flushing first if the buffer is full.

Link copied to clipboard
fun writeBytes(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size - offset)

Buffers length bytes of bytes starting at offset, flushing as often as it needs to.

Link copied to clipboard

Writes a null-terminated string.

Link copied to clipboard
fun writeInt(i: Int)

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

Link copied to clipboard
fun writeShort(s: Int)

Buffers an unsigned 16-bit integer, most significant byte first - taken as an Int because the protocol's counts run to 65535 and a Short would make half of them negative.