Top Description Fields Constructors Methods
org.lwjgl.system

public abstract Class CustomBuffer<SELF extends CustomBuffer<SELF>>

extends Default
Class Inheritance
Known Direct Subclasses
org.lwjgl.system.StructBuffer, org.lwjgl.CLongBuffer, org.lwjgl.PointerBuffer
Imports
javax.annotation.*, java.nio.*

Base class of custom buffers with an API that mirrors java.nio for convenience.

Field Summary

Modifier and TypeField and Description
protected int
protected ByteBuffer
protected int
protected int
protected int
Inherited from org.lwjgl.system.Pointer.Default:
ADDRESSaddressBUFFER_CAPACITYBUFFER_CONTAINERBUFFER_LIMITBUFFER_MARKBUFFER_POSITIONUNSAFE

Constructor Summary

AccessConstructor and Description
protected
CustomBuffer(long address, ByteBuffer container, int mark, int position, int limit, int capacity)

Method Summary

Modifier and TypeMethod and Description
public long
address()

Overrides org.lwjgl.system.Pointer.Default.address.

Implements org.lwjgl.system.Pointer.address.

Returns the memory address at the current buffer position.
public long
address(int position)

Returns the memory address at the specified buffer position.

public long
address0()

Returns the buffer's base address.

public int

Returns:

the capacity of this buffer
capacity
()

Returns this buffer's capacity.

public SELF

Returns:

This buffer
clear
()

Clears this buffer.

public SELF

Returns:

This buffer
compact
()

Compacts this buffer  (optional operation).

public SELF

Returns:

the new buffer
duplicate
()

Creates a new buffer that shares this buffer's content.

public SELF

Returns:

This buffer
flip
()

Flips this buffer.

public void
free()

Frees the buffer allocation.

public boolean

Returns:

true if, and only if, there is at least one element remaining in this buffer
hasRemaining
()

Tells whether there are any elements between the current position and the limit.

public int

Returns:

the limit of this buffer
limit
()

Returns this buffer's limit.

public SELF

Returns:

This buffer
limit
(int
the new limit value; must be non-negative and no larger than this buffer's capacity
limit
)

Sets this buffer's limit.

public SELF

Returns:

This buffer
mark
()

Sets this buffer's mark at its position.

protected final int
protected final int
public int

Returns:

the position of this buffer
position
()

Returns this buffer's position.

public SELF

Returns:

This buffer
position
(int
the new position value; must be non-negative and no larger than the current limit
position
)

Sets this buffer's position.

public SELF

Returns:

This buffer
put
(SELF
the source buffer from which elements are to be read; must not be this buffer
src
)

Relative bulk put method  (optional operation).

public int

Returns:

the number of elements remaining in this buffer
remaining
()

Returns the number of elements between the current position and the limit.

public SELF

Returns:

This buffer
reset
()

Resets this buffer's position to the previously-marked position.

public SELF

Returns:

This buffer
rewind
()

Rewinds this buffer.

protected abstract SELF
self()

public abstract int
sizeof()

Returns the sizeof a single element in the buffer.

public SELF

Returns:

the new buffer
slice
()

Creates a new buffer whose content is a shared subsequence of this buffer's content.

public SELF

Returns:

the sliced buffer
slice
(int
the slice offset, it must be ≤ this.remaining()
offset
,
int
the slice length, it must be ≤ this.capacity() - (this.position() + offset)
capacity
)

Returns a slice of this buffer between (buffer.position() + offset) and (buffer.position() + offset + capacity).

public String

Returns:

A summary string
toString
()

Overrides org.lwjgl.system.Pointer.Default.toString.

Returns a string summarizing the state of this buffer.
Inherited from org.lwjgl.system.Pointer.Default:
equalshashCode

Field Detail

capacityback to summary
protected int capacity
containerback to summary
protected ByteBuffer container
Annotations
@Nullable
limitback to summary
protected int limit
markback to summary
protected int mark
positionback to summary
protected int position

Constructor Detail

CustomBufferback to summary
protected CustomBuffer(long address, ByteBuffer container, int mark, int position, int limit, int capacity)

Method Detail

addressback to summary
public long address()

Overrides org.lwjgl.system.Pointer.Default.address.

Implements org.lwjgl.system.Pointer.address.

Returns the memory address at the current buffer position.

Returns:long

Doc from org.lwjgl.system.Pointer.address.

the pointer address

Annotations
@Override
addressback to summary
public long address(int position)

Returns the memory address at the specified buffer position.

address0back to summary
public long address0()

Returns the buffer's base address. [INTERNAL USE ONLY]

capacityback to summary
public int capacity()

Returns this buffer's capacity.

Returns:int

the capacity of this buffer

clearback to summary
public SELF clear()

Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.

Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:

buf.clear();     // Prepare buffer for reading
in.read(buf);    // Read data

