java.nio
Class MappedByteBuffer

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.nio.Buffer sample code for java.nio.Buffer definition code for java.nio.Buffer 
      extended by java.nio.ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer 
          extended by java.nio.MappedByteBuffer
All Implemented Interfaces:
Comparable sample code for java.lang.Comparable definition code for java.lang.Comparable <ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer >

public abstract class MappedByteBuffer
extends ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer

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

Mapped byte buffers are created via the FileChannel.map sample code for java.nio.channels.FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long) definition code for java.nio.channels.FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long) method. This class extends the ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer class with operations that are specific to memory-mapped file regions.

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

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.

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.

Mapped byte buffers otherwise behave no differently than ordinary direct byte buffers.

Since:
1.4

Method Summary
 MappedByteBuffer sample code for java.nio.MappedByteBuffer definition code for java.nio.MappedByteBuffer force sample code for java.nio.MappedByteBuffer.force() definition code for java.nio.MappedByteBuffer.force() ()
          Forces any changes made to this buffer's content to be written to the storage device containing the mapped file.
 boolean isLoaded sample code for java.nio.MappedByteBuffer.isLoaded() definition code for java.nio.MappedByteBuffer.isLoaded() ()
          Tells whether or not this buffer's content is resident in physical memory.
 MappedByteBuffer sample code for java.nio.MappedByteBuffer definition code for java.nio.MappedByteBuffer load sample code for java.nio.MappedByteBuffer.load() definition code for java.nio.MappedByteBuffer.load() ()
          Loads this buffer's content into physical memory.
 
Methods inherited from class java.nio.ByteBuffer sample code for java.nio.ByteBuffer definition code for java.nio.ByteBuffer
allocate sample code for java.nio.ByteBuffer.allocate(int) definition code for java.nio.ByteBuffer.allocate(int) , allocateDirect sample code for java.nio.ByteBuffer.allocateDirect(int) definition code for java.nio.ByteBuffer.allocateDirect(int) , array sample code for java.nio.ByteBuffer.array() definition code for java.nio.ByteBuffer.array() , arrayOffset sample code for java.nio.ByteBuffer.arrayOffset() definition code for java.nio.ByteBuffer.arrayOffset() , asCharBuffer sample code for java.nio.ByteBuffer.asCharBuffer() definition code for java.nio.ByteBuffer.asCharBuffer() , asDoubleBuffer sample code for java.nio.ByteBuffer.asDoubleBuffer() definition code for java.nio.ByteBuffer.asDoubleBuffer() , asFloatBuffer sample code for java.nio.ByteBuffer.asFloatBuffer() definition code for java.nio.ByteBuffer.asFloatBuffer() , asIntBuffer sample code for java.nio.ByteBuffer.asIntBuffer() definition code for java.nio.ByteBuffer.asIntBuffer() , asLongBuffer sample code for java.nio.ByteBuffer.asLongBuffer() definition code for java.nio.ByteBuffer.asLongBuffer() , asReadOnlyBuffer sample code for java.nio.ByteBuffer.asReadOnlyBuffer() definition code for java.nio.ByteBuffer.asReadOnlyBuffer() , asShortBuffer sample code for java.nio.ByteBuffer.asShortBuffer() definition code for java.nio.ByteBuffer.asShortBuffer() , compact sample code for java.nio.ByteBuffer.compact() definition code for java.nio.ByteBuffer.compact() , compareTo sample code for java.nio.ByteBuffer.compareTo(java.nio.ByteBuffer) definition code for java.nio.ByteBuffer.compareTo(java.nio.ByteBuffer) , duplicate sample code for java.nio.ByteBuffer.duplicate() definition code for java.nio.ByteBuffer.duplicate() , equals sample code for java.nio.ByteBuffer.equals(java.lang.Object) definition code for java.nio.ByteBuffer.equals(java.lang.Object) , get sample code for java.nio.ByteBuffer.get() definition code for java.nio.ByteBuffer.get() , get sample code for java.nio.ByteBuffer.get(byte[]) definition code for java.nio.ByteBuffer.get(byte[]) , get sample code for java.nio.ByteBuffer.get(byte[], int, int) definition code for java.nio.ByteBuffer.get(byte[], int, int) , get sample code for java.nio.ByteBuffer.get(int) definition code for java.nio.ByteBuffer.get(int) , getChar sample code for java.nio.ByteBuffer.getChar() definition code for java.nio.ByteBuffer.getChar() , getChar sample code for java.nio.ByteBuffer.getChar(int) definition code for java.nio.ByteBuffer.getChar(int) , getDouble sample code for java.nio.ByteBuffer.getDouble() definition code for java.nio.ByteBuffer.getDouble() , getDouble sample code for java.nio.ByteBuffer.getDouble(int) definition code for java.nio.ByteBuffer.getDouble(int) , getFloat sample code for java.nio.ByteBuffer.getFloat() definition code for java.nio.ByteBuffer.getFloat() , getFloat sample code for java.nio.ByteBuffer.getFloat(int) definition code for java.nio.ByteBuffer.getFloat(int) , getInt sample code for java.nio.ByteBuffer.getInt() definition code for java.nio.ByteBuffer.getInt() , getInt sample code for java.nio.ByteBuffer.getInt(int) definition code for java.nio.ByteBuffer.getInt(int) , getLong sample code for java.nio.ByteBuffer.getLong() definition code for java.nio.ByteBuffer.getLong() , getLong sample code for java.nio.ByteBuffer.getLong(int) definition code for java.nio.ByteBuffer.getLong(int) , getShort sample code for java.nio.ByteBuffer.getShort() definition code for java.nio.ByteBuffer.getShort() , getShort sample code for java.nio.ByteBuffer.getShort(int) definition code for java.nio.ByteBuffer.getShort(int) , hasArray sample code for java.nio.ByteBuffer.hasArray() definition code for java.nio.ByteBuffer.hasArray() , hashCode sample code for java.nio.ByteBuffer.hashCode() definition code for java.nio.ByteBuffer.hashCode() , isDirect sample code for java.nio.ByteBuffer.isDirect() definition code for java.nio.ByteBuffer.isDirect() , order sample code for java.nio.ByteBuffer.order() definition code for java.nio.ByteBuffer.order() , order sample code for java.nio.ByteBuffer.order(java.nio.ByteOrder) definition code for java.nio.ByteBuffer.order(java.nio.ByteOrder) , put sample code for java.nio.ByteBuffer.put(byte) definition code for java.nio.ByteBuffer.put(byte) , put sample code for java.nio.ByteBuffer.put(byte[]) definition code for java.nio.ByteBuffer.put(byte[]) , put sample code for java.nio.ByteBuffer.put(byte[], int, int) definition code for java.nio.ByteBuffer.put(byte[], int, int) , put sample code for java.nio.ByteBuffer.put(java.nio.ByteBuffer) definition code for java.nio.ByteBuffer.put(java.nio.ByteBuffer) , put sample code for java.nio.ByteBuffer.put(int, byte) definition code for java.nio.ByteBuffer.put(int, byte) , putChar sample code for java.nio.ByteBuffer.putChar(char) definition code for java.nio.ByteBuffer.putChar(char) , putChar sample code for java.nio.ByteBuffer.putChar(int, char) definition code for java.nio.ByteBuffer.putChar(int, char) , putDouble sample code for java.nio.ByteBuffer.putDouble(double) definition code for java.nio.ByteBuffer.putDouble(double) , putDouble sample code for java.nio.ByteBuffer.putDouble(int, double) definition code for java.nio.ByteBuffer.putDouble(int, double) , putFloat sample code for java.nio.ByteBuffer.putFloat(float) definition code for java.nio.ByteBuffer.putFloat(float) , putFloat sample code for java.nio.ByteBuffer.putFloat(int, float) definition code for java.nio.ByteBuffer.putFloat(int, float) , putInt sample code for java.nio.ByteBuffer.putInt(int) definition code for java.nio.ByteBuffer.putInt(int) , putInt sample code for java.nio.ByteBuffer.putInt(int, int) definition code for java.nio.ByteBuffer.putInt(int, int) , putLong sample code for java.nio.ByteBuffer.putLong(int, long) definition code for java.nio.ByteBuffer.putLong(int, long) , putLong sample code for java.nio.ByteBuffer.putLong(long) definition code for java.nio.ByteBuffer.putLong(long) , putShort sample code for java.nio.ByteBuffer.putShort(int, short) definition code for java.nio.ByteBuffer.putShort(int, short) , putShort sample code for java.nio.ByteBuffer.putShort(short) definition code for java.nio.ByteBuffer.putShort(short) , slice sample code for java.nio.ByteBuffer.slice() definition code for java.nio.ByteBuffer.slice() , toString sample code for java.nio.ByteBuffer.toString() definition code for java.nio.ByteBuffer.toString() , wrap sample code for java.nio.ByteBuffer.wrap(byte[]) definition code for java.nio.ByteBuffer.wrap(byte[]) , wrap sample code for java.nio.ByteBuffer.wrap(byte[], int, int) definition code for java.nio.ByteBuffer.wrap(byte[], int, int)
 
Methods inherited from class java.nio.Buffer sample code for java.nio.Buffer definition code for java.nio.Buffer
capacity sample code for java.nio.Buffer.capacity() definition code for java.nio.Buffer.capacity() , clear sample code for java.nio.Buffer.clear() definition code for java.nio.Buffer.clear() , flip sample code for java.nio.Buffer.flip() definition code for java.nio.Buffer.flip() , hasRemaining sample code for java.nio.Buffer.hasRemaining() definition code for java.nio.Buffer.hasRemaining() , isReadOnly sample code for java.nio.Buffer.isReadOnly() definition code for java.nio.Buffer.isReadOnly() , limit sample code for java.nio.Buffer.limit() definition code for java.nio.Buffer.limit() , limit sample code for java.nio.Buffer.limit(int) definition code for java.nio.Buffer.limit(int) , mark sample code for java.nio.Buffer.mark() definition code for java.nio.Buffer.mark() , position sample code for java.nio.Buffer.position() definition code for java.nio.Buffer.position() , position sample code for java.nio.Buffer.position(int) definition code for java.nio.Buffer.position(int) , remaining sample code for java.nio.Buffer.remaining() definition code for java.nio.Buffer.remaining() , reset sample code for java.nio.Buffer.reset() definition code for java.nio.Buffer.reset() , rewind sample code for java.nio.Buffer.rewind() definition code for java.nio.Buffer.rewind()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Method Detail

isLoaded sample code for java.nio.MappedByteBuffer.isLoaded() definition code for java.nio.MappedByteBuffer.isLoaded()

public final boolean isLoaded()
Tells whether or not this buffer's content is resident in physical memory.

A return value of true implies that it is highly likely that all of the data in this buffer is resident in physical memory and may therefore be accessed without incurring any virtual-memory page faults or I/O operations. A return value of false does not necessarily imply that the buffer's content is not resident in physical memory.

The returned value is a hint, rather than a guarantee, because the underlying operating system may have paged out some of the buffer's data by the time that an invocation of this method returns.

Returns:
true if it is likely that this buffer's content is resident in physical memory

load sample code for java.nio.MappedByteBuffer.load() definition code for java.nio.MappedByteBuffer.load()

public final MappedByteBuffer sample code for java.nio.MappedByteBuffer definition code for java.nio.MappedByteBuffer  load()
Loads this buffer's content into physical memory.

This method makes a best effort to ensure that, when it returns, this buffer's content is resident in physical memory. Invoking this method may cause some number of page faults and I/O operations to occur.

Returns:
This buffer

force sample code for java.nio.MappedByteBuffer.force() definition code for java.nio.MappedByteBuffer.force()

public final MappedByteBuffer sample code for java.nio.MappedByteBuffer definition code for java.nio.MappedByteBuffer  force()
Forces any changes made to this buffer's content to be written to the storage device containing the mapped file.

If the file mapped into this buffer resides on a local storage device then when this method returns it is guaranteed that all changes made to the buffer since it was created, or since this method was last invoked, will have been written to that device.

If the file does not reside on a local device then no such guarantee is made.

If this buffer was not mapped in read/write mode (FileChannel.MapMode.READ_WRITE sample code for java.nio.channels.FileChannel.MapMode.READ_WRITE definition code for java.nio.channels.FileChannel.MapMode.READ_WRITE ) then invoking this method has no effect.

Returns:
This buffer