Class PanamaWasiOutputStream
java.lang.Object
ai.tegmentum.wasmtime4j.panama.wasi.io.PanamaWasiOutputStream
- All Implemented Interfaces:
ai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream,AutoCloseable
public final class PanamaWasiOutputStream
extends Object
implements ai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream, AutoCloseable
Panama FFI implementation of the WasiOutputStream interface.
This class provides access to WASI Preview 2 output stream operations through Panama Foreign Function API calls to the native Wasmtime library. Output streams support non-blocking and blocking write operations, as well as stream splicing.
This implementation ensures defensive programming to prevent native resource leaks and JVM crashes.
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionPanamaWasiOutputStream(MemorySegment contextHandle, MemorySegment streamHandle) Creates a new Panama WASI output stream with the given native handles. -
Method Summary
Modifier and TypeMethodDescriptionvoidlongblockingSplice(ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream source, long length) voidblockingWriteAndFlush(byte[] contents) voidblockingWriteZeroesAndFlush(long length) longvoidclose()voidflush()longgetId()Returns the native stream handle.getType()booleanisClosed()Checks if this output stream has been closed.booleanisOwned()booleanisValid()longsplice(ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream source, long length) ai.tegmentum.wasmtime4j.wasi.io.WasiPollablevoidwrite(byte[] contents) voidwriteZeroes(long length)
-
Constructor Details
-
PanamaWasiOutputStream
Creates a new Panama WASI output stream with the given native handles.- Parameters:
contextHandle- the native context handlestreamHandle- the native stream handle- Throws:
IllegalArgumentException- if either handle is null
-
-
Method Details
-
checkWrite
public long checkWrite() throws ai.tegmentum.wasmtime4j.exception.WasmException- Specified by:
checkWritein interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
write
public void write(byte[] contents) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
writein interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingWriteAndFlush
public void blockingWriteAndFlush(byte[] contents) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
blockingWriteAndFlushin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
flush
public void flush() throws ai.tegmentum.wasmtime4j.exception.WasmException- Specified by:
flushin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingFlush
public void blockingFlush() throws ai.tegmentum.wasmtime4j.exception.WasmException- Specified by:
blockingFlushin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
writeZeroes
public void writeZeroes(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
writeZeroesin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingWriteZeroesAndFlush
public void blockingWriteZeroesAndFlush(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
blockingWriteZeroesAndFlushin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
splice
public long splice(ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream source, long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
splicein interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingSplice
public long blockingSplice(ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream source, long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
blockingSplicein interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
subscribe
public ai.tegmentum.wasmtime4j.wasi.io.WasiPollable subscribe() throws ai.tegmentum.wasmtime4j.exception.WasmException- Specified by:
subscribein interfaceai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
getId
public long getId() -
getType
-
isOwned
public boolean isOwned() -
isValid
public boolean isValid() -
getAvailableOperations
-
invoke
-
getLastAccessedAt
-
getCreatedAt
-
getNativeHandle
Returns the native stream handle.- Returns:
- the native memory segment
-
isClosed
public boolean isClosed()Checks if this output stream has been closed.- Returns:
- true if closed
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-