Mutable buffer of value elements.
Mutable buffer of value elements.
This wraps one of the Java NIO buffer classes. Most of the Java documentation is applicable to this class.
Buffer instances are in no way synchronized and are typically used from a single fiber. Extract immutable Chunk
s to
pass values to other fibers or via streams.
There is a concrete buffer subclass for each primitive type. There are three ways to create a buffer:
Simply allocates a new buffer on the heap of a certain size, for example Buffer.byte(100)
, Buffer.char(200)
.
For ByteBuffer
there is the special case of direct buffers, which can be constructed via Buffer.byteDirect
. See
the Java docs for details of the advantages and disadvantages of direct byte buffers.
Buffers can wrap existing Java buffers, or ZIO Chunk
s. Care must be taken when wrapping Java buffers that the
wrapped buffer is not subsequently modified; these objects are typically wrapped to provide efficient
interoperability with Java APIs.
A CharBuffer
can also wrap any java.lang.CharSequence
.
While ByteBuffer
s are created via allocation or wrapping, the other buffer types are more commonly constructed as a
view over a ByteBuffer
. Each numeric buffer class supports either big-endian or little-endian byte order as
required.
View buffers are constructed via the various asXXX
methods on the zio.nio.ByteBuffer class, for example:
val ints(implicit trace: ZTraceElement): UIO[IntBuffer] = bytes.asIntBuffer
Changes to made via view buffers are reflected in the original ByteBuffer
and vice-versa.
The Java API supports "invocation chaining", which does not work with effect values. The Java example:
b.flip().position(23).limit(42)
is typically written:
for { _ <- b.flip _ <- b.position(23) _ <- b.limit(42) } yield ()
or in cases like this when the intermediate values aren't used:
b.flip *> b.position(23) *> b.limit(42)
A mutable buffer of bytes.
A mutable buffer of characters.
A mutable buffer of doubles.
A mutable buffer of floats.
A resource with an effect to close or release the resource.
Representation of an Internet Protocol (IP) address.
Representation of an Internet Protocol (IP) address.
Will be either a 32-bit IPv4 address or a 128-bit IPv6 address.
Representation of an IP Socket Address (IP address + port number).
Representation of an IP Socket Address (IP address + port number).
It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname. If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy. However, note that network channels generally do not accept unresolved socket addresses.
This class provides an immutable object used by sockets for binding, connecting, or as returned values.
The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.
A mutable buffer of ints.
A mutable buffer of longs.
A direct byte buffer whose content is a memory-mapped region of a file.
A direct byte buffer whose content is a memory-mapped region of a file. Mapped byte buffers are created by the
FileChannel#map
method.
zio.nio.channels.FileChannel#map
A mutable buffer of shorts.
Representation of a socket address without a specific protocol.
Representation of a socket address without a specific protocol.
The concrete subclass InetSocketAddress is used in practice.
ZIO-NIO, the API for using Java's NIO API in ZIO programs.