Liking cljdoc? Tell your friends :D

easy-nio.buffer

Wrapper around java.nio.ByteBuffer.

ByteBuffers are stateful and mutable. All functions that modify buffer state return the buffer itself to support threading via -> or as->.

Terminology follows the java.nio convention:

  • capacity : total bytes the buffer can hold
  • limit : the first byte that should not be read or written
  • position : the current read/write cursor
  • remaining: (- limit position)
Wrapper around java.nio.ByteBuffer.

ByteBuffers are stateful and mutable. All functions that modify buffer
state return the buffer itself to support threading via -> or as->.

Terminology follows the java.nio convention:
  - capacity : total bytes the buffer can hold
  - limit    : the first byte that should not be read or written
  - position : the current read/write cursor
  - remaining: (- limit position)
raw docstring

->bytesclj

(->bytes buf)

Returns a byte-array of the bytes between position and limit without advancing the position. Safe to call multiple times.

Returns a byte-array of the bytes between position and limit
without advancing the position. Safe to call multiple times.
sourceraw docstring

->strclj

(->str buf)

Decodes the bytes between position and limit as a UTF-8 string. Does not advance position.

Decodes the bytes between position and limit as a UTF-8 string.
Does not advance position.
sourceraw docstring

allocateclj

(allocate capacity)
(allocate capacity direct?)

Allocates a heap ByteBuffer of capacity bytes if direct? is false. Otherwise, allocates a direct (off-heap) ByteBuffer of capacity bytes. The former should be used for general purpose buffers while the latter should be prefverred for I/O operations with NIO channels.

Allocates a heap ByteBuffer of `capacity` bytes if direct? is false.
Otherwise, allocates a direct (off-heap) ByteBuffer of `capacity` bytes.
The former should be used for general purpose buffers while the latter 
should be prefverred for I/O operations with NIO channels.
sourceraw docstring

as-read-onlyclj

(as-read-only buf)

Returns a read-only view of buf. Writes to the returned buffer throw ReadOnlyBufferException.

Returns a read-only view of `buf`. Writes to the returned buffer
throw ReadOnlyBufferException.
sourceraw docstring

big-endianclj

source

byte-orderclj

(byte-order buf)

Returns the current ByteOrder of buf.

Returns the current ByteOrder of `buf`.
sourceraw docstring

capacityclj

(capacity buf)

Returns the total byte capacity of buf.

Returns the total byte capacity of `buf`.
sourceraw docstring

clear!clj

(clear! buf)

Resets buf for writing from scratch. Sets position to 0 and limit to capacity. Does not zero out data. Returns buf.

Resets `buf` for writing from scratch.
Sets position to 0 and limit to capacity. Does not zero out data.
Returns `buf`.
sourceraw docstring

compact!clj

(compact! buf)

Compacts buf. Copies unread bytes to the start, then positions after the last copied byte ready for more writes. Use instead of clear! when you want to preserve unread data. Returns buf.

Compacts `buf`. Copies unread bytes to the start, then positions
after the last copied byte ready for more writes.
Use instead of clear! when you want to preserve unread data.
Returns `buf`.
sourceraw docstring

direct?clj

(direct? buf)

Returns true if buf is a direct (off-heap) buffer.

Returns true if `buf` is a direct (off-heap) buffer.
sourceraw docstring

duplicateclj

(duplicate buf)

Returns a new ByteBuffer sharing the same backing data but with independent position, limit, and mark. Useful for reading the same buffer concurrently without rewinding.

Returns a new ByteBuffer sharing the same backing data but with
independent position, limit, and mark. Useful for reading the same
buffer concurrently without rewinding.
sourceraw docstring

flip!clj

(flip! buf)

Switches buf from write mode to read mode. Sets limit to current position, then resets position to 0. Returns buf.

Switches `buf` from write mode to read mode.
Sets limit to current position, then resets position to 0.
Returns `buf`.
sourceraw docstring

from-bytesclj

(from-bytes ba)

Allocates a direct ByteBuffer containing ba, ready for reading.

Allocates a direct ByteBuffer containing `ba`, ready for reading.
sourceraw docstring

from-stringclj

(from-string s)

Allocates a direct ByteBuffer containing the UTF-8 bytes of s, ready for reading (already flipped).

Allocates a direct ByteBuffer containing the UTF-8 bytes of `s`,
ready for reading (already flipped).
sourceraw docstring

get-byte!clj

(get-byte! buf)

Reads and returns a single byte at the current position, advancing position by 1.

Reads and returns a single byte at the current position,
advancing position by 1.
sourceraw docstring

get-bytes!clj

(get-bytes! buf n)

Reads n bytes from buf into a new byte-array and returns it. Advances position by n.

Reads `n` bytes from `buf` into a new byte-array and returns it.
Advances position by `n`.
sourceraw docstring

get-double!clj

(get-double! buf)

Reads and returns a double (8 bytes) at the current position.

Reads and returns a double (8 bytes) at the current position.
sourceraw docstring

get-float!clj

(get-float! buf)

