# FixIO Documentation

Back to summary

`import "io/stream";`

## Stream class

Synchronous stream.

Subclasses: ArrayStream, BufferedStream, ZStream, GZipStream, File, TCPConnection, ProcessStream

### Initialization

`static function create(): Stream`
  Creates a new instance of Stream class.

### Stream interface

`virtual function read_part(buf: Byte[], off: Integer, len: Integer): Integer`
  Reads part of the data from the stream. Returns how many bytes were actually read. Zero means end of file.
  Override to implement reading of data in your stream, the default implementation throws an error.
`virtual function write_part(buf: Byte[], off: Integer, len: Integer): Integer`
  Writes part of the data to the stream. Returns how many bytes were actually written.
  Override to implement writing of data in your stream, the default implementation throws an error.
`virtual function flush()`
  Flushes any cached data to the underlying stream.
`virtual function skip(len: Integer)`
  Skips (as by reading, but more efficiently) given amount of bytes.
  The default implementation just reads data into a temporary buffer.
`virtual function close()`
  Closes the stream.

### Utility functions

`function read(buf: Byte[])
function read(buf: Byte[], off: Integer, len: Integer)`
  Reads all the requested data into given buffer by repeatedly calling `read_part` function. If there is not enough data an error is thrown.
`function write(buf: Byte[])
function write(buf: Byte[], off: Integer, len: Integer)`
  Writes all the data from given buffer by repeatedly calling `write_part` function.
`function read_all(): Byte[]
function read_all(buf: Byte[]): Byte[]`
  Reads all the remaining data from the stream into the provided buffer (or creates a new one).
`function read_part(buf: Byte[]): Integer`
  A variant of `read_part` function that tries to read the whole buffer.
`function write_part(buf: Byte[]): Integer`
  A variant of `write_part` function that tries to write the whole buffer.
`function read_byte(): Byte
function read_ubyte(): Byte
function read_short_LE(): Short
function read_ushort_LE(): Short
function read_short_BE(): Short
function read_ushort_BE(): Short
function read_int_LE(): Integer
function read_int_BE(): Integer
function read_long_LE(): Long
function read_long_LE(out: Long): Long
function read_long_BE(): Long
function read_long_BE(out: Long): Long
function read_float_LE(): Float
function read_float_BE(): Float
function read_double_LE(): Double
function read_double_LE(out: Double): Double
function read_double_BE(): Double
function read_double_BE(out: Double): Double
`
  Reads a primitive type from the stream. There are two variants depending on what endianess you want to use: LE (little endian) or BE (big endian). For Long and Double types you can provide an existing instance to read to.
`function write_byte(value: Byte)
function write_ubyte(value: Byte)
function write_short_LE(value: Short)
function write_short_BE(value: Short)
function write_ushort_LE(value: Short)
function write_ushort_BE(value: Short)
function write_int_LE(value: Integer)
function write_int_BE(value: Integer)
function write_long_LE(value: Long)
function write_long_BE(value: Long)
function write_float_LE(value: Float)
function write_float_BE(value: Float)
function write_double_LE(value: Double)
function write_double_BE(value: Double)
`
  Writes a primitive type to the stream. There are two variants depending on what endianess you want to use: LE (little endian) or BE (big endian).
`function write_stream(stream: Stream)`
  Writes the whole stream (by reading it) to another stream.
`function write_null_string(s: Byte[])
function write_null_string(s: Byte[], off: Integer, len: Integer)
`
  Writes null terminated byte string.