author | michaelm |
Tue, 29 Oct 2019 19:23:09 +0000 | |
branch | unixdomainchannels |
changeset 58847 | 692de65ab293 |
parent 50701 | 80fe6f64d8a0 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
50701
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
package java.nio.channels; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
import java.nio.file.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
import java.nio.file.attribute.FileAttribute; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
import java.nio.file.spi.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import java.nio.ByteBuffer; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
import java.io.IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
import java.util.concurrent.Future; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
import java.util.concurrent.ExecutorService; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import java.util.Set; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
import java.util.HashSet; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
import java.util.Collections; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
* An asynchronous channel for reading, writing, and manipulating a file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
* <p> An asynchronous file channel is created when a file is opened by invoking |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
* one of the {@link #open open} methods defined by this class. The file contains |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
* a variable-length sequence of bytes that can be read and written and whose |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
* current size can be {@link #size() queried}. The size of the file increases |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
* when bytes are written beyond its current size; the size of the file decreases |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
* when it is {@link #truncate truncated}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
* <p> An asynchronous file channel does not have a <i>current position</i> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
* within the file. Instead, the file position is specified to each read and |
8568
f59001e07166
6944810: (ch) Assert failure in sun.nio.ch.PendingIoCache.clearPendingIoMap [win]
alanb
parents:
8539
diff
changeset
|
51 |
* write method that initiates asynchronous operations. A {@link CompletionHandler} |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
52 |
* is specified as a parameter and is invoked to consume the result of the I/O |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
53 |
* operation. This class also defines read and write methods that initiate |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
54 |
* asynchronous operations, returning a {@link Future} to represent the pending |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
55 |
* result of the operation. The {@code Future} may be used to check if the |
8539
eeb9fc5a68c1
7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents:
5506
diff
changeset
|
56 |
* operation has completed, wait for its completion, and retrieve the result. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
* <p> In addition to read and write operations, this class defines the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
* following operations: </p> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
* <ul> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
* <li><p> Updates made to a file may be {@link #force <i>forced |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
* out</i>} to the underlying storage device, ensuring that data are not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
* lost in the event of a system crash. </p></li> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
67 |
* <li><p> A region of a file may be {@link #lock <i>locked</i>} against |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
68 |
* access by other programs. </p></li> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
* </ul> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
* <p> An {@code AsynchronousFileChannel} is associated with a thread pool to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
* which tasks are submitted to handle I/O events and dispatch to completion |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
* handlers that consume the results of I/O operations on the channel. The |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
* completion handler for an I/O operation initiated on a channel is guaranteed |
8568
f59001e07166
6944810: (ch) Assert failure in sun.nio.ch.PendingIoCache.clearPendingIoMap [win]
alanb
parents:
8539
diff
changeset
|
76 |
* to be invoked by one of the threads in the thread pool (This ensures that the |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
* completion handler is run by a thread with the expected <em>identity</em>). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
* Where an I/O operation completes immediately, and the initiating thread is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
* itself a thread in the thread pool, then the completion handler may be invoked |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
* directly by the initiating thread. When an {@code AsynchronousFileChannel} is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
81 |
* created without specifying a thread pool then the channel is associated with |
8539
eeb9fc5a68c1
7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents:
5506
diff
changeset
|
82 |
* a system-dependent default thread pool that may be shared with other |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
* channels. The default thread pool is configured by the system properties |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
* defined by the {@link AsynchronousChannelGroup} class. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
* <p> Channels of this type are safe for use by multiple concurrent threads. The |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
* {@link Channel#close close} method may be invoked at any time, as specified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
* by the {@link Channel} interface. This causes all outstanding asynchronous |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
* operations on the channel to complete with the exception {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
* AsynchronousCloseException}. Multiple read and write operations may be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
* outstanding at the same time. When multiple read and write operations are |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
* outstanding then the ordering of the I/O operations, and the order that the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
* completion handlers are invoked, is not specified; they are not, in particular, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
* guaranteed to execute in the order that the operations were initiated. The |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
* {@link java.nio.ByteBuffer ByteBuffers} used when reading or writing are not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
* safe for use by multiple concurrent I/O operations. Furthermore, after an I/O |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
* operation is initiated then care should be taken to ensure that the buffer is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
* not accessed until after the operation has completed. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
* <p> As with {@link FileChannel}, the view of a file provided by an instance of |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
* this class is guaranteed to be consistent with other views of the same file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
102 |
* provided by other instances in the same program. The view provided by an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
* instance of this class may or may not, however, be consistent with the views |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
* seen by other concurrently-running programs due to caching performed by the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
* underlying operating system and delays induced by network-filesystem protocols. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
* This is true regardless of the language in which these other programs are |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
* written, and whether they are running on the same machine or on some other |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
108 |
* machine. The exact nature of any such inconsistencies are system-dependent |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
* and are therefore unspecified. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
* @since 1.7 |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
public abstract class AsynchronousFileChannel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
implements AsynchronousChannel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
* Initializes a new instance of this class. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
protected AsynchronousFileChannel() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
* Opens or creates a file for reading and/or writing, returning an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
* asynchronous file channel to access the file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
* <p> The {@code options} parameter determines how the file is opened. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
* The {@link StandardOpenOption#READ READ} and {@link StandardOpenOption#WRITE |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
* WRITE} options determines if the file should be opened for reading and/or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
* writing. If neither option is contained in the array then an existing file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
* is opened for reading. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
* <p> In addition to {@code READ} and {@code WRITE}, the following options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
* may be present: |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
* |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
136 |
* <table class="striped"> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
137 |
* <caption style="display:none">additional options</caption> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
138 |
* <thead> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
139 |
* <tr> <th scope="col">Option</th> <th scope="col">Description</th> </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
140 |
* </thead> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
141 |
* <tbody> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
142 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
143 |
* <th scope="row"> {@link StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
144 |
* <td> When opening an existing file, the file is first truncated to a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
* size of 0 bytes. This option is ignored when the file is opened only |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
* for reading.</td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
147 |
* </tr> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
148 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
149 |
* <th scope="row"> {@link StandardOpenOption#CREATE_NEW CREATE_NEW} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
* <td> If this option is present then a new file is created, failing if |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
* the file already exists. When creating a file the check for the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
* existence of the file and the creation of the file if it does not exist |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
153 |
* is atomic with respect to other file system operations. This option is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
* ignored when the file is opened only for reading. </td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
* </tr> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
157 |
* <th scope="row" > {@link StandardOpenOption#CREATE CREATE} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
* <td> If this option is present then an existing file is opened if it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
* exists, otherwise a new file is created. When creating a file the check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
* for the existence of the file and the creation of the file if it does |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
* not exist is atomic with respect to other file system operations. This |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
* option is ignored if the {@code CREATE_NEW} option is also present or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
* the file is opened only for reading. </td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
* </tr> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
166 |
* <th scope="row" > {@link StandardOpenOption#DELETE_ON_CLOSE DELETE_ON_CLOSE} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
* <td> When this option is present then the implementation makes a |
47478 | 168 |
* <em>best effort</em> attempt to delete the file when closed by |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
* the {@link #close close} method. If the {@code close} method is not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
* invoked then a <em>best effort</em> attempt is made to delete the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
171 |
* when the Java virtual machine terminates. </td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
* </tr> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
173 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
174 |
* <th scope="row">{@link StandardOpenOption#SPARSE SPARSE} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
175 |
* <td> When creating a new file this option is a <em>hint</em> that the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
176 |
* new file will be sparse. This option is ignored when not creating |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
177 |
* a new file. </td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
178 |
* </tr> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
179 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
180 |
* <th scope="row"> {@link StandardOpenOption#SYNC SYNC} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
181 |
* <td> Requires that every update to the file's content or metadata be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
182 |
* written synchronously to the underlying storage device. (see <a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
183 |
* href="../file/package-summary.html#integrity"> Synchronized I/O file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
* integrity</a>). </td> |
21801
b8a5ff5f0c2a
8028049: Tidy warnings cleanup for packages java.nio/java.io
yan
parents:
18574
diff
changeset
|
185 |
* </tr> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45124
diff
changeset
|
187 |
* <th scope="row"> {@link StandardOpenOption#DSYNC DSYNC} </th> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
* <td> Requires that every update to the file's content be written |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
* synchronously to the underlying storage device. (see <a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
* href="../file/package-summary.html#integrity"> Synchronized I/O file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
* integrity</a>). </td> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
* </tr> |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
29986
diff
changeset
|
193 |
* </tbody> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
194 |
* </table> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
195 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
196 |
* <p> An implementation may also support additional options. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
197 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
* <p> The {@code executor} parameter is the {@link ExecutorService} to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
199 |
* which tasks are submitted to handle I/O events and dispatch completion |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
200 |
* results for operations initiated on resulting channel. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
201 |
* The nature of these tasks is highly implementation specific and so care |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
202 |
* should be taken when configuring the {@code Executor}. Minimally it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
203 |
* should support an unbounded work queue and should not run tasks on the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
204 |
* caller thread of the {@link ExecutorService#execute execute} method. |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
205 |
* Shutting down the executor service while the channel is open results in |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
206 |
* unspecified behavior. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
207 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
208 |
* <p> The {@code attrs} parameter is an optional array of file {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
209 |
* FileAttribute file-attributes} to set atomically when creating the file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
210 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
211 |
* <p> The new channel is created by invoking the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
212 |
* FileSystemProvider#newFileChannel newFileChannel} method on the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
213 |
* provider that created the {@code Path}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
214 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
215 |
* @param file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
* The path of the file to open or create |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
217 |
* @param options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
218 |
* Options specifying how the file is opened |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
219 |
* @param executor |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
220 |
* The thread pool or {@code null} to associate the channel with |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
221 |
* the default thread pool |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
222 |
* @param attrs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
223 |
* An optional list of file attributes to set atomically when |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
224 |
* creating the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
226 |
* @return A new asynchronous file channel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
227 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
228 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
229 |
* If the set contains an invalid combination of options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
230 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
231 |
* If the {@code file} is associated with a provider that does not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
232 |
* support creating asynchronous file channels, or an unsupported |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
233 |
* open option is specified, or the array contains an attribute that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
234 |
* cannot be set atomically when creating the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
235 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
236 |
* If an I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
237 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
238 |
* If a security manager is installed and it denies an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
239 |
* unspecified permission required by the implementation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
240 |
* In the case of the default provider, the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
241 |
* SecurityManager#checkRead(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
242 |
* read access if the file is opened for reading. The {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
243 |
* SecurityManager#checkWrite(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
244 |
* write access if the file is opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
245 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
246 |
public static AsynchronousFileChannel open(Path file, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
247 |
Set<? extends OpenOption> options, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
248 |
ExecutorService executor, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
249 |
FileAttribute<?>... attrs) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
250 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
251 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
252 |
FileSystemProvider provider = file.getFileSystem().provider(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
253 |
return provider.newAsynchronousFileChannel(file, options, executor, attrs); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
254 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
255 |
|
13795
73850c397272
7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents:
10137
diff
changeset
|
256 |
@SuppressWarnings({"unchecked", "rawtypes"}) // generic array construction |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
257 |
private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0]; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
258 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
259 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
260 |
* Opens or creates a file for reading and/or writing, returning an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
261 |
* asynchronous file channel to access the file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
262 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
263 |
* <p> An invocation of this method behaves in exactly the same way as the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
264 |
* invocation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
265 |
* <pre> |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
266 |
* ch.{@link #open(Path,Set,ExecutorService,FileAttribute[]) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
267 |
* open}(file, opts, null, new FileAttribute<?>[0]); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
268 |
* </pre> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
269 |
* where {@code opts} is a {@code Set} containing the options specified to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
270 |
* this method. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
271 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
272 |
* <p> The resulting channel is associated with default thread pool to which |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
273 |
* tasks are submitted to handle I/O events and dispatch to completion |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
274 |
* handlers that consume the result of asynchronous operations performed on |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
275 |
* the resulting channel. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
276 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
277 |
* @param file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
278 |
* The path of the file to open or create |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
279 |
* @param options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
280 |
* Options specifying how the file is opened |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
281 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
282 |
* @return A new asynchronous file channel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
283 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
284 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
285 |
* If the set contains an invalid combination of options |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
286 |
* @throws UnsupportedOperationException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
287 |
* If the {@code file} is associated with a provider that does not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
288 |
* support creating file channels, or an unsupported open option is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
289 |
* specified |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
290 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
291 |
* If an I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
292 |
* @throws SecurityException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
293 |
* If a security manager is installed and it denies an |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
294 |
* unspecified permission required by the implementation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
295 |
* In the case of the default provider, the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
296 |
* SecurityManager#checkRead(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
297 |
* read access if the file is opened for reading. The {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
298 |
* SecurityManager#checkWrite(String)} method is invoked to check |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
299 |
* write access if the file is opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
300 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
301 |
public static AsynchronousFileChannel open(Path file, OpenOption... options) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
302 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
303 |
{ |
50701
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
304 |
Set<OpenOption> set; |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
305 |
if (options.length == 0) { |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
306 |
set = Collections.emptySet(); |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
307 |
} else { |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
308 |
set = new HashSet<>(); |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
309 |
Collections.addAll(set, options); |
80fe6f64d8a0
8199124: (fs) Reduce allocation for file system methods that are invoked with no open options
bpb
parents:
47478
diff
changeset
|
310 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
311 |
return open(file, set, null, NO_ATTRIBUTES); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
312 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
313 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
314 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
315 |
* Returns the current size of this channel's file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
316 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
317 |
* @return The current size of this channel's file, measured in bytes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
318 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
319 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
320 |
* If this channel is closed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
321 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
322 |
* If some other I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
323 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
324 |
public abstract long size() throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
325 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
326 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
327 |
* Truncates this channel's file to the given size. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
328 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
329 |
* <p> If the given size is less than the file's current size then the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
330 |
* is truncated, discarding any bytes beyond the new end of the file. If |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
331 |
* the given size is greater than or equal to the file's current size then |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
332 |
* the file is not modified. </p> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
333 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
334 |
* @param size |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
335 |
* The new size, a non-negative byte count |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
336 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
337 |
* @return This file channel |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
338 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
339 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
340 |
* If this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
341 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
342 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
343 |
* If this channel is closed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
344 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
345 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
346 |
* If the new size is negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
347 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
348 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
349 |
* If some other I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
350 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
351 |
public abstract AsynchronousFileChannel truncate(long size) throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
352 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
353 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
354 |
* Forces any updates to this channel's file to be written to the storage |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
355 |
* device that contains it. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
356 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
357 |
* <p> If this channel's file resides on a local storage device then when |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
358 |
* this method returns it is guaranteed that all changes made to the file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
359 |
* since this channel was created, or since this method was last invoked, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
360 |
* will have been written to that device. This is useful for ensuring that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
361 |
* critical information is not lost in the event of a system crash. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
362 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
363 |
* <p> If the file does not reside on a local device then no such guarantee |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
364 |
* is made. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
365 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
366 |
* <p> The {@code metaData} parameter can be used to limit the number of |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
367 |
* I/O operations that this method is required to perform. Passing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
368 |
* {@code false} for this parameter indicates that only updates to the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
369 |
* file's content need be written to storage; passing {@code true} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
370 |
* indicates that updates to both the file's content and metadata must be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
371 |
* written, which generally requires at least one more I/O operation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
372 |
* Whether this parameter actually has any effect is dependent upon the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
373 |
* underlying operating system and is therefore unspecified. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
374 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
375 |
* <p> Invoking this method may cause an I/O operation to occur even if the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
376 |
* channel was only opened for reading. Some operating systems, for |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
377 |
* example, maintain a last-access time as part of a file's metadata, and |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
378 |
* this time is updated whenever the file is read. Whether or not this is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
379 |
* actually done is system-dependent and is therefore unspecified. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
380 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
381 |
* <p> This method is only guaranteed to force changes that were made to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
382 |
* this channel's file via the methods defined in this class. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
383 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
384 |
* @param metaData |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
385 |
* If {@code true} then this method is required to force changes |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
386 |
* to both the file's content and metadata to be written to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
387 |
* storage; otherwise, it need only force content changes to be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
388 |
* written |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
389 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
390 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
391 |
* If this channel is closed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
392 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
393 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
394 |
* If some other I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
395 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
396 |
public abstract void force(boolean metaData) throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
397 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
398 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
399 |
* Acquires a lock on the given region of this channel's file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
400 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
401 |
* <p> This method initiates an operation to acquire a lock on the given |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
402 |
* region of this channel's file. The {@code handler} parameter is a |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
403 |
* completion handler that is invoked when the lock is acquired (or the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
404 |
* operation fails). The result passed to the completion handler is the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
405 |
* resulting {@code FileLock}. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
406 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
407 |
* <p> The region specified by the {@code position} and {@code size} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
408 |
* parameters need not be contained within, or even overlap, the actual |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
409 |
* underlying file. Lock regions are fixed in size; if a locked region |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
410 |
* initially contains the end of the file and the file grows beyond the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
411 |
* region then the new portion of the file will not be covered by the lock. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
412 |
* If a file is expected to grow in size and a lock on the entire file is |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
413 |
* required then a region starting at zero, and no smaller than the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
414 |
* expected maximum size of the file, should be locked. The two-argument |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
415 |
* {@link #lock(Object,CompletionHandler)} method simply locks a region |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
416 |
* of size {@link Long#MAX_VALUE}. If a lock that overlaps the requested |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
417 |
* region is already held by this Java virtual machine, or this method has |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
418 |
* been invoked to lock an overlapping region and that operation has not |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
419 |
* completed, then this method throws {@link OverlappingFileLockException}. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
420 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
421 |
* <p> Some operating systems do not support a mechanism to acquire a file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
422 |
* lock in an asynchronous manner. Consequently an implementation may |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
423 |
* acquire the file lock in a background thread or from a task executed by |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
424 |
* a thread in the associated thread pool. If there are many lock operations |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
425 |
* outstanding then it may consume threads in the Java virtual machine for |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
426 |
* indefinite periods. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
427 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
428 |
* <p> Some operating systems do not support shared locks, in which case a |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
429 |
* request for a shared lock is automatically converted into a request for |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
430 |
* an exclusive lock. Whether the newly-acquired lock is shared or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
431 |
* exclusive may be tested by invoking the resulting lock object's {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
432 |
* FileLock#isShared() isShared} method. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
433 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
434 |
* <p> File locks are held on behalf of the entire Java virtual machine. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
435 |
* They are not suitable for controlling access to a file by multiple |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
436 |
* threads within the same virtual machine. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
437 |
* |
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
438 |
* @param <A> |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
439 |
* The type of the attachment |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
440 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
441 |
* The position at which the locked region is to start; must be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
442 |
* non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
443 |
* @param size |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
444 |
* The size of the locked region; must be non-negative, and the sum |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
445 |
* {@code position} + {@code size} must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
446 |
* @param shared |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
447 |
* {@code true} to request a shared lock, in which case this |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
448 |
* channel must be open for reading (and possibly writing); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
449 |
* {@code false} to request an exclusive lock, in which case this |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
450 |
* channel must be open for writing (and possibly reading) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
451 |
* @param attachment |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
452 |
* The object to attach to the I/O operation; can be {@code null} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
453 |
* @param handler |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
454 |
* The handler for consuming the result |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
455 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
456 |
* @throws OverlappingFileLockException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
457 |
* If a lock that overlaps the requested region is already held by |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
458 |
* this Java virtual machine, or there is already a pending attempt |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
459 |
* to lock an overlapping region |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
460 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
461 |
* If the preconditions on the parameters do not hold |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
462 |
* @throws NonReadableChannelException |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
463 |
* If {@code shared} is true but this channel was not opened for reading |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
464 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
465 |
* If {@code shared} is false but this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
466 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
467 |
public abstract <A> void lock(long position, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
468 |
long size, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
469 |
boolean shared, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
470 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
471 |
CompletionHandler<FileLock,? super A> handler); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
472 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
473 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
474 |
* Acquires an exclusive lock on this channel's file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
475 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
476 |
* <p> This method initiates an operation to acquire a lock on the given |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
477 |
* region of this channel's file. The {@code handler} parameter is a |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
478 |
* completion handler that is invoked when the lock is acquired (or the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
479 |
* operation fails). The result passed to the completion handler is the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
480 |
* resulting {@code FileLock}. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
481 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
482 |
* <p> An invocation of this method of the form {@code ch.lock(att,handler)} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
483 |
* behaves in exactly the same way as the invocation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
484 |
* <pre> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
485 |
* ch.{@link #lock(long,long,boolean,Object,CompletionHandler) lock}(0L, Long.MAX_VALUE, false, att, handler) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
486 |
* </pre> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
487 |
* |
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
488 |
* @param <A> |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
489 |
* The type of the attachment |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
490 |
* @param attachment |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
491 |
* The object to attach to the I/O operation; can be {@code null} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
492 |
* @param handler |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
493 |
* The handler for consuming the result |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
494 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
495 |
* @throws OverlappingFileLockException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
496 |
* If a lock is already held by this Java virtual machine, or there |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
497 |
* is already a pending attempt to lock a region |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
498 |
* @throws NonWritableChannelException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
499 |
* If this channel was not opened for writing |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
500 |
*/ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
501 |
public final <A> void lock(A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
502 |
CompletionHandler<FileLock,? super A> handler) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
503 |
{ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
504 |
lock(0L, Long.MAX_VALUE, false, attachment, handler); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
505 |
} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
506 |
|
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
507 |
/** |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
508 |
* Acquires a lock on the given region of this channel's file. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
509 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
510 |
* <p> This method initiates an operation to acquire a lock on the given |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
511 |
* region of this channel's file. The method behaves in exactly the same |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
512 |
* manner as the {@link #lock(long, long, boolean, Object, CompletionHandler)} |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
513 |
* method except that instead of specifying a completion handler, this |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
514 |
* method returns a {@code Future} representing the pending result. The |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
515 |
* {@code Future}'s {@link Future#get() get} method returns the {@link |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
516 |
* FileLock} on successful completion. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
517 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
518 |
* @param position |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
519 |
* The position at which the locked region is to start; must be |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
520 |
* non-negative |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
521 |
* @param size |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
522 |
* The size of the locked region; must be non-negative, and the sum |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
523 |
* {@code position} + {@code size} must be non-negative |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
524 |
* @param shared |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
525 |
* {@code true} to request a shared lock, in which case this |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
526 |
* channel must be open for reading (and possibly writing); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
527 |
* {@code false} to request an exclusive lock, in which case this |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
528 |
* channel must be open for writing (and possibly reading) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
529 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
530 |
* @return a {@code Future} object representing the pending result |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
531 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
532 |
* @throws OverlappingFileLockException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
533 |
* If a lock is already held by this Java virtual machine, or there |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
534 |
* is already a pending attempt to lock a region |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
535 |
* @throws IllegalArgumentException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
536 |
* If the preconditions on the parameters do not hold |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
537 |
* @throws NonReadableChannelException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
538 |
* If {@code shared} is true but this channel was not opened for reading |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
539 |
* @throws NonWritableChannelException |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
540 |
* If {@code shared} is false but this channel was not opened for writing |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
541 |
*/ |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
542 |
public abstract Future<FileLock> lock(long position, long size, boolean shared); |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
543 |
|
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
544 |
/** |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
545 |
* Acquires an exclusive lock on this channel's file. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
546 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
547 |
* <p> This method initiates an operation to acquire an exclusive lock on this |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
548 |
* channel's file. The method returns a {@code Future} representing the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
549 |
* pending result of the operation. The {@code Future}'s {@link Future#get() |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
550 |
* get} method returns the {@link FileLock} on successful completion. |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
551 |
* |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
552 |
* <p> An invocation of this method behaves in exactly the same way as the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
553 |
* invocation |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
554 |
* <pre> |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
555 |
* ch.{@link #lock(long,long,boolean) lock}(0L, Long.MAX_VALUE, false) |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
556 |
* </pre> |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
557 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
558 |
* @return a {@code Future} object representing the pending result |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
559 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
560 |
* @throws OverlappingFileLockException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
561 |
* If a lock is already held by this Java virtual machine, or there |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
562 |
* is already a pending attempt to lock a region |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
563 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
564 |
* If this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
565 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
566 |
public final Future<FileLock> lock() { |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
567 |
return lock(0L, Long.MAX_VALUE, false); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
568 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
569 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
570 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
571 |
* Attempts to acquire a lock on the given region of this channel's file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
572 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
573 |
* <p> This method does not block. An invocation always returns immediately, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
574 |
* either having acquired a lock on the requested region or having failed to |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
575 |
* do so. If it fails to acquire a lock because an overlapping lock is held |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
576 |
* by another program then it returns {@code null}. If it fails to acquire |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
577 |
* a lock for any other reason then an appropriate exception is thrown. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
578 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
579 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
580 |
* The position at which the locked region is to start; must be |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
581 |
* non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
582 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
583 |
* @param size |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
584 |
* The size of the locked region; must be non-negative, and the sum |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
585 |
* {@code position} + {@code size} must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
586 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
587 |
* @param shared |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
588 |
* {@code true} to request a shared lock, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
589 |
* {@code false} to request an exclusive lock |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
590 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
591 |
* @return A lock object representing the newly-acquired lock, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
592 |
* or {@code null} if the lock could not be acquired |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
593 |
* because another program holds an overlapping lock |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
594 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
595 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
596 |
* If the preconditions on the parameters do not hold |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
597 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
598 |
* If this channel is closed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
599 |
* @throws OverlappingFileLockException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
600 |
* If a lock that overlaps the requested region is already held by |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
601 |
* this Java virtual machine, or if another thread is already |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
602 |
* blocked in this method and is attempting to lock an overlapping |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
603 |
* region of the same file |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
604 |
* @throws NonReadableChannelException |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
605 |
* If {@code shared} is true but this channel was not opened for reading |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
606 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
607 |
* If {@code shared} is false but this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
608 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
609 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
610 |
* If some other I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
611 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
612 |
* @see #lock(Object,CompletionHandler) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
613 |
* @see #lock(long,long,boolean,Object,CompletionHandler) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
614 |
* @see #tryLock() |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
615 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
616 |
public abstract FileLock tryLock(long position, long size, boolean shared) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
617 |
throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
618 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
619 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
620 |
* Attempts to acquire an exclusive lock on this channel's file. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
621 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
622 |
* <p> An invocation of this method of the form {@code ch.tryLock()} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
623 |
* behaves in exactly the same way as the invocation |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
624 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
625 |
* <pre> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
626 |
* ch.{@link #tryLock(long,long,boolean) tryLock}(0L, Long.MAX_VALUE, false) </pre> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
627 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
628 |
* @return A lock object representing the newly-acquired lock, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
629 |
* or {@code null} if the lock could not be acquired |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
630 |
* because another program holds an overlapping lock |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
631 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
632 |
* @throws ClosedChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
633 |
* If this channel is closed |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
634 |
* @throws OverlappingFileLockException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
635 |
* If a lock that overlaps the requested region is already held by |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
636 |
* this Java virtual machine, or if another thread is already |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
637 |
* blocked in this method and is attempting to lock an overlapping |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
638 |
* region |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
639 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
640 |
* If {@code shared} is false but this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
641 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
642 |
* @throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
643 |
* If some other I/O error occurs |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
644 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
645 |
* @see #lock(Object,CompletionHandler) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
646 |
* @see #lock(long,long,boolean,Object,CompletionHandler) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
647 |
* @see #tryLock(long,long,boolean) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
648 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
649 |
public final FileLock tryLock() throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
650 |
return tryLock(0L, Long.MAX_VALUE, false); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
651 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
652 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
653 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
654 |
* Reads a sequence of bytes from this channel into the given buffer, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
655 |
* starting at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
656 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
657 |
* <p> This method initiates the reading of a sequence of bytes from this |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
658 |
* channel into the given buffer, starting at the given file position. The |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
659 |
* result of the read is the number of bytes read or {@code -1} if the given |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
660 |
* position is greater than or equal to the file's size at the time that the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
661 |
* read is attempted. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
662 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
663 |
* <p> This method works in the same manner as the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
664 |
* AsynchronousByteChannel#read(ByteBuffer,Object,CompletionHandler)} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
665 |
* method, except that bytes are read starting at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
666 |
* If the given file position is greater than the file's size at the time |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
667 |
* that the read is attempted then no bytes are read. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
668 |
* |
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
669 |
* @param <A> |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
670 |
* The type of the attachment |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
671 |
* @param dst |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
672 |
* The buffer into which bytes are to be transferred |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
673 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
674 |
* The file position at which the transfer is to begin; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
675 |
* must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
676 |
* @param attachment |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
677 |
* The object to attach to the I/O operation; can be {@code null} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
678 |
* @param handler |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
679 |
* The handler for consuming the result |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
680 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
681 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
682 |
* If the position is negative or the buffer is read-only |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
683 |
* @throws NonReadableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
684 |
* If this channel was not opened for reading |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
685 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
686 |
public abstract <A> void read(ByteBuffer dst, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
687 |
long position, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
688 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
689 |
CompletionHandler<Integer,? super A> handler); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
690 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
691 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
692 |
* Reads a sequence of bytes from this channel into the given buffer, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
693 |
* starting at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
694 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
695 |
* <p> This method initiates the reading of a sequence of bytes from this |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
696 |
* channel into the given buffer, starting at the given file position. This |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
697 |
* method returns a {@code Future} representing the pending result of the |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
698 |
* operation. The {@code Future}'s {@link Future#get() get} method returns |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
699 |
* the number of bytes read or {@code -1} if the given position is greater |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
700 |
* than or equal to the file's size at the time that the read is attempted. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
701 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
702 |
* <p> This method works in the same manner as the {@link |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
703 |
* AsynchronousByteChannel#read(ByteBuffer)} method, except that bytes are |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
704 |
* read starting at the given file position. If the given file position is |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
705 |
* greater than the file's size at the time that the read is attempted then |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
706 |
* no bytes are read. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
707 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
708 |
* @param dst |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
709 |
* The buffer into which bytes are to be transferred |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
710 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
711 |
* The file position at which the transfer is to begin; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
712 |
* must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
713 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
714 |
* @return A {@code Future} object representing the pending result |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
715 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
716 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
717 |
* If the position is negative or the buffer is read-only |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
718 |
* @throws NonReadableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
719 |
* If this channel was not opened for reading |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
720 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
721 |
public abstract Future<Integer> read(ByteBuffer dst, long position); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
722 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
723 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
724 |
* Writes a sequence of bytes to this channel from the given buffer, starting |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
725 |
* at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
726 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
727 |
* <p> This method works in the same manner as the {@link |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
728 |
* AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler)} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
729 |
* method, except that bytes are written starting at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
730 |
* If the given position is greater than the file's size, at the time that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
731 |
* the write is attempted, then the file will be grown to accommodate the new |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
732 |
* bytes; the values of any bytes between the previous end-of-file and the |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
733 |
* newly-written bytes are unspecified. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
734 |
* |
18574
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
735 |
* @param <A> |
4aeaeb541678
8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents:
14342
diff
changeset
|
736 |
* The type of the attachment |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
737 |
* @param src |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
738 |
* The buffer from which bytes are to be transferred |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
739 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
740 |
* The file position at which the transfer is to begin; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
741 |
* must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
742 |
* @param attachment |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
743 |
* The object to attach to the I/O operation; can be {@code null} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
744 |
* @param handler |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
745 |
* The handler for consuming the result |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
746 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
747 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
748 |
* If the position is negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
749 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
750 |
* If this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
751 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
752 |
public abstract <A> void write(ByteBuffer src, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
753 |
long position, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
754 |
A attachment, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
755 |
CompletionHandler<Integer,? super A> handler); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
756 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
757 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
758 |
* Writes a sequence of bytes to this channel from the given buffer, starting |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
759 |
* at the given file position. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
760 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
761 |
* <p> This method initiates the writing of a sequence of bytes to this |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
762 |
* channel from the given buffer, starting at the given file position. The |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
763 |
* method returns a {@code Future} representing the pending result of the |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
764 |
* write operation. The {@code Future}'s {@link Future#get() get} method |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
765 |
* returns the number of bytes written. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
766 |
* |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
767 |
* <p> This method works in the same manner as the {@link |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
768 |
* AsynchronousByteChannel#write(ByteBuffer)} method, except that bytes are |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
769 |
* written starting at the given file position. If the given position is |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
770 |
* greater than the file's size, at the time that the write is attempted, |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
771 |
* then the file will be grown to accommodate the new bytes; the values of |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
772 |
* any bytes between the previous end-of-file and the newly-written bytes |
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
773 |
* are unspecified. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
774 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
775 |
* @param src |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
776 |
* The buffer from which bytes are to be transferred |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
777 |
* @param position |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
778 |
* The file position at which the transfer is to begin; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
779 |
* must be non-negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
780 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
781 |
* @return A {@code Future} object representing the pending result |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
782 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
783 |
* @throws IllegalArgumentException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
784 |
* If the position is negative |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
785 |
* @throws NonWritableChannelException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
786 |
* If this channel was not opened for writing |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
787 |
*/ |
3632
399359a027de
6842687: New I/O: Update Asynchronous I/O API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
788 |
public abstract Future<Integer> write(ByteBuffer src, long position); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
789 |
} |