std/io
std/io — byte-stream I/O in pure Axle over libc stdio.
InputStream / OutputStream — the byte-stream contracts.
File — a path facade (no open handle).
FileInputStream / FileOutputStream — libc-FILE*-backed byte streams.
ByteArrayInputStream / …OutputStream — in-memory streams.
BufferedReader / BufferedWriter / PrintWriter — text over a file stream.
Scanner — conventional stdin reader.
Polymorphism is at the trait boundary: a fn drain(s : InputStream)
accepts any concrete stream above. Streaming only: there is no
whole-file readAll / writeAll, so a large file never has to live in
memory at once. The open mode is one of the OPEN_READ / OPEN_WRITE /OPEN_APPEND flags, never a text spelling, so I/O stays byte-exact.
Entry: the fs:: libc bindings and std/text byte bridges resolve
by cross-module use.
Exit: the classes above are declared and exported as std/io.
Free functions
| Type | Method and description |
|---|---|
| axle_libc_stdin() : ptr |
| asStream(handle : i64) : ptr View an i64 address (a stored FILE* handle, or a buffer address frombufferAddr) as the opaque ptr the fs:: bindings expect. |
| streamHandle(s : ptr) : i64 Materialise a libc FILE* ptr as the i64 handle a stream field holds. |
| clampedTo(len : i64, capacity : i64) : i64 A byte count bounded to [0, capacity] — the range a stream may treatas valid. A negative count reads as empty, and one past the buffer end reads short rather than out of bounds. ByteArrayInputStream clamps itslength with it, so every later read, skip and available inherits thebound once rather than each re-testing it. |
| copy(src : InputStream, dst : OutputStream) : i64 Stream every remaining byte from src to dst through one fixed-sizebuffer, so no more than that buffer is ever resident and a large source is copied in constant memory. Takes any pair of concrete streams. |
Method detail
#axle_libc_stdin
#asStream
View an i64 address (a stored FILE* handle, or a buffer address frombufferAddr) as the opaque ptr the fs:: bindings expect.
#streamHandle
Materialise a libc FILE* ptr as the i64 handle a stream field holds.
#clampedTo
A byte count bounded to [0, capacity] — the range a stream may treat
as valid. A negative count reads as empty, and one past the buffer end
reads short rather than out of bounds. ByteArrayInputStream clamps its
length with it, so every later read, skip and available inherits the
bound once rather than each re-testing it.
#copy
Stream every remaining byte from src to dst through one fixed-size
buffer, so no more than that buffer is ever resident and a large source
is copied in constant memory. Takes any pair of concrete streams.
src stream drained from its current position to EOFdst stream the bytes are written toIOException if either stream raises one.C class File
A File wraps a filesystem path and owns no open handle: each method
opens, operates and closes within its own scope, or hands back an open
stream the caller is responsible for closing. Content is streamed, so
there is no whole-file read/write shortcut.
Constructors
| Type | Method and description |
|---|---|
| constructor(path : string) Wrap a path; opens no handle until a method is called. |
Method detail
#constructor
Wrap a path; opens no handle until a method is called.
path filesystem path the file operations targetMethods
| Type | Method and description |
|---|---|
| exists(self) : bool |
| length(self) : i64 |
| delete(self) : void |
| openRead(self) : FileInputStream |
| openWrite(self) : FileOutputStream |
| openAppend(self) : FileOutputStream |
| close(self) : void |
Method detail
#exists
#length
#delete
#openRead
#openWrite
#openAppend
#close
C class FileInputStream
Byte-oriented read stream backed by a libc FILE*. ImplementsInputStream, so it can be read as text via BufferedReader.handle holds the FILE* as an i64 (0 once closed). Async reads
offload the blocking call to a worker thread.
Constructors
| Type | Method and description |
|---|---|
| constructor(path : string) Open path for binary reading. |
Method detail
#constructor
Open path for binary reading.
path filesystem path to openFileNotFoundException if the path names no readable file.A directory is reported by that same exception with its
own message: the open fails for either, and "file not found"
about a path that is right there sends the caller looking
for the wrong thing. The kind is asked only when the open
failed.
Methods
| Type | Method and description |
|---|---|
| fromFile(file : File) : FileInputStream |
| read(self) : i32 |
| readBytes(self, buf : i8[], offset : i64, len : i64) : i64 |
| skip(self, n : i64) : i64 |
| available(self) : i64 |
| close(mut self) : void |
Method detail
#fromFile
#read
#readBytes
#skip
#available
#close
C class FileOutputStream
Byte-oriented write stream backed by a libc FILE*. ImplementsOutputStream, so it can be written as text via PrintWriter.handle holds the FILE* as an i64 (0 once closed).
Constructors
| Type | Method and description |
|---|---|
| constructor(path : string, mode : FileOpenMode) Open path for binary writing. |
Method detail
#constructor
Open path for binary writing.
path filesystem path to openmode FileOpenMode::APPEND writes past the end;any other mode truncates
IOException if the path cannot be opened.Methods
| Type | Method and description |
|---|---|
| fromFile(file : File) : FileOutputStream |
| write(self, b : i32) : void |
| writeBytes(self, buf : i8[], offset : i64, len : i64) : void |
| flush(self) : void |
| close(mut self) : void |
Method detail
#fromFile
#write
#writeBytes
#flush
#close
C class ByteArrayInputStream
In-memory read stream over an i8[] buffer. Pure Axle — no OS
handle. read() returns -1 at EOF without throwing (the -1 sentinel
matches the fgetc convention).
Fields: data is the backing buffer; cursor is the next-read
index; len is the number of valid bytes in data.
Constructors
| Type | Method and description |
|---|---|
| constructor(data : i8[], len : i64) Wrap data treating the first len bytes as the stream content. |
Method detail
#constructor
Wrap data treating the first len bytes as the stream content.
data backing buffer; not copied — caller must not mutate itlen number of valid bytes in data; a count past thebuffer end is clamped to it, so a miscount reads short
rather than out of bounds
Methods
| Type | Method and description |
|---|---|
| fromString(s : string) : ByteArrayInputStream |
| read(mut self) : i32 |
| readBytes(mut self, buf : i8[], offset : i64, len : i64) : i64 |
| skip(mut self, n : i64) : i64 |
| available(self) : i64 |
| reset(mut self) : void |
| close(self) : void |
Method detail
#fromString
#read
#readBytes
#skip
#available
#reset
#close
C class ByteArrayOutputStream
In-memory write stream backed by a growable i8[]. Pure Axle — no
OS handle.buf is the backing store; len counts bytes written so far; cap
is the allocated capacity. __grow doubles capacity until the new
minimum fits. toByteArray / toString materialise the written
content; reset resets the write cursor without freeing the buffer.
Constructors
| Type | Method and description |
|---|---|
| constructor() Start with a 16-byte initial capacity; the buffer grows on demand. |
Method detail
#constructor
Start with a 16-byte initial capacity; the buffer grows on demand.
Methods
| Type | Method and description |
|---|---|
| write(mut self, b : i32) : void |
| writeBytes(mut self, buf : i8[], offset : i64, len : i64) : void |
| flush(self) : void |
| close(self) : void |
| toByteArray(self) : i8[] |
| toString(self) : string |
| size(self) : i64 |
| reset(mut self) : void |
Method detail
#write
#writeBytes
#flush
#close
#toByteArray
#toString
#size
#reset
C class BufferedReader
Line-oriented text reader over a FileInputStream. The usual pattern
is new BufferedReader(new FileInputStream(path)); the reader steals
the source stream's handle, leaving the source inert.
The bytes arrive a block at a time into buf; pos indexes the next
byte still unread in it and filled counts the bytes the last refill
actually produced, so the block's valid window is buf[pos .. filled).
Constructors
| Type | Method and description |
|---|---|
| constructor(input : FileInputStream) Take ownership of input's open handle. input is left inert andmust not be used afterwards. |
Method detail
#constructor
Take ownership of input's open handle. input is left inert and
must not be used afterwards.
input source stream whose open handle is taken overMethods
| Type | Method and description |
|---|---|
| open(path : string) : BufferedReader |
| hasMoreLines(mut self) : bool |
| readLine(mut self) : string |
| close(mut self) : void |
Method detail
#open
#hasMoreLines
#readLine
#close
C class BufferedWriter
Text writer over a FileOutputStream. The usual pattern isnew BufferedWriter(new FileOutputStream(path, FileOpenMode::WRITE));
the writer steals the source stream's handle, leaving the source inert.
Constructors
| Type | Method and description |
|---|---|
| constructor(output : FileOutputStream) Take ownership of output's open handle. output is left inertand must not be used afterwards. |
Method detail
#constructor
Take ownership of output's open handle. output is left inert
and must not be used afterwards.
output source stream whose open handle is taken overMethods
| Type | Method and description |
|---|---|
| write(self, content : string) : void |
| writeLine(self, content : string) : void |
| flush(self) : void |
| close(mut self) : void |
Method detail
#write
#writeLine
#flush
#close
C class PrintWriter
Print-style text writer over a FileOutputStream — the file-output
sibling of Console. Constructed like BufferedWriter, stealing the
source stream's handle.
Constructors
| Type | Method and description |
|---|---|
| constructor(output : FileOutputStream) Take ownership of output's open handle. output is left inertand must not be used afterwards. |
Method detail
#constructor
Take ownership of output's open handle. output is left inert
and must not be used afterwards.
output source stream whose open handle is taken overMethods
| Type | Method and description |
|---|---|
| print(self, text : string) : void |
| println(self, text : string) : void |
| printf(self, format : string) : void |
| flush(self) : void |
| close(mut self) : void |
Method detail
#println
#printf
#flush
#close
C class Scanner
Conventional stdin reader over the libc stdin FILE*. One Scanner
per program is the usual shape; the default ctor binds to the
process stdin handle. A one-byte pushback slot (peeked) letshasNextLine look ahead for EOF without consuming the byte the next
read must return.
Constructors
| Type | Method and description |
|---|---|
| constructor() Bind to the process-wide stdin handle with an empty pushback. |
Method detail
#constructor
Bind to the process-wide stdin handle with an empty pushback.
Methods
| Type | Method and description |
|---|---|
| nextLine(self) : string |
| hasNextLine(mut self) : bool |
| nextI32(self) : i32 |
| nextI64(self) : i64 |
| nextF64(self) : f64 |
| close(mut self) : void |
Method detail
#nextLine
#hasNextLine
#nextI32
#nextI64
#nextF64
#close
T trait InputStream
Byte-oriented readable stream. Extends Closeable so atry-with-resources pattern closes the stream on exit.read() returns the next byte as 0..255, or -1 at EOF; the i32
return type is intentional — a signed i8 cannot distinguish -1
(EOF) from byte 0xFF. readBytes bulk-reads into a caller-suppliedi8[] slice [offset, offset+len), returning the count read or -1 at
EOF. skip advances the position by up to n bytes. available is a
non-blocking lower bound on bytes readable without blocking.
| Type | Method and description |
|---|---|
| read(self) : i32 Next byte 0..255, or -1 at EOF. |
| readBytes(self, buf : i8[], offset : i64, len : i64) : i64 Read up to len bytes into buf[offset .. offset+len). |
| skip(self, n : i64) : i64 Skip up to n bytes forward in the stream. |
| available(self) : i64 Lower bound on bytes readable without blocking. Returns 0 when the stream is closed or at EOF. |
| close(self) : void Release the stream. Idempotent. Redeclared from Closeable so apolymorphic stream.close() dispatches against InputStream'sown contract row. |
Method detail
#read
Next byte 0..255, or -1 at EOF.
#readBytes
Read up to len bytes into buf[offset .. offset+len).
buf destination bufferoffset first destination indexlen maximum bytes to read#skip
Skip up to n bytes forward in the stream.
n maximum bytes to skip#available
Lower bound on bytes readable without blocking.
Returns 0 when the stream is closed or at EOF.
#close
Release the stream. Idempotent. Redeclared from Closeable so a
polymorphic stream.close() dispatches against InputStream's
own contract row.
T trait OutputStream
Byte-oriented writable stream. Extends Closeable so atry-with-resources pattern closes the stream on exit.write(b) emits the low 8 bits of b. writeBytes bulk-writes from
a caller-supplied i8[] slice [offset, offset+len). flush pushes
any libc or in-memory buffer to the underlying sink.
| Type | Method and description |
|---|---|
| write(self, b : i32) : void Write the low 8 bits of b as one byte. |
| writeBytes(self, buf : i8[], offset : i64, len : i64) : void Write buf[offset .. offset+len) to the stream. |
| flush(self) : void Flush any buffered bytes to the underlying sink. |
| close(self) : void Release the stream. Idempotent. Redeclared from Closeable so apolymorphic stream.close() dispatches against OutputStream'sown contract row. |
Method detail
#write
Write the low 8 bits of b as one byte.
b source value; only its low 8 bits are emitted#writeBytes
Write buf[offset .. offset+len) to the stream.
buf source bufferoffset first source indexlen number of bytes to write#flush
Flush any buffered bytes to the underlying sink.
#close
Release the stream. Idempotent. Redeclared from Closeable so a
polymorphic stream.close() dispatches against OutputStream's
own contract row.