8221397: Support implementation-defined Map Modes
Allow implementation-defined extensions to FileChannel MapMode enum Reviewed-by: alanb
This commit is contained in:
parent
4a477cabd8
commit
1c7d214f53
@ -791,7 +791,7 @@ public abstract class FileChannel
|
|||||||
// -- Memory-mapped buffers --
|
// -- Memory-mapped buffers --
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A typesafe enumeration for file-mapping modes.
|
* A file-mapping mode.
|
||||||
*
|
*
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*
|
*
|
||||||
@ -819,6 +819,12 @@ public abstract class FileChannel
|
|||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an instance of this class. This constructor may be used
|
||||||
|
* by code in java.base to create file mapping modes beyond the file
|
||||||
|
* mapping modes defined here.
|
||||||
|
* @param name the name of the map mode
|
||||||
|
*/
|
||||||
private MapMode(String name) {
|
private MapMode(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@ -837,8 +843,8 @@ public abstract class FileChannel
|
|||||||
/**
|
/**
|
||||||
* Maps a region of this channel's file directly into memory.
|
* Maps a region of this channel's file directly into memory.
|
||||||
*
|
*
|
||||||
* <p> A region of a file may be mapped into memory in one of three modes:
|
* <p> The {@code mode} parameter specifies how the region of the file is
|
||||||
* </p>
|
* mapped and may be one of the following modes:
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
*
|
*
|
||||||
@ -859,6 +865,8 @@ public abstract class FileChannel
|
|||||||
*
|
*
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
* <p> An implementation may support additional map modes.
|
||||||
|
*
|
||||||
* <p> For a read-only mapping, this channel must have been opened for
|
* <p> For a read-only mapping, this channel must have been opened for
|
||||||
* reading; for a read/write or private mapping, this channel must have
|
* reading; for a read/write or private mapping, this channel must have
|
||||||
* been opened for both reading and writing.
|
* been opened for both reading and writing.
|
||||||
@ -892,7 +900,8 @@ public abstract class FileChannel
|
|||||||
* MapMode#READ_WRITE READ_WRITE}, or {@link MapMode#PRIVATE
|
* MapMode#READ_WRITE READ_WRITE}, or {@link MapMode#PRIVATE
|
||||||
* PRIVATE} defined in the {@link MapMode} class, according to
|
* PRIVATE} defined in the {@link MapMode} class, according to
|
||||||
* whether the file is to be mapped read-only, read/write, or
|
* whether the file is to be mapped read-only, read/write, or
|
||||||
* privately (copy-on-write), respectively
|
* privately (copy-on-write), respectively, or an implementation
|
||||||
|
* specific map mode
|
||||||
*
|
*
|
||||||
* @param position
|
* @param position
|
||||||
* The position within the file at which the mapped region
|
* The position within the file at which the mapped region
|
||||||
@ -905,25 +914,29 @@ public abstract class FileChannel
|
|||||||
* @return The mapped byte buffer
|
* @return The mapped byte buffer
|
||||||
*
|
*
|
||||||
* @throws NonReadableChannelException
|
* @throws NonReadableChannelException
|
||||||
* If the {@code mode} is {@link MapMode#READ_ONLY READ_ONLY} but
|
* If the {@code mode} is {@link MapMode#READ_ONLY READ_ONLY} or
|
||||||
* this channel was not opened for reading
|
* an implementation specific map mode requiring read access
|
||||||
|
* but this channel was not opened for reading
|
||||||
*
|
*
|
||||||
* @throws NonWritableChannelException
|
* @throws NonWritableChannelException
|
||||||
* If the {@code mode} is {@link MapMode#READ_WRITE READ_WRITE} or
|
* If the {@code mode} is {@link MapMode#READ_WRITE READ_WRITE}.
|
||||||
* {@link MapMode#PRIVATE PRIVATE} but this channel was not opened
|
* {@link MapMode#PRIVATE PRIVATE} or an implementation specific
|
||||||
* for both reading and writing
|
* map mode requiring write access but this channel was not
|
||||||
|
* opened for both reading and writing
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException
|
* @throws IllegalArgumentException
|
||||||
* If the preconditions on the parameters do not hold
|
* If the preconditions on the parameters do not hold
|
||||||
*
|
*
|
||||||
|
* @throws UnsupportedOperationException
|
||||||
|
* If an unsupported map mode is specified
|
||||||
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* If some other I/O error occurs
|
* If some other I/O error occurs
|
||||||
*
|
*
|
||||||
* @see java.nio.channels.FileChannel.MapMode
|
* @see java.nio.channels.FileChannel.MapMode
|
||||||
* @see java.nio.MappedByteBuffer
|
* @see java.nio.MappedByteBuffer
|
||||||
*/
|
*/
|
||||||
public abstract MappedByteBuffer map(MapMode mode,
|
public abstract MappedByteBuffer map(MapMode mode, long position, long size)
|
||||||
long position, long size)
|
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
|
|
||||||
|
@ -940,14 +940,15 @@ public class FileChannelImpl
|
|||||||
if (size > Integer.MAX_VALUE)
|
if (size > Integer.MAX_VALUE)
|
||||||
throw new IllegalArgumentException("Size exceeds Integer.MAX_VALUE");
|
throw new IllegalArgumentException("Size exceeds Integer.MAX_VALUE");
|
||||||
|
|
||||||
int imode = -1;
|
int imode;
|
||||||
if (mode == MapMode.READ_ONLY)
|
if (mode == MapMode.READ_ONLY)
|
||||||
imode = MAP_RO;
|
imode = MAP_RO;
|
||||||
else if (mode == MapMode.READ_WRITE)
|
else if (mode == MapMode.READ_WRITE)
|
||||||
imode = MAP_RW;
|
imode = MAP_RW;
|
||||||
else if (mode == MapMode.PRIVATE)
|
else if (mode == MapMode.PRIVATE)
|
||||||
imode = MAP_PV;
|
imode = MAP_PV;
|
||||||
assert (imode >= 0);
|
else
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
if ((mode != MapMode.READ_ONLY) && !writable)
|
if ((mode != MapMode.READ_ONLY) && !writable)
|
||||||
throw new NonWritableChannelException();
|
throw new NonWritableChannelException();
|
||||||
if (!readable)
|
if (!readable)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user