Package ej.wasi.io.file
Class WasiFileImpl
- java.lang.Object
-
- ej.wasi.io.file.WasiFileImpl
-
- All Implemented Interfaces:
WasiFile,ReadableIO,WasiIO,WritableIO,WasiConstants,java.io.Closeable,java.lang.AutoCloseable
public class WasiFileImpl extends java.lang.Object implements WasiFile
-
-
Field Summary
Fields Modifier and Type Field Description static intCURstatic intENDstatic intSET-
Fields inherited from interface ej.wasi.WasiConstants
AF_INET, AF_INET6, BLOCKING_CONNECT_TIMEOUT, BUFFERED_INPUT_STREAM_SIZE, CLOCK_MONOTONIC, CLOCK_REALTIME, DIRENT_COOKIE_OFFSET, DIRENT_ENTRY_NAME_LENGTH_OFFSET, DIRENT_FILE_TYPE_OFFSET, DIRENT_INODE_OFFSET, DIRENT_SIZE, ERRNO_ACCES, ERRNO_ADDRINUSE, ERRNO_ADDRNOTAVAIL, ERRNO_AFNOSUPPORT, ERRNO_AGAIN, ERRNO_BADF, ERRNO_CONNREFUSED, ERRNO_EXIST, ERRNO_FAULT, ERRNO_HOSTUNREACH, ERRNO_INPROGRESS, ERRNO_INTR, ERRNO_INVAL, ERRNO_IO, ERRNO_ISCONN, ERRNO_ISDIR, ERRNO_MSGSIZE, ERRNO_NAMETOOLONG, ERRNO_NOENT, ERRNO_NOMEM, ERRNO_NOSYS, ERRNO_NOTCONN, ERRNO_NOTDIR, ERRNO_NOTEMPTY, ERRNO_NOTSOCK, ERRNO_NOTSUP, ERRNO_OVERFLOW, ERRNO_SPIPE, ERRNO_SUCCESS, EVENT_AVAILABLE_BYTE_OFFSET, EVENT_ERROR_OFFSET, EVENT_EVENT_TYPE_OFFSET, EVENT_READ_WRITE_HANGUP_OFFSET, EVENT_SIZE, EVENT_USER_DATA_OFFSET, FDFLAGS_APPEND_MASK, FDFLAGS_NON_BLOCK_MASK, FDSTAT_BASE_RIGHTS_OFFSET, FDSTAT_FILE_TYPE_OFFSET, FDSTAT_FLAGS_OFFSET, FDSTAT_INHERITING_RIGHTS_OFFSET, FILESTAT_FILESIZE_OFFSET, FILESTAT_FILETYPE_OFFSET, FILESTAT_INODE_OFFSET, FILESTAT_LAST_MODIFIED_TIME_OFFSET, IFF_LOOPBACK, IFF_RUNNING, IFF_UP, IOVEC_BUFFER_INDEX, IOVEC_BUFFER_LENGTH_INDEX, IOVEC_SIZE, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_TTL, IPPROTO_IP, IPPROTO_IPV6, IPv4AddressSize, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPv6AddressSize, LOOKUPFLAGS_SYMLINK_FOLLOW_MASK, MILLIS_TO_NANO, NON_BLOCKING_TIMEOUT, OFLAGS_CREAT_MASK, OFLAGS_DIRECTORY_MASK, OFLAGS_EXCL_MASK, OFLAGS_TRUNC_MASK, POLLING_TIMEOUT, PREOPENTYPE_DIR, PREOPENTYPE_UNKNOWN, PRESTAT_PREOPEN_DIRNAME_OFFSET, PRESTAT_PREOPEN_TAG_OFFSET, RIFLAGS_MSG_PEEK_MASK, RIFLAGS_WAITALL_MASK, RIGHTS_ALL, RIGHTS_DIR, SDFLAGS_READ, SDFLAGS_WRITE, SO_BROADCAST, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SOCK_CLOEXEC, SOCK_NONBLOCK, SOCKET_LEVEL, UDP_PEEK_BUFFER_MAX_SIZE
-
-
Constructor Summary
Constructors Constructor Description WasiFileImpl(java.io.File file, boolean truncate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns an estimate of the number of bytes that can be read from this input stream without blocking by the next read method invocation.voidclose()voiddelete()java.lang.StringgetCanonicalPath()FileTypegetType()Gets the WasiIO file descriptor type.longlastModidied()longlength()intread(byte[] buffer, int offset, int length)Readslengthbytes of data from this WasiIO into an array of bytes.voidrenameTo(WasiFile newFile)longseek(long offset, int whence)voidsetNonBlocking(boolean nonBlocking)Sets this WasiIO in non blocking state.longtell()voidwasiSetLength(long length)Sets the length of a file.voidwrite(byte[] buffer, int offset, int length)Writeslengthbytes from t he specified byte array starting at offsetoffsetto this WasiIO.
-
-
-
Field Detail
-
SET
public static final int SET
- See Also:
- Constant Field Values
-
CUR
public static final int CUR
- See Also:
- Constant Field Values
-
END
public static final int END
- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOExceptionDescription copied from interface:WritableIOWriteslengthbytes from t he specified byte array starting at offsetoffsetto this WasiIO.- Specified by:
writein interfaceWritableIO- Parameters:
buffer- the data to write.offset- the starting offset.length- the number of bytes to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public int read(byte[] buffer, int offset, int length) throws java.io.IOExceptionDescription copied from interface:ReadableIOReadslengthbytes of data from this WasiIO into an array of bytes.- Specified by:
readin interfaceReadableIO- Parameters:
buffer- the buffer into which the data is read.offset- the start offset in arraybat which the data is written.length- the maximum number of bytes to read.- Returns:
- the total number of bytes read into the buffer or
-1if there is no more data. - Throws:
java.io.IOException- if an I/O error occurs.
-
available
public int available() throws java.io.IOExceptionDescription copied from interface:ReadableIOReturns an estimate of the number of bytes that can be read from this input stream without blocking by the next read method invocation.- Specified by:
availablein interfaceReadableIO- Returns:
- an estimate of the number of bytes that can be read from this input
stream without blocking or
0when it reaches the end of this WasiIO. - Throws:
java.io.IOException- if an I/O error occurs.
-
seek
public long seek(long offset, int whence) throws java.io.IOException
-
tell
public long tell() throws java.io.IOException
-
getType
public FileType getType()
Description copied from interface:WasiIOGets the WasiIO file descriptor type.
-
setNonBlocking
public void setNonBlocking(boolean nonBlocking) throws java.io.IOExceptionDescription copied from interface:ReadableIOSets this WasiIO in non blocking state.- Specified by:
setNonBlockingin interfaceReadableIO- Parameters:
nonBlocking- whether to enable or disable the non blocking option.- Throws:
java.io.IOException- if an I/O error occurs.
-
wasiSetLength
public void wasiSetLength(long length) throws java.io.IOExceptionSets the length of a file. If file is shortened, the data is lost, if file is grown, the new data is filled with zeros.- Specified by:
wasiSetLengthin interfaceWasiFile- Parameters:
length- The new length to set for the file.- Throws:
java.io.IOException- If an io error occurs
-
lastModidied
public long lastModidied()
- Specified by:
lastModidiedin interfaceWasiFile
-
getCanonicalPath
public java.lang.String getCanonicalPath() throws java.io.IOException- Specified by:
getCanonicalPathin interfaceWasiFile- Throws:
java.io.IOException
-
renameTo
public void renameTo(WasiFile newFile) throws WasiIOException
- Specified by:
renameToin interfaceWasiFile- Throws:
WasiIOException
-
delete
public void delete() throws WasiIOException- Specified by:
deletein interfaceWasiFile- Throws:
WasiIOException
-
-