< prev index next >

src/java.base/unix/classes/sun/nio/fs/UnixChannelFactory.java

Print this page

114         throws UnixException
115     {
116         Flags flags = Flags.toFlags(options);
117 
118         // default is reading; append => writing
119         if (!flags.read && !flags.write) {
120             if (flags.append) {
121                 flags.write = true;
122             } else {
123                 flags.read = true;
124             }
125         }
126 
127         // validation
128         if (flags.read && flags.append)
129             throw new IllegalArgumentException("READ + APPEND not allowed");
130         if (flags.append && flags.truncateExisting)
131             throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
132 
133         FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
134         return FileChannelImpl.open(fdObj, path.toString(), flags.read,
135                 flags.write, flags.direct, null);
136     }
137 
138     /**
139      * Constructs a file channel by opening the given file.
140      */
141     static FileChannel newFileChannel(UnixPath path,
142                                       Set<? extends OpenOption> options,
143                                       int mode)
144         throws UnixException
145     {
146         return newFileChannel(-1, path, null, options, mode);
147     }
148 
149     /**
150      * Constructs an asynchronous file channel by opening the given file.
151      */
152     static AsynchronousFileChannel newAsynchronousFileChannel(UnixPath path,
153                                                               Set<? extends OpenOption> options,
154                                                               int mode,
155                                                               ThreadPool pool)

114         throws UnixException
115     {
116         Flags flags = Flags.toFlags(options);
117 
118         // default is reading; append => writing
119         if (!flags.read && !flags.write) {
120             if (flags.append) {
121                 flags.write = true;
122             } else {
123                 flags.read = true;
124             }
125         }
126 
127         // validation
128         if (flags.read && flags.append)
129             throw new IllegalArgumentException("READ + APPEND not allowed");
130         if (flags.append && flags.truncateExisting)
131             throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed");
132 
133         FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode);
134         return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write,
135                 (flags.sync || flags.dsync), flags.direct, null);
136     }
137 
138     /**
139      * Constructs a file channel by opening the given file.
140      */
141     static FileChannel newFileChannel(UnixPath path,
142                                       Set<? extends OpenOption> options,
143                                       int mode)
144         throws UnixException
145     {
146         return newFileChannel(-1, path, null, options, mode);
147     }
148 
149     /**
150      * Constructs an asynchronous file channel by opening the given file.
151      */
152     static AsynchronousFileChannel newAsynchronousFileChannel(UnixPath path,
153                                                               Set<? extends OpenOption> options,
154                                                               int mode,
155                                                               ThreadPool pool)
< prev index next >