This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.

Returns:SELF

This buffer

compactback to summary
public SELF compact()

Compacts this buffer  (optional operation).

The elements between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the element at index p = position() is copied to index zero, the element at index p + 1 is copied to index one, and so forth until the element at index limit() - 1 is copied to index n = limit() - 1 -  p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.

The buffer's position is set to the number of elements copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.

Returns:SELF

This buffer

Exceptions
ReadOnlyBufferException:
If this buffer is read-only
duplicateback to summary
public SELF duplicate()

Creates a new buffer that shares this buffer's content.

The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's capacity, limit and position will be identical to those of this buffer.

Returns:SELF

the new buffer

Annotations
@SuppressWarnings:unchecked
flipback to summary
public SELF flip()

Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.

After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:

buf.put(magic);    // Prepend header
in.read(buf);      // Read data into rest of buffer
buf.flip();        // Flip buffer
out.write(buf);    // Write header + data to channel

This method is often used in conjunction with the compact method when transferring data from one place to another.

Returns:SELF

This buffer

freeback to summary
public void free()

Frees the buffer allocation.

This method should not be used if the memory backing this buffer is not owned by the buffer.

hasRemainingback to summary
public boolean hasRemaining()

Tells whether there are any elements between the current position and the limit.

Returns:boolean

true if, and only if, there is at least one element remaining in this buffer

limitback to summary
public int limit()

Returns this buffer's limit.

Returns:int

the limit of this buffer

limitback to summary
public SELF limit(int limit)

Sets this buffer's limit. If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded.

Parameters
limit:int

the new limit value; must be non-negative and no larger than this buffer's capacity

Returns:SELF

This buffer

Exceptions
IllegalArgumentException:
If the preconditions on newLimit do not hold
markback to summary
public SELF mark()

Sets this buffer's mark at its position.

Returns:SELF

This buffer

nextGetIndexback to summary
protected final int nextGetIndex()
nextPutIndexback to summary
protected final int nextPutIndex()
positionback to summary
public int position()

Returns this buffer's position.

Returns:int

the position of this buffer

positionback to summary
public SELF position(int position)

Sets this buffer's position. If the mark is defined and larger than the new position then it is discarded.

Parameters
position:int

the new position value; must be non-negative and no larger than the current limit

Returns:SELF

This buffer

Exceptions
IllegalArgumentException:
If the preconditions on newPosition do not hold
putback to summary
public SELF put(SELF src)

Relative bulk put method  (optional operation).

This method transfers the elements remaining in the specified source buffer into this buffer. If there are more elements remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no elements are transferred and a java.nio.BufferOverflowException is thrown.

Otherwise, this method copies n = src.remaining() elements from the specified buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop

    while (src.hasRemaining())
        dst.put(src.get()); 

except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.

Parameters
src:SELF

the source buffer from which elements are to be read; must not be this buffer

Returns:SELF

This buffer

Exceptions
BufferOverflowException:
If there is insufficient space in this buffer for the remaining elements in the source buffer
IllegalArgumentException:
If the source buffer is this buffer
ReadOnlyBufferException:
If this buffer is read-only
remainingback to summary
public int remaining()

Returns the number of elements between the current position and the limit.

Returns:int

the number of elements remaining in this buffer

resetback to summary
public SELF reset()

Resets this buffer's position to the previously-marked position.

Invoking this method neither changes nor discards the mark's value.

Returns:SELF

This buffer

Exceptions
InvalidMarkException:
If the mark has not been set
rewindback to summary
public SELF rewind()

Rewinds this buffer. The position is set to zero and the mark is discarded.

Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:

out.write(buf);    // Write remaining data
buf.rewind();      // Rewind buffer
buf.get(array);    // Copy data into array
Returns:SELF

This buffer

selfback to summary
protected abstract SELF self()
sizeofback to summary
public abstract int sizeof()

Returns the sizeof a single element in the buffer.

sliceback to summary
public SELF slice()

Creates a new buffer whose content is a shared subsequence of this buffer's content.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of elements remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.

Returns:SELF

the new buffer

Annotations
@SuppressWarnings:unchecked
sliceback to summary
public SELF slice(int offset, int capacity)

Returns a slice of this buffer between (buffer.position() + offset) and (buffer.position() + offset + capacity).

The position and limit of this buffer are preserved after a call to this method.

Parameters
offset:int

the slice offset, it must be ≤ this.remaining()

capacity:int

the slice length, it must be ≤ this.capacity() - (this.position() + offset)

Returns:SELF

the sliced buffer

Annotations
@SuppressWarnings:unchecked
toStringback to summary
public String toString()

Overrides org.lwjgl.system.Pointer.Default.toString.

Returns a string summarizing the state of this buffer.

Returns:String

A summary string