Class PanamaWasiInputStream
java.lang.Object
ai.tegmentum.wasmtime4j.panama.wasi.io.PanamaWasiInputStream
- All Implemented Interfaces:
ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream,AutoCloseable
public final class PanamaWasiInputStream
extends Object
implements ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream, AutoCloseable
Panama FFI implementation of the WasiInputStream interface.
This class provides access to WASI Preview 2 input stream operations through Panama Foreign Function API calls to the native Wasmtime library. Input streams support non-blocking and blocking read operations.
This implementation ensures defensive programming to prevent native resource leaks and JVM crashes.
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionPanamaWasiInputStream(MemorySegment contextHandle, MemorySegment streamHandle) Creates a new Panama WASI input stream with the given native handles. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]blockingRead(long length) longblockingSkip(long length) voidclose()longgetId()Returns the native stream handle.getType()booleanisClosed()Checks if this input stream has been closed.booleanisOwned()booleanisValid()byte[]read(long length) longskip(long length) ai.tegmentum.wasmtime4j.wasi.io.WasiPollable
-
Constructor Details
-
PanamaWasiInputStream
Creates a new Panama WASI input 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
-
read
public byte[] read(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
readin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiInputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingRead
public byte[] blockingRead(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
blockingReadin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiInputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
skip
public long skip(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
skipin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiInputStream- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException
-
blockingSkip
public long blockingSkip(long length) throws ai.tegmentum.wasmtime4j.exception.WasmException - Specified by:
blockingSkipin interfaceai.tegmentum.wasmtime4j.wasi.io.WasiInputStream- 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.WasiInputStream- 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 input stream has been closed.- Returns:
- true if closed
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-