Java asynchronous file copy




















This method does not block. An invocation always returns immediately, either having acquired a lock on the requested region or having failed to do so. If it fails to acquire a lock because an overlapping lock is held by another program then it returns null. If it fails to acquire a lock for any other reason then an appropriate exception is thrown. This method initiates the reading of a sequence of bytes from this channel into the given buffer, starting at the given file position.

The result of the read is the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time that the read is attempted. This method works in the same manner as the AsynchronousByteChannel. If the given file position is greater than the file's size at the time that the read is attempted then no bytes are read.

This method returns a Future representing the pending result of the operation. The Future 's get method returns the number of bytes read or -1 if the given position is greater than or equal to the file's size at the time that the read is attempted. If the given position is greater than the file's size, at the time that the write is attempted, then the file will be grown to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.

This method initiates the writing of a sequence of bytes to this channel from the given buffer, starting at the given file position. The method returns a Future representing the pending result of the write operation. The Future 's get method returns the number of bytes written. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. All rights reserved. Use is subject to license terms.

Also see the documentation redistribution policy. Object java. In addition to read and write operations, this class defines the following operations: Updates made to a file may be forced out to the underlying storage device, ensuring that data are not lost in the event of a system crash.

Forces any updates to this channel's file to be written to the storage device that contains it. Reads a sequence of bytes from this channel into the given buffer, starting at the given file position. Writes a sequence of bytes to this channel from the given buffer, starting at the given file position. Truncates this channel's file to the given size. Acquires a lock on the given region of this channel's file.

Acquires an exclusive lock on this channel's file. Attempts to acquire a lock on the given region of this channel's file. Attempts to acquire an exclusive lock on this channel's file.

AsynchronousFileChannel Initializes a new instance of this class. When opening an existing file, the file is first truncated to a size of 0 bytes. If this option is present then a new file is created, failing if the file already exists.

If this option is present then an existing file is opened if it exists, otherwise a new file is created. When this option is present then the implementation makes a best effort attempt to delete the file when closed by the the close method. When creating a new file this option is a hint that the new file will be sparse. Requires that every update to the file's content or metadata be written synchronously to the underlying storage device.

Requires that every update to the file's content be written synchronously to the underlying storage device.

Asynchronous File IO in Java. Browse pages. A t tachments 0 Page History People who can view. Copy Page Tree. Pages Index Documentation. Jira links. FileInputStream; import java. ByteBuffer; import org. AioFutureListener; import org. AioFutureReadWrite; import org.

No labels. Mike Heath. Add a comment. Active Oldest Votes. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.



0コメント

  • 1000 / 1000