< prev index next >

src/java.base/share/classes/java/nio/channels/AsynchronousFileChannel.java

Print this page




 116 {
 117     /**
 118      * Initializes a new instance of this class.
 119      */
 120     protected AsynchronousFileChannel() {
 121     }
 122 
 123     /**
 124      * Opens or creates a file for reading and/or writing, returning an
 125      * asynchronous file channel to access the file.
 126      *
 127      * <p> The {@code options} parameter determines how the file is opened.
 128      * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE
 129      * WRITE} options determines if the file should be opened for reading and/or
 130      * writing. If neither option is contained in the array then an existing file
 131      * is opened for  reading.
 132      *
 133      * <p> In addition to {@code READ} and {@code WRITE}, the following options
 134      * may be present:
 135      *
 136      * <table border=1 cellpadding=5 summary="">


 137      * <tr> <th>Option</th> <th>Description</th> </tr>


 138      * <tr>
 139      *   <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td>
 140      *   <td> When opening an existing file, the file is first truncated to a
 141      *   size of 0 bytes. This option is ignored when the file is opened only
 142      *   for reading.</td>
 143      * </tr>
 144      * <tr>
 145      *   <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td>
 146      *   <td> If this option is present then a new file is created, failing if
 147      *   the file already exists. When creating a file the check for the
 148      *   existence of the file and the creation of the file if it does not exist
 149      *   is atomic with respect to other file system operations. This option is
 150      *   ignored when the file is opened only for reading. </td>
 151      * </tr>
 152      * <tr>
 153      *   <td > {@link StandardOpenOption#CREATE CREATE} </td>
 154      *   <td> If this option is present then an existing file is opened if it
 155      *   exists, otherwise a new file is created. When creating a file the check
 156      *   for the existence of the file and the creation of the file if it does
 157      *   not exist is atomic with respect to other file system operations. This


 169      * <tr>
 170      *   <td>{@link StandardOpenOption#SPARSE SPARSE} </td>
 171      *   <td> When creating a new file this option is a <em>hint</em> that the
 172      *   new file will be sparse. This option is ignored when not creating
 173      *   a new file. </td>
 174      * </tr>
 175      * <tr>
 176      *   <td> {@link StandardOpenOption#SYNC SYNC} </td>
 177      *   <td> Requires that every update to the file's content or metadata be
 178      *   written synchronously to the underlying storage device. (see <a
 179      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 180      *   integrity</a>). </td>
 181      * </tr>
 182      * <tr>
 183      *   <td> {@link StandardOpenOption#DSYNC DSYNC} </td>
 184      *   <td> Requires that every update to the file's content be written
 185      *   synchronously to the underlying storage device. (see <a
 186      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 187      *   integrity</a>). </td>
 188      * </tr>

 189      * </table>
 190      *
 191      * <p> An implementation may also support additional options.
 192      *
 193      * <p> The {@code executor} parameter is the {@link ExecutorService} to
 194      * which tasks are submitted to handle I/O events and dispatch completion
 195      * results for operations initiated on resulting channel.
 196      * The nature of these tasks is highly implementation specific and so care
 197      * should be taken when configuring the {@code Executor}. Minimally it
 198      * should support an unbounded work queue and should not run tasks on the
 199      * caller thread of the {@link ExecutorService#execute execute} method.
 200      * Shutting down the executor service while the channel is open results in
 201      * unspecified behavior.
 202      *
 203      * <p> The {@code attrs} parameter is an optional array of file {@link
 204      * FileAttribute file-attributes} to set atomically when creating the file.
 205      *
 206      * <p> The new channel is created by invoking the {@link
 207      * FileSystemProvider#newFileChannel newFileChannel} method on the
 208      * provider that created the {@code Path}.




 116 {
 117     /**
 118      * Initializes a new instance of this class.
 119      */
 120     protected AsynchronousFileChannel() {
 121     }
 122 
 123     /**
 124      * Opens or creates a file for reading and/or writing, returning an
 125      * asynchronous file channel to access the file.
 126      *
 127      * <p> The {@code options} parameter determines how the file is opened.
 128      * The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE
 129      * WRITE} options determines if the file should be opened for reading and/or
 130      * writing. If neither option is contained in the array then an existing file
 131      * is opened for  reading.
 132      *
 133      * <p> In addition to {@code READ} and {@code WRITE}, the following options
 134      * may be present:
 135      *
 136      * <table class="striped">
 137      * <caption style="display:none">additional options</caption>
 138      * <thead>
 139      * <tr> <th>Option</th> <th>Description</th> </tr>
 140      * </thead>
 141      * <tbody>
 142      * <tr>
 143      *   <td> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </td>
 144      *   <td> When opening an existing file, the file is first truncated to a
 145      *   size of 0 bytes. This option is ignored when the file is opened only
 146      *   for reading.</td>
 147      * </tr>
 148      * <tr>
 149      *   <td> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </td>
 150      *   <td> If this option is present then a new file is created, failing if
 151      *   the file already exists. When creating a file the check for the
 152      *   existence of the file and the creation of the file if it does not exist
 153      *   is atomic with respect to other file system operations. This option is
 154      *   ignored when the file is opened only for reading. </td>
 155      * </tr>
 156      * <tr>
 157      *   <td > {@link StandardOpenOption#CREATE CREATE} </td>
 158      *   <td> If this option is present then an existing file is opened if it
 159      *   exists, otherwise a new file is created. When creating a file the check
 160      *   for the existence of the file and the creation of the file if it does
 161      *   not exist is atomic with respect to other file system operations. This


 173      * <tr>
 174      *   <td>{@link StandardOpenOption#SPARSE SPARSE} </td>
 175      *   <td> When creating a new file this option is a <em>hint</em> that the
 176      *   new file will be sparse. This option is ignored when not creating
 177      *   a new file. </td>
 178      * </tr>
 179      * <tr>
 180      *   <td> {@link StandardOpenOption#SYNC SYNC} </td>
 181      *   <td> Requires that every update to the file's content or metadata be
 182      *   written synchronously to the underlying storage device. (see <a
 183      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 184      *   integrity</a>). </td>
 185      * </tr>
 186      * <tr>
 187      *   <td> {@link StandardOpenOption#DSYNC DSYNC} </td>
 188      *   <td> Requires that every update to the file's content be written
 189      *   synchronously to the underlying storage device. (see <a
 190      *   href="../file/package-summary.html#integrity"> Synchronized I/O file
 191      *   integrity</a>). </td>
 192      * </tr>
 193      * </tbody>
 194      * </table>
 195      *
 196      * <p> An implementation may also support additional options.
 197      *
 198      * <p> The {@code executor} parameter is the {@link ExecutorService} to
 199      * which tasks are submitted to handle I/O events and dispatch completion
 200      * results for operations initiated on resulting channel.
 201      * The nature of these tasks is highly implementation specific and so care
 202      * should be taken when configuring the {@code Executor}. Minimally it
 203      * should support an unbounded work queue and should not run tasks on the
 204      * caller thread of the {@link ExecutorService#execute execute} method.
 205      * Shutting down the executor service while the channel is open results in
 206      * unspecified behavior.
 207      *
 208      * <p> The {@code attrs} parameter is an optional array of file {@link
 209      * FileAttribute file-attributes} to set atomically when creating the file.
 210      *
 211      * <p> The new channel is created by invoking the {@link
 212      * FileSystemProvider#newFileChannel newFileChannel} method on the
 213      * provider that created the {@code Path}.


< prev index next >