MappedByteBuffer.java revision 0
0N/A * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * A direct byte buffer whose content is a memory-mapped region of a file. 0N/A * <p> Mapped byte buffers are created via the {@link 0N/A * java.nio.channels.FileChannel#map FileChannel.map} method. This class 0N/A * extends the {@link ByteBuffer} class with operations that are specific to 0N/A * memory-mapped file regions. 0N/A * <p> A mapped byte buffer and the file mapping that it represents remain 0N/A * valid until the buffer itself is garbage-collected. 0N/A * <p> The content of a mapped byte buffer can change at any time, for example 0N/A * if the content of the corresponding region of the mapped file is changed by 0N/A * this program or another. Whether or not such changes occur, and when they 0N/A * occur, is operating-system dependent and therefore unspecified. 0N/A * <a name="inaccess"><p> All or part of a mapped byte buffer may become 0N/A * inaccessible at any time, for example if the mapped file is truncated. An 0N/A * attempt to access an inaccessible region of a mapped byte buffer will not 0N/A * change the buffer's content and will cause an unspecified exception to be 0N/A * thrown either at the time of the access or at some later time. It is 0N/A * therefore strongly recommended that appropriate precautions be taken to 0N/A * avoid the manipulation of a mapped file by this program, or by a 0N/A * concurrently running program, except to read or write the file's content. 0N/A * <p> Mapped byte buffers otherwise behave no differently than ordinary direct 0N/A * byte buffers. </p> 0N/A * @author Mark Reinhold 0N/A * @author JSR-51 Expert Group 0N/A // This is a little bit backwards: By rights MappedByteBuffer should be a 0N/A // subclass of DirectByteBuffer, but to keep the spec clear and simple, and 0N/A // for optimization purposes, it's easier to do it the other way around. 0N/A // This works because DirectByteBuffer is a package-private class. 0N/A // Volatile to make sure that the finalization thread sees the current 0N/A // value of this so that a region is not accidentally unmapped again later. 0N/A // This should only be invoked by the DirectByteBuffer constructors 0N/A // Can only happen if a luser explicitly casts a direct byte buffer 0N/A * Tells whether or not this buffer's content is resident in physical 0N/A * <p> A return value of <tt>true</tt> implies that it is highly likely 0N/A * that all of the data in this buffer is resident in physical memory and 0N/A * may therefore be accessed without incurring any virtual-memory page 0N/A * faults or I/O operations. A return value of <tt>false</tt> does not 0N/A * necessarily imply that the buffer's content is not resident in physical 0N/A * <p> The returned value is a hint, rather than a guarantee, because the 0N/A * underlying operating system may have paged out some of the buffer's data 0N/A * by the time that an invocation of this method returns. </p> 0N/A * @return <tt>true</tt> if it is likely that this buffer's content 0N/A * is resident in physical memory 0N/A * Loads this buffer's content into physical memory. 0N/A * <p> This method makes a best effort to ensure that, when it returns, 0N/A * this buffer's content is resident in physical memory. Invoking this 0N/A * method may cause some number of page faults and I/O operations to 0N/A * @return This buffer 0N/A * Forces any changes made to this buffer's content to be written to the 0N/A * storage device containing the mapped file. 0N/A * <p> If the file mapped into this buffer resides on a local storage 0N/A * device then when this method returns it is guaranteed that all changes 0N/A * made to the buffer since it was created, or since this method was last 0N/A * invoked, will have been written to that device. 0N/A * <p> If the file does not reside on a local device then no such guarantee 0N/A * <p> If this buffer was not mapped in read/write mode ({@link 0N/A * java.nio.channels.FileChannel.MapMode#READ_WRITE}) then invoking this 0N/A * method has no effect. </p> 0N/A * @return This buffer