⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filechannel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * is made.     *     * <p> The <tt>metaData</tt> parameter can be used to limit the number of     * I/O operations that this method is required to perform.  Passing     * <tt>false</tt> for this parameter indicates that only updates to the     * file's content need be written to storage; passing <tt>true</tt>     * indicates that updates to both the file's content and metadata must be     * written, which generally requires at least one more I/O operation.     * Whether this parameter actually has any effect is dependent upon the     * underlying operating system and is therefore unspecified.     *     * <p> Invoking this method may cause an I/O operation to occur even if the     * channel was only opened for reading.  Some operating systems, for     * example, maintain a last-access time as part of a file's metadata, and     * this time is updated whenever the file is read.  Whether or not this is     * actually done is system-dependent and is therefore unspecified.     *     * <p> This method is only guaranteed to force changes that were made to     * this channel's file via the methods defined in this class.  It may or     * may not force changes that were made by modifying the content of a     * {@link MappedByteBuffer </code>mapped byte buffer<code>} obtained by     * invoking the {@link #map map} method.  Invoking the {@link     * MappedByteBuffer#force force} method of the mapped byte buffer will     * force changes made to the buffer's content to be written.  </p>     *     * @param   metaData     *          If <tt>true</tt> then this method is required to force changes     *          to both the file's content and metadata to be written to     *          storage; otherwise, it need only force content changes to be     *          written     *     * @throws  ClosedChannelException     *          If this channel is closed     *     * @throws  IOException     *          If some other I/O error occurs     */    public abstract void force(boolean metaData) throws IOException;    /**     * Transfers bytes from this channel's file to the given writable byte     * channel.     *     * <p> An attempt is made to read up to <tt>count</tt> bytes starting at     * the given <tt>position</tt> in this channel's file and write them to the     * target channel.  An invocation of this method may or may not transfer     * all of the requested bytes; whether or not it does so depends upon the     * natures and states of the channels.  Fewer than the requested number of     * bytes are transferred if this channel's file contains fewer than     * <tt>count</tt> bytes starting at the given <tt>position</tt>, or if the     * target channel is non-blocking and it has fewer than <tt>count</tt>     * bytes free in its output buffer.     *     * <p> This method does not modify this channel's position.  If the given     * position is greater than the file's current size then no bytes are     * transferred.  If the target channel has a position then bytes are     * written starting at that position and then the position is incremented     * by the number of bytes written.     *     * <p> This method is potentially much more efficient than a simple loop     * that reads from this channel and writes to the target channel.  Many     * operating systems can transfer bytes directly from the filesystem cache     * to the target channel without actually copying them.  </p>     *     * @param  position     *         The position within the file at which the transfer is to begin;     *         must be non-negative     *     * @param  count     *         The maximum number of bytes to be transferred; must be     *         non-negative     *     * @param  target     *         The target channel     *     * @return  The number of bytes, possibly zero,     *          that were actually transferred     *     * @throws IllegalArgumentException     *         If the preconditions on the parameters do not hold     *     * @throws  NonReadableChannelException     *          If this channel was not opened for reading     *     * @throws  NonWritableChannelException     *          If the target channel was not opened for writing     *     * @throws  ClosedChannelException     *          If either this channel or the target channel is closed     *     * @throws  AsynchronousCloseException     *          If another thread closes either channel     *          while the transfer is in progress     *     * @throws  ClosedByInterruptException     *          If another thread interrupts the current thread while the     *          transfer is in progress, thereby closing both channels and     *          setting the current thread's interrupt status     *     * @throws  IOException     *          If some other I/O error occurs     */    public abstract long transferTo(long position, long count,				    WritableByteChannel target)	throws IOException;    /**     * Transfers bytes into this channel's file from the given readable byte     * channel.     *     * <p> An attempt is made to read up to <tt>count</tt> bytes from the     * source channel and write them to this channel's file starting at the     * given <tt>position</tt>.  An invocation of this method may or may not     * transfer all of the requested bytes; whether or not it does so depends     * upon the natures and states of the channels.  Fewer than the requested     * number of bytes will be transferred if the source channel has fewer than     * <tt>count</tt> bytes remaining, or if the source channel is non-blocking     * and has fewer than <tt>count</tt> bytes immediately available in its     * input buffer.     *     * <p> This method does not modify this channel's position.  If the given     * position is greater than the file's current size then no bytes are     * transferred.  If the source channel has a position then bytes are read     * starting at that position and then the position is incremented by the     * number of bytes read.     *     * <p> This method is potentially much more efficient than a simple loop     * that reads from the source channel and writes to this channel.  Many     * operating systems can transfer bytes directly from the source channel     * into the filesystem cache without actually copying them.  </p>     *     * @param  src     *         The source channel     *     * @param  position     *         The position within the file at which the transfer is to begin;     *         must be non-negative     *     * @param  count     *         The maximum number of bytes to be transferred; must be     *         non-negative     *     * @return  The number of bytes, possibly zero,     *          that were actually transferred     *     * @throws IllegalArgumentException     *         If the preconditions on the parameters do not hold     *     * @throws  NonReadableChannelException     *          If the source channel was not opened for reading     *     * @throws  NonWritableChannelException     *          If this channel was not opened for writing     *     * @throws  ClosedChannelException     *          If either this channel or the source channel is closed     *     * @throws  AsynchronousCloseException     *          If another thread closes either channel     *          while the transfer is in progress     *     * @throws  ClosedByInterruptException     *          If another thread interrupts the current thread while the     *          transfer is in progress, thereby closing both channels and     *          setting the current thread's interrupt status     *     * @throws  IOException     *          If some other I/O error occurs     */    public abstract long transferFrom(ReadableByteChannel src,				      long position, long count)	throws IOException;    /**     * Reads a sequence of bytes from this channel into the given buffer,     * starting at the given file position.     *     * <p> This method works in the same manner as the {@link     * #read(ByteBuffer)} method, except that bytes are read starting at the     * given file position rather than at the channel's current position.  This     * method does not modify this channel's position.  If the given position     * is greater than the file's current size then no bytes are read.  </p>     *     * @param  dst     *         The buffer into which bytes are to be transferred     *     * @param  position     *         The file position at which the transfer is to begin;     *         must be non-negative     *     * @return  The number of bytes read, possibly zero, or <tt>-1</tt> if the     *          given position is greater than or equal to the file's current     *          size     *     * @throws  IllegalArgumentException     *          If the position is negative     *     * @throws  NonReadableChannelException     *          If this channel was not opened for reading     *     * @throws  ClosedChannelException     *          If this channel is closed     *     * @throws  AsynchronousCloseException     *          If another thread closes this channel     *          while the read operation is in progress     *     * @throws  ClosedByInterruptException     *          If another thread interrupts the current thread     *          while the read operation is in progress, thereby     *          closing the channel and setting the current thread's     *          interrupt status     *     * @throws  IOException     *          If some other I/O error occurs     */    public abstract int read(ByteBuffer dst, long position) throws IOException;    /**     * Writes a sequence of bytes to this channel from the given buffer,     * starting at the given file position.     *     * <p> This method works in the same manner as the {@link     * #write(ByteBuffer)} method, except that bytes are written starting at     * the given file position rather than at the channel's current position.     * This method does not modify this channel's position.  If the given     * position is greater than the file's current size then the file will be     * grown to accomodate the new bytes; the values of any bytes between the     * previous end-of-file and the newly-written bytes are unspecified.  </p>     *     * @param  src     *         The buffer from which bytes are to be transferred     *     * @param  position     *         The file position at which the transfer is to begin;     *         must be non-negative     *     * @return  The number of bytes written, possibly zero     *     * @throws  IllegalArgumentException     *          If the position is negative     *     * @throws  NonWritableChannelException     *          If this channel was not opened for writing     *     * @throws  ClosedChannelException     *          If this channel is closed     *     * @throws  AsynchronousCloseException     *          If another thread closes this channel     *          while the write operation is in progress     *     * @throws  ClosedByInterruptException     *          If another thread interrupts the current thread     *          while the write operation is in progress, thereby     *          closing the channel and setting the current thread's     *          interrupt status     *     * @throws  IOException     *          If some other I/O error occurs     */    public abstract int write(ByteBuffer src, long position) throws IOException;    // -- Memory-mapped buffers --    /**     * A typesafe enumeration for file-mapping modes.     *     * @version 1.38, 03/01/23     * @since 1.4     *     * @see java.nio.channels.FileChannel#map     */    public static class MapMode {	/**	 * Mode for a read-only mapping.	 */	public static final MapMode READ_ONLY	    = new MapMode("READ_ONLY");	/**	 * Mode for a read/write mapping.	 */	public static final MapMode READ_WRITE	    = new MapMode("READ_WRITE");	/**	 * Mode for a private (copy-on-write) mapping.	 */	public static final MapMode PRIVATE	    = new MapMode("PRIVATE");	private final String name;	private MapMode(String name) {	    this.name = name;	}	/**	 * Returns a string describing this file-mapping mode.	 *	 * @return  A descriptive string	 */	public String toString() {	    return name;	}    }    /**     * 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>     *     * <ul type=disc>     *     *   <li><p> <i>Read-only:</i> Any attempt to modify the resulting buffer     *   will cause a {@link java.nio.ReadOnlyBufferException} to be thrown.     *   ({@link MapMode#READ_ONLY MapMode.READ_ONLY}) </p></li>     *     *   <li><p> <i>Read/write:</i> Changes made to the resulting buffer will

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -