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 Details

    • PanamaWasiInputStream

      public PanamaWasiInputStream(MemorySegment contextHandle, MemorySegment streamHandle)
      Creates a new Panama WASI input stream with the given native handles.
      Parameters:
      contextHandle - the native context handle
      streamHandle - 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:
      read in interface ai.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:
      blockingRead in interface ai.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:
      skip in interface ai.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:
      blockingSkip in interface ai.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:
      subscribe in interface ai.tegmentum.wasmtime4j.wasi.io.WasiInputStream
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getId

      public long getId()
    • getType

      public String getType()
    • isOwned

      public boolean isOwned()
    • isValid

      public boolean isValid()
    • getAvailableOperations

      public List<String> getAvailableOperations()
    • invoke

      public Object invoke(String operation, Object... parameters) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getLastAccessedAt

      public Optional<Instant> getLastAccessedAt()
    • getCreatedAt

      public Instant getCreatedAt()
    • getNativeHandle

      public MemorySegment 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:
      close in interface AutoCloseable