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 Details

    • PanamaWasiOutputStream

      public PanamaWasiOutputStream(MemorySegment contextHandle, MemorySegment streamHandle)
      Creates a new Panama WASI output 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

    • checkWrite

      public long checkWrite() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      checkWrite in interface ai.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:
      write in interface ai.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:
      blockingWriteAndFlush in interface ai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • flush

      public void flush() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      flush in interface ai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • blockingFlush

      public void blockingFlush() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      blockingFlush in interface ai.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:
      writeZeroes in interface ai.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:
      blockingWriteZeroesAndFlush in interface ai.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:
      splice in interface ai.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:
      blockingSplice in interface ai.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:
      subscribe in interface ai.tegmentum.wasmtime4j.wasi.io.WasiOutputStream
      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 output stream has been closed.
      Returns:
      true if closed
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable