src/share/classes/java/io/RandomAccessFile.java

Print this page
rev 9260 : JDK-8033911: Simplify instrumentation of FileInputStream and RandomAccessFile
Reviewed-by:


 292     private native void open(String name, int mode)
 293         throws FileNotFoundException;
 294 
 295     // 'Read' primitives
 296 
 297     /**
 298      * Reads a byte of data from this file. The byte is returned as an
 299      * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This
 300      * method blocks if no input is yet available.
 301      * <p>
 302      * Although {@code RandomAccessFile} is not a subclass of
 303      * {@code InputStream}, this method behaves in exactly the same
 304      * way as the {@link InputStream#read()} method of
 305      * {@code InputStream}.
 306      *
 307      * @return     the next byte of data, or {@code -1} if the end of the
 308      *             file has been reached.
 309      * @exception  IOException  if an I/O error occurs. Not thrown if
 310      *                          end-of-file has been reached.
 311      */
 312     public native int read() throws IOException;




 313 
 314     /**
 315      * Reads a sub array as a sequence of bytes.
 316      * @param b the buffer into which the data is read.
 317      * @param off the start offset of the data.
 318      * @param len the number of bytes to read.
 319      * @exception IOException If an I/O error has occurred.
 320      */
 321     private native int readBytes(byte b[], int off, int len) throws IOException;
 322 
 323     /**
 324      * Reads up to {@code len} bytes of data from this file into an
 325      * array of bytes. This method blocks until at least one byte of input
 326      * is available.
 327      * <p>
 328      * Although {@code RandomAccessFile} is not a subclass of
 329      * {@code InputStream}, this method behaves in exactly the
 330      * same way as the {@link InputStream#read(byte[], int, int)} method of
 331      * {@code InputStream}.
 332      *


 440         len = length();
 441         newpos = pos + n;
 442         if (newpos > len) {
 443             newpos = len;
 444         }
 445         seek(newpos);
 446 
 447         /* return the actual number of bytes skipped */
 448         return (int) (newpos - pos);
 449     }
 450 
 451     // 'Write' primitives
 452 
 453     /**
 454      * Writes the specified byte to this file. The write starts at
 455      * the current file pointer.
 456      *
 457      * @param      b   the {@code byte} to be written.
 458      * @exception  IOException  if an I/O error occurs.
 459      */
 460     public native void write(int b) throws IOException;




 461 
 462     /**
 463      * Writes a sub array as a sequence of bytes.
 464      * @param b the data to be written
 465 
 466      * @param off the start offset in the data
 467      * @param len the number of bytes that are written
 468      * @exception IOException If an I/O error has occurred.
 469      */
 470     private native void writeBytes(byte b[], int off, int len) throws IOException;
 471 
 472     /**
 473      * Writes {@code b.length} bytes from the specified byte array
 474      * to this file, starting at the current file pointer.
 475      *
 476      * @param      b   the data.
 477      * @exception  IOException  if an I/O error occurs.
 478      */
 479     public void write(byte b[]) throws IOException {
 480         writeBytes(b, 0, b.length);




 292     private native void open(String name, int mode)
 293         throws FileNotFoundException;
 294 
 295     // 'Read' primitives
 296 
 297     /**
 298      * Reads a byte of data from this file. The byte is returned as an
 299      * integer in the range 0 to 255 ({@code 0x00-0x0ff}). This
 300      * method blocks if no input is yet available.
 301      * <p>
 302      * Although {@code RandomAccessFile} is not a subclass of
 303      * {@code InputStream}, this method behaves in exactly the same
 304      * way as the {@link InputStream#read()} method of
 305      * {@code InputStream}.
 306      *
 307      * @return     the next byte of data, or {@code -1} if the end of the
 308      *             file has been reached.
 309      * @exception  IOException  if an I/O error occurs. Not thrown if
 310      *                          end-of-file has been reached.
 311      */
 312     public int read() throws IOException {
 313         return read0();
 314     }
 315 
 316     private native int read0() throws IOException;
 317 
 318     /**
 319      * Reads a sub array as a sequence of bytes.
 320      * @param b the buffer into which the data is read.
 321      * @param off the start offset of the data.
 322      * @param len the number of bytes to read.
 323      * @exception IOException If an I/O error has occurred.
 324      */
 325     private native int readBytes(byte b[], int off, int len) throws IOException;
 326 
 327     /**
 328      * Reads up to {@code len} bytes of data from this file into an
 329      * array of bytes. This method blocks until at least one byte of input
 330      * is available.
 331      * <p>
 332      * Although {@code RandomAccessFile} is not a subclass of
 333      * {@code InputStream}, this method behaves in exactly the
 334      * same way as the {@link InputStream#read(byte[], int, int)} method of
 335      * {@code InputStream}.
 336      *


 444         len = length();
 445         newpos = pos + n;
 446         if (newpos > len) {
 447             newpos = len;
 448         }
 449         seek(newpos);
 450 
 451         /* return the actual number of bytes skipped */
 452         return (int) (newpos - pos);
 453     }
 454 
 455     // 'Write' primitives
 456 
 457     /**
 458      * Writes the specified byte to this file. The write starts at
 459      * the current file pointer.
 460      *
 461      * @param      b   the {@code byte} to be written.
 462      * @exception  IOException  if an I/O error occurs.
 463      */
 464     public void write(int b) throws IOException {
 465         write0(b);
 466     }
 467 
 468     private native void write0(int b) throws IOException;
 469 
 470     /**
 471      * Writes a sub array as a sequence of bytes.
 472      * @param b the data to be written
 473 
 474      * @param off the start offset in the data
 475      * @param len the number of bytes that are written
 476      * @exception IOException If an I/O error has occurred.
 477      */
 478     private native void writeBytes(byte b[], int off, int len) throws IOException;
 479 
 480     /**
 481      * Writes {@code b.length} bytes from the specified byte array
 482      * to this file, starting at the current file pointer.
 483      *
 484      * @param      b   the data.
 485      * @exception  IOException  if an I/O error occurs.
 486      */
 487     public void write(byte b[]) throws IOException {
 488         writeBytes(b, 0, b.length);