279 public final FileChannel getChannel() {
280 synchronized (this) {
281 if (channel == null) {
282 channel = FileChannelImpl.open(fd, path, true, rw, this);
283 }
284 return channel;
285 }
286 }
287
288 /**
289 * Opens a file and returns the file descriptor. The file is
290 * opened in read-write mode if the O_RDWR bit in {@code mode}
291 * is true, else the file is opened as read-only.
292 * If the {@code name} refers to a directory, an IOException
293 * is thrown.
294 *
295 * @param name the name of the file
296 * @param mode the mode flags, a combination of the O_ constants
297 * defined above
298 */
299 private native void open(String name, int mode)
300 throws FileNotFoundException;
301
302 // 'Read' primitives
303
304 /**
305 * Reads a byte of data from this file. The byte is returned as an
306 * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This
307 * method blocks if no input is yet available.
308 * <p>
309 * Although {@code RandomAccessFile} is not a subclass of
310 * {@code InputStream}, this method behaves in exactly the same
311 * way as the {@link InputStream#read()} method of
312 * {@code InputStream}.
313 *
314 * @return the next byte of data, or {@code -1} if the end of the
315 * file has been reached.
316 * @exception IOException if an I/O error occurs. Not thrown if
317 * end-of-file has been reached.
318 */
319 public int read() throws IOException {
|
279 public final FileChannel getChannel() {
280 synchronized (this) {
281 if (channel == null) {
282 channel = FileChannelImpl.open(fd, path, true, rw, this);
283 }
284 return channel;
285 }
286 }
287
288 /**
289 * Opens a file and returns the file descriptor. The file is
290 * opened in read-write mode if the O_RDWR bit in {@code mode}
291 * is true, else the file is opened as read-only.
292 * If the {@code name} refers to a directory, an IOException
293 * is thrown.
294 *
295 * @param name the name of the file
296 * @param mode the mode flags, a combination of the O_ constants
297 * defined above
298 */
299 private void open(String name, int mode) throws FileNotFoundException {
300 open0(name, mode);
301 }
302
303 /**
304 * Opens a file and returns the file descriptor. The file is
305 * opened in read-write mode if the O_RDWR bit in {@code mode}
306 * is true, else the file is opened as read-only.
307 * If the {@code name} refers to a directory, an IOException
308 * is thrown.
309 *
310 * @param name the name of the file
311 * @param mode the mode flags, a combination of the O_ constants
312 * defined above
313 */
314 private native void open0(String name, int mode)
315 throws FileNotFoundException;
316
317 // 'Read' primitives
318
319 /**
320 * Reads a byte of data from this file. The byte is returned as an
321 * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This
322 * method blocks if no input is yet available.
323 * <p>
324 * Although {@code RandomAccessFile} is not a subclass of
325 * {@code InputStream}, this method behaves in exactly the same
326 * way as the {@link InputStream#read()} method of
327 * {@code InputStream}.
328 *
329 * @return the next byte of data, or {@code -1} if the end of the
330 * file has been reached.
331 * @exception IOException if an I/O error occurs. Not thrown if
332 * end-of-file has been reached.
333 */
334 public int read() throws IOException {
|