Package java.nio.channels; Public abstract class FileChannel extends Abstractinterruptiblechannel implements Seekablebytechannel, Gatheringby
Techannel, Scatteringbytechannel {/** * Initializes an parameterless constructor.
* * Protected FileChannel () {}//Open or create a file that returns a file channel to access the file public static FileChannel open (path path, set<? Extends openoption> options, Fileattribute<?> ... attrs) throws Ioexcep
tion {Filesystemprovider Provider = Path.getfilesystem (). Provider ();
return Provider.newfilechannel (Path, options, attrs);
private static final fileattribute<?>[] No_attributes = new Fileattribute[0];
Opens or creates a file that returns a file channel to access the file public static FileChannel open (path Path, openoption ... options) throws IOException
{set<openoption> Set = new hashset<openoption> (options.length);
Collections.addall (set, options);Return open (path, set, no_attributes);
//read a byte sequence from this channel to the given buffer public abstract int Read (Bytebuffer DST) throws IOException; Reads the byte sequence at the specified start position and length from this channel to the given buffer public abstract long read (bytebuffer[] dsts, int offset, int length) throws IOE
Xception; /** * Reads a sequence of bytes from this channel to the given buffer */public final long read (bytebuffer[] dsts) throws IOException {return
Read (DSTs, 0, dsts.length);
/** * Writes a byte sequence from a given buffer to this channel * * Public abstract int write (Bytebuffer src) throws IOException;
/** * Writes a byte sequence to the channel from a subsequence of a given buffer * * Public abstract long write (bytebuffer[] srcs, int offset, int length)
Throws IOException; /** * Writes a byte sequence from a given buffer to this channel/public final long write (bytebuffer[] srcs) throws IOException {return W
Rite (SRCS, 0, srcs.length);
/** * Returns the start position in the channel read/write buffer/public abstract long position () throws IOException; /** * Set the start position in the channel read/write buffer * * Public ABSTract FileChannel position (long newposition) throws IOException;
/** * Returns the current size of this channel file */public abstract long size () throws IOException;
/** * Intercepts the size of the channel by the specified parameter size * * Public abstract FileChannel truncate (long size) throws IOException;
/** * Forces the update files in the channel to be written to the storage device (disk, etc.)/public abstract void Force (Boolean metaData) throws IOException; /** * Writes a file in the current channel to a writable byte channel * position is where the write begins, long is the length of the write/public abstract long transferTo (long position,
Long count, Writablebytechannel target) throws IOException; /** * Writes the files in the current channel to the readable byte channel * position is where to begin writing, long is the length of write/public abstract long Transferfrom (Readablebytech
Annel src, long position, long count) throws IOException; /** * Reads a series of bytes from the channel to the given buffer * reads from the specified read start position position/public abstract int Read (Bytebuffer DST, long Positio
n) throws IOException;
/** * Writes a byte sequence from a given buffer to this channel * starts writing at the specified read start position position/public abstract int Write (Bytebuffer src, lon
G position) throws IOException;
--memory-mapped buffers--/** * A file Map mode type Security enumeration/public static class Mapmode {//read-only mapping model
public static final Mapmode read_only = new Mapmode ("Read_Only");
Read-Write mapping model public static final Mapmode read_write = new Mapmode ("Read_write");
/** * Private mode (copy in write) mapping * * public static final Mapmode PRIVATE = new Mapmode ("private");
Private final String name;
Private Mapmode (String name) {this.name = name;
}/** * Maps a region of the channel file directly into memory/public abstract Mappedbytebuffer Map (mapmode mode,
Long position, long size) throws IOException; /** * Gets the lock * area on the given area of the current channel file starting at position, and the size length * shared as true representsGets the shared lock, and false represents a acquire exclusive lock/public abstract Filelock Lock (long position, long size, Boolean shared) throws Ioex
ception; /** * Get exclusive lock on current channel file/public final Filelock lock () throws IOException {return lock (0L, Long.max_va
LUE, false); /** * Attempts to acquire a lock on the given channel file area is starting at the position, and the size length * shared to true represents acquiring a shared lock, false represents acquiring an exclusive lock/public
Abstract Filelock Trylock (long position, long size, Boolean shared) throws IOException; /** * Attempt to acquire exclusive lock on current channel file/public final Filelock Trylock () throws IOException {return Trylock (0L, Lon
G.max_value, false);
}
}