Android Guides | Samples

Java.Nio.Buffer Class

A buffer is a list of elements of a specific primitive type.

See Also: Buffer

Syntax

[Android.Runtime.Register("java/nio/Buffer", DoNotGenerateAcw=true)]
public abstract class Buffer : Object

Remarks

A buffer is a list of elements of a specific primitive type.

A buffer can be described by the following properties:

  • Capacity: the number of elements a buffer can hold. Capacity may not be negative and never changes.
  • Position: a cursor of this buffer. Elements are read or written at the position if you do not specify an index explicitly. Position may not be negative and not greater than the limit.
  • Limit: controls the scope of accessible elements. You can only read or write elements from index zero to limit - 1. Accessing elements out of the scope will cause an exception. Limit may not be negative and not greater than capacity.
  • Mark: used to remember the current position, so that you can reset the position later. Mark may not be negative and no greater than position.
  • A buffer can be read-only or read-write. Trying to modify the elements of a read-only buffer will cause a ReadOnlyBufferException, while changing the position, limit and mark of a read-only buffer is OK.
  • A buffer can be direct or indirect. A direct buffer will try its best to take advantage of native memory APIs and it may not stay in the Java heap, thus it is not affected by garbage collection.

Buffers are not thread-safe. If concurrent access to a buffer instance is required, then the callers are responsible to take care of the synchronization issues.

[Android Documentation]

Requirements

Namespace: Java.Nio
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Nio.Buffer are listed below.

See Also: Object

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
abstract
HasArrayBoolean. Returns true if array and arrayOffset won't throw.
[read-only]
HasRemainingBoolean. Indicates if there are elements remaining in this buffer, that is if position .
[read-only]
abstract
IsDirectBoolean. Returns true if this is a direct buffer.
[read-only]
abstract
IsReadOnlyBoolean. Indicates whether this buffer is read-only.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

abstract
ArrayOffset() : Int32
Returns the offset into the array returned by array of the first element of the buffer (optional operation).
Capacity() : Int32
Returns the capacity of this buffer.
Clear() : Buffer
Clears this buffer.
Flip() : Buffer
Flips this buffer.
GetDirectBufferAddress() : IntPtr
Limit() : Int32
Returns the limit of this buffer.
Limit(Int32) : Buffer
Sets the limit of this buffer.
Mark() : Buffer
Marks the current position, so that the position may return to this point later by calling reset().
Position() : Int32
Returns the position of this buffer.
Position(Int32) : Buffer
Sets the position of this buffer.
Remaining() : Int32
Returns the number of remaining elements in this buffer, that is limit - position.
Reset() : Buffer
Resets the position of this buffer to the mark.
Rewind() : Buffer
Rewinds this buffer.