< prev index next >

src/java.base/share/classes/java/io/FileInputStream.java

Print this page




 223      * Reads a byte of data from this input stream. This method blocks
 224      * if no input is yet available.
 225      *
 226      * @return     the next byte of data, or <code>-1</code> if the end of the
 227      *             file is reached.
 228      * @exception  IOException  if an I/O error occurs.
 229      */
 230     public int read() throws IOException {
 231         return read0();
 232     }
 233 
 234     private native int read0() throws IOException;
 235 
 236     /**
 237      * Reads a subarray as a sequence of bytes.
 238      * @param b the data to be written
 239      * @param off the start offset in the data
 240      * @param len the number of bytes that are written
 241      * @exception IOException If an I/O error has occurred.
 242      */
 243     private native int readBytes(byte b[], int off, int len) throws IOException;
 244 
 245     /**
 246      * Reads up to <code>b.length</code> bytes of data from this input
 247      * stream into an array of bytes. This method blocks until some input
 248      * is available.
 249      *
 250      * @param      b   the buffer into which the data is read.
 251      * @return     the total number of bytes read into the buffer, or
 252      *             <code>-1</code> if there is no more data because the end of
 253      *             the file has been reached.
 254      * @exception  IOException  if an I/O error occurs.
 255      */
 256     public int read(byte b[]) throws IOException {
 257         return readBytes(b, 0, b.length);
 258     }
 259 
 260     /**
 261      * Reads up to <code>len</code> bytes of data from this input stream
 262      * into an array of bytes. If <code>len</code> is not zero, the method
 263      * blocks until some input is available; otherwise, no
 264      * bytes are read and <code>0</code> is returned.
 265      *
 266      * @param      b     the buffer into which the data is read.
 267      * @param      off   the start offset in the destination array <code>b</code>
 268      * @param      len   the maximum number of bytes read.
 269      * @return     the total number of bytes read into the buffer, or
 270      *             <code>-1</code> if there is no more data because the end of
 271      *             the file has been reached.
 272      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 273      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 274      * <code>len</code> is negative, or <code>len</code> is greater than
 275      * <code>b.length - off</code>
 276      * @exception  IOException  if an I/O error occurs.
 277      */
 278     public int read(byte b[], int off, int len) throws IOException {
 279         return readBytes(b, off, len);
 280     }
 281 
 282     /**
 283      * Skips over and discards <code>n</code> bytes of data from the
 284      * input stream.
 285      *
 286      * <p>The <code>skip</code> method may, for a variety of
 287      * reasons, end up skipping over some smaller number of bytes,
 288      * possibly <code>0</code>. If <code>n</code> is negative, the method
 289      * will try to skip backwards. In case the backing file does not support
 290      * backward skip at its current position, an <code>IOException</code> is
 291      * thrown. The actual number of bytes skipped is returned. If it skips
 292      * forwards, it returns a positive value. If it skips backwards, it
 293      * returns a negative value.
 294      *
 295      * <p>This method may skip more bytes than what are remaining in the
 296      * backing file. This produces no exception and the number of bytes skipped
 297      * may include some number of bytes that were beyond the EOF of the
 298      * backing file. Attempting to read from the stream after skipping past




 223      * Reads a byte of data from this input stream. This method blocks
 224      * if no input is yet available.
 225      *
 226      * @return     the next byte of data, or <code>-1</code> if the end of the
 227      *             file is reached.
 228      * @exception  IOException  if an I/O error occurs.
 229      */
 230     public int read() throws IOException {
 231         return read0();
 232     }
 233 
 234     private native int read0() throws IOException;
 235 
 236     /**
 237      * Reads a subarray as a sequence of bytes.
 238      * @param b the data to be written
 239      * @param off the start offset in the data
 240      * @param len the number of bytes that are written
 241      * @exception IOException If an I/O error has occurred.
 242      */
 243     private native int readBytes(byte[] b, int off, int len) throws IOException;
 244 
 245     /**
 246      * Reads up to <code>b.length</code> bytes of data from this input
 247      * stream into an array of bytes. This method blocks until some input
 248      * is available.
 249      *
 250      * @param      b   the buffer into which the data is read.
 251      * @return     the total number of bytes read into the buffer, or
 252      *             <code>-1</code> if there is no more data because the end of
 253      *             the file has been reached.
 254      * @exception  IOException  if an I/O error occurs.
 255      */
 256     public int read(byte[] b) throws IOException {
 257         return readBytes(b, 0, b.length);
 258     }
 259 
 260     /**
 261      * Reads up to <code>len</code> bytes of data from this input stream
 262      * into an array of bytes. If <code>len</code> is not zero, the method
 263      * blocks until some input is available; otherwise, no
 264      * bytes are read and <code>0</code> is returned.
 265      *
 266      * @param      b     the buffer into which the data is read.
 267      * @param      off   the start offset in the destination array <code>b</code>
 268      * @param      len   the maximum number of bytes read.
 269      * @return     the total number of bytes read into the buffer, or
 270      *             <code>-1</code> if there is no more data because the end of
 271      *             the file has been reached.
 272      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 273      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 274      * <code>len</code> is negative, or <code>len</code> is greater than
 275      * <code>b.length - off</code>
 276      * @exception  IOException  if an I/O error occurs.
 277      */
 278     public int read(byte[] b, int off, int len) throws IOException {
 279         return readBytes(b, off, len);
 280     }
 281 
 282     /**
 283      * Skips over and discards <code>n</code> bytes of data from the
 284      * input stream.
 285      *
 286      * <p>The <code>skip</code> method may, for a variety of
 287      * reasons, end up skipping over some smaller number of bytes,
 288      * possibly <code>0</code>. If <code>n</code> is negative, the method
 289      * will try to skip backwards. In case the backing file does not support
 290      * backward skip at its current position, an <code>IOException</code> is
 291      * thrown. The actual number of bytes skipped is returned. If it skips
 292      * forwards, it returns a positive value. If it skips backwards, it
 293      * returns a negative value.
 294      *
 295      * <p>This method may skip more bytes than what are remaining in the
 296      * backing file. This produces no exception and the number of bytes skipped
 297      * may include some number of bytes that were beyond the EOF of the
 298      * backing file. Attempting to read from the stream after skipping past


< prev index next >