MappedByteBuffer

A direct byte buffer whose content is a memory-mapped region of a file.

<p> Mapped byte buffers are created via the {@link java.nio.channels.FileChannel#map FileChannel.map} method. This class extends the {@link ByteBuffer} class with operations that are specific to memory-mapped file regions.

<p> A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected.

<p> The content of a mapped byte buffer can change at any time, for example if the content of the corresponding region of the mapped file is changed by this program or another. Whether or not such changes occur, and when they occur, is operating-system dependent and therefore unspecified.

<a name="inaccess"></a><p> All or part of a mapped byte buffer may become inaccessible at any time, for example if the mapped file is truncated. An attempt to access an inaccessible region of a mapped byte buffer will not change the buffer's content and will cause an unspecified exception to be thrown either at the time of the access or at some later time. It is therefore strongly recommended that appropriate precautions be taken to avoid the manipulation of a mapped file by this program, or by a concurrently running program, except to read or write the file's content.

<p> Mapped byte buffers otherwise behave no differently than ordinary direct byte buffers. </p>

More...

Constructors

this
this(int mark, int pos, int lim, int cap, FileDescriptor fd)
Undocumented in source.
this
this(int mark, int pos, int lim, int cap)
Undocumented in source.

Inherited Members

From ByteBuffer

hb
byte[] hb;
Undocumented in source.
offset
int offset;
Undocumented in source.
bigEndian
bool bigEndian;
Undocumented in source.
order
ByteOrder order()

Retrieves this buffer's byte order.

order
ByteBuffer order(ByteOrder bo)

Modifies this buffer's byte order.

allocateDirect
deprecated ByteBuffer allocateDirect(int capacity)

Allocates a new direct byte buffer.

allocate
deprecated ByteBuffer allocate(size_t capacity)

Allocates a new byte buffer.

wrap
deprecated ByteBuffer wrap(byte[] array, int offset, int length)

Wraps a byte array into a buffer.

wrap
deprecated ByteBuffer wrap(byte[] array)

Wraps a byte array into a buffer.

slice
ByteBuffer slice()

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

duplicate
ByteBuffer duplicate()

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

asReadOnlyBuffer
ByteBuffer asReadOnlyBuffer()

Creates a new, read-only byte buffer that shares this buffer's content.

get
byte get()

Relative <i>get</i> method. Reads the byte at this buffer's current position, and then increments the position.

put
ByteBuffer put(byte b)

Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.

get
byte get(int index)

Absolute <i>get</i> method. Reads the byte at the given index.

put
ByteBuffer put(int index, byte b)

Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.

get
ByteBuffer get(byte[] dst, int offset, int length)

Relative bulk <i>get</i> method.

get
ByteBuffer get(byte[] dst)

Relative bulk <i>get</i> method.

put
ByteBuffer put(ByteBuffer src)

Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.

put
ByteBuffer put(byte[] src, int offset, int length)

Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.

put
ByteBuffer put(byte[] src)

Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.

put
ByteBuffer put(string src)
Undocumented in source. Be warned that the author may not have intended to support it.
getShort
short getShort()

Relative <i>get</i> method for reading a short value.

putShort
ByteBuffer putShort(short value)

Relative <i>put</i> method for writing a short value&nbsp;&nbsp;<i>(optional operation)</i>.

getShort
short getShort(int index)

Absolute <i>get</i> method for reading a short value.

putShort
ByteBuffer putShort(int index, short value)

Absolute <i>put</i> method for writing a short value&nbsp;&nbsp;<i>(optional operation)</i>.

getInt
int getInt()

Relative <i>get</i> method for reading an int value.

putInt
ByteBuffer putInt(int value)

Relative <i>put</i> method for writing an int value&nbsp;&nbsp;<i>(optional operation)</i>.

getInt
int getInt(int index)

Absolute <i>get</i> method for reading an int value.

putInt
ByteBuffer putInt(int index, int value)

Absolute <i>put</i> method for writing an int value&nbsp;&nbsp;<i>(optional operation)</i>.

getLong
long getLong()

Relative <i>get</i> method for reading a long value.

putLong
ByteBuffer putLong(long value)

Relative <i>put</i> method for writing a long value&nbsp;&nbsp;<i>(optional operation)</i>.

getLong
long getLong(int index)

Absolute <i>get</i> method for reading a long value.

putLong
ByteBuffer putLong(int index, long value)

Absolute <i>put</i> method for writing a long value&nbsp;&nbsp;<i>(optional operation)</i>.

hasArray
bool hasArray()

Tells whether or not this buffer is backed by an accessible byte array.

array
byte[] array()

Returns the byte array that backs this buffer&nbsp;&nbsp;<i>(optional operation)</i>.

arrayOffset
int arrayOffset()

Returns the offset within this buffer's backing array of the first element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.

compact
ByteBuffer compact()

Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.

get
T get()

Relative <i>get</i> method for reading an int value.

get
T get(int index)

Absolute <i>get</i> method for reading an int value.

put
ByteBuffer put(T value)

Relative <i>put</i> method for writing a short value&nbsp;&nbsp;<i>(optional operation)</i>.

put
ByteBuffer put(int index, T value)

Absolute <i>put</i> method for writing a short value&nbsp;&nbsp;<i>(optional operation)</i>.

ix
int ix(int i)
Undocumented in source. Be warned that the author may not have intended to support it.
byteOffset
size_t byteOffset(size_t i)
Undocumented in source. Be warned that the author may not have intended to support it.
getString
string getString(size_t offset, size_t len)
Undocumented in source. Be warned that the author may not have intended to support it.
getRemaining
byte[] getRemaining()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Returns a string summarizing the state of this buffer.

Detailed Description

@author Mark Reinhold @author JSR-51 Expert Group

Meta