Reads and returns a float (4 bytes) at the current position.

Reads and returns a float (4 bytes) at the current position.
sourceraw docstring

get-int!clj

(get-int! buf)

Reads and returns an int (4 bytes) at the current position.

Reads and returns an int (4 bytes) at the current position.
sourceraw docstring

get-long!clj

(get-long! buf)

Reads and returns a long (8 bytes) at the current position.

Reads and returns a long (8 bytes) at the current position.
sourceraw docstring

get-short!clj

(get-short! buf)

Reads and returns a short (2 bytes) at the current position.

Reads and returns a short (2 bytes) at the current position.
sourceraw docstring

has-remaining?clj

(has-remaining? buf)

Returns true if there is at least one byte between position and limit.

Returns true if there is at least one byte between position and limit.
sourceraw docstring

limitclj

(limit buf)

Returns the current limit of buf.

Returns the current limit of `buf`.
sourceraw docstring

little-endianclj

source

mark!clj

(mark! buf)

Marks the current position for a later reset!. Returns buf.

Marks the current position for a later reset!. Returns `buf`.
sourceraw docstring

positionclj

(position buf)

Returns the current position of buf.

Returns the current position of `buf`.
sourceraw docstring

put-buffer!clj

(put-buffer! buf src)

Writes all remaining bytes from src ByteBuffer into buf. Returns buf.

Writes all remaining bytes from `src` ByteBuffer into `buf`.
Returns `buf`.
sourceraw docstring

put-byte!clj

(put-byte! buf b)

Writes a single byte b at the current position. Returns buf.

Writes a single byte `b` at the current position. Returns `buf`.
sourceraw docstring

put-bytes!clj

(put-bytes! buf ba)
(put-bytes! buf ba offset length)

Writes all bytes from byte-array ba into buf at the current position. Optionally accepts offset and length to write a sub-range of ba. Returns buf.

Writes all bytes from byte-array `ba` into `buf` at the current
position. Optionally accepts `offset` and `length` to write a
sub-range of `ba`. Returns `buf`.
sourceraw docstring

put-double!clj

(put-double! buf n)

Writes an 8-byte double at the current position. Returns buf.

Writes an 8-byte double at the current position. Returns `buf`.
sourceraw docstring

put-float!clj

(put-float! buf n)

Writes a 4-byte float at the current position. Returns buf.

Writes a 4-byte float at the current position. Returns `buf`.
sourceraw docstring

put-int!clj

(put-int! buf n)

Writes a 4-byte int at the current position. Returns buf.

Writes a 4-byte int at the current position. Returns `buf`.
sourceraw docstring

put-long!clj

(put-long! buf n)

Writes an 8-byte long at the current position. Returns buf.

Writes an 8-byte long at the current position. Returns `buf`.
sourceraw docstring

put-short!clj

(put-short! buf n)

Writes a 2-byte short at the current position. Returns buf.

Writes a 2-byte short at the current position. Returns `buf`.
sourceraw docstring

read-only?clj

(read-only? buf)

Returns true if buf is read-only.

Returns true if `buf` is read-only.
sourceraw docstring

remainingclj

(remaining buf)

Returns the number of bytes between position and limit.

Returns the number of bytes between position and limit.
sourceraw docstring

reset-to-mark!clj

(reset-to-mark! buf)

Resets position to the previously marked position. Returns buf.

Resets position to the previously marked position. Returns `buf`.
sourceraw docstring

rewind!clj

(rewind! buf)

Resets position to 0 without changing the limit. Useful for re-reading a buffer that has already been flipped. Returns buf.

Resets position to 0 without changing the limit.
Useful for re-reading a buffer that has already been flipped.
Returns `buf`.
sourceraw docstring

set-byte-order!clj

(set-byte-order! buf order)

Sets the byte order of buf to order (use big-endian or little-endian). Returns buf.

Sets the byte order of `buf` to `order` (use `big-endian` or
`little-endian`). Returns `buf`.
sourceraw docstring

set-limit!clj

(set-limit! buf n)

Sets the limit of buf to n. Returns buf.

Sets the limit of `buf` to `n`. Returns `buf`.
sourceraw docstring

set-position!clj

(set-position! buf n)

Sets the position of buf to n. Returns buf.

Sets the position of `buf` to `n`. Returns `buf`.
sourceraw docstring

sliceclj

(slice buf)

Returns a new ByteBuffer sharing the region from the current position to the limit of buf. Changes to the slice's content are reflected in the original.

Returns a new ByteBuffer sharing the region from the current
position to the limit of `buf`. Changes to the slice's content
are reflected in the original.
sourceraw docstring

wrapclj

(wrap ba)
(wrap ba offset length)

Wraps an existing byte-array into a ByteBuffer. The buffer shares the backing array, mutations to one are visible in the other. Optionally accepts offset and length to wrap a sub-region.

Wraps an existing byte-array into a ByteBuffer.
The buffer shares the backing array, mutations to one are visible
in the other. Optionally accepts `offset` and `length` to wrap a
sub-region.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close