< prev index next >

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

Print this page
rev 56290 : 8230648: Replace @exception tag with @throws in java.base
Summary: Minor coding style update of javadoc tag in any file in java.base
Reviewed-by: prappo, lancea


 160 
 161             @Override
 162             public void close() throws IOException {
 163                 closed = true;
 164             }
 165         };
 166     }
 167 
 168     /**
 169      * Reads the next byte of data from the input stream. The value byte is
 170      * returned as an <code>int</code> in the range <code>0</code> to
 171      * <code>255</code>. If no byte is available because the end of the stream
 172      * has been reached, the value <code>-1</code> is returned. This method
 173      * blocks until input data is available, the end of the stream is detected,
 174      * or an exception is thrown.
 175      *
 176      * <p> A subclass must provide an implementation of this method.
 177      *
 178      * @return     the next byte of data, or <code>-1</code> if the end of the
 179      *             stream is reached.
 180      * @exception  IOException  if an I/O error occurs.
 181      */
 182     public abstract int read() throws IOException;
 183 
 184     /**
 185      * Reads some number of bytes from the input stream and stores them into
 186      * the buffer array <code>b</code>. The number of bytes actually read is
 187      * returned as an integer.  This method blocks until input data is
 188      * available, end of file is detected, or an exception is thrown.
 189      *
 190      * <p> If the length of <code>b</code> is zero, then no bytes are read and
 191      * <code>0</code> is returned; otherwise, there is an attempt to read at
 192      * least one byte. If no byte is available because the stream is at the
 193      * end of the file, the value <code>-1</code> is returned; otherwise, at
 194      * least one byte is read and stored into <code>b</code>.
 195      *
 196      * <p> The first byte read is stored into element <code>b[0]</code>, the
 197      * next one into <code>b[1]</code>, and so on. The number of bytes read is,
 198      * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
 199      * number of bytes actually read; these bytes will be stored in elements
 200      * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
 201      * leaving elements <code>b[</code><i>k</i><code>]</code> through
 202      * <code>b[b.length-1]</code> unaffected.
 203      *
 204      * <p> The <code>read(b)</code> method for class <code>InputStream</code>
 205      * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
 206      *
 207      * @param      b   the buffer into which the data is read.
 208      * @return     the total number of bytes read into the buffer, or
 209      *             <code>-1</code> if there is no more data because the end of
 210      *             the stream has been reached.
 211      * @exception  IOException  If the first byte cannot be read for any reason
 212      * other than the end of the file, if the input stream has been closed, or
 213      * if some other I/O error occurs.
 214      * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
 215      * @see        java.io.InputStream#read(byte[], int, int)
 216      */
 217     public int read(byte b[]) throws IOException {
 218         return read(b, 0, b.length);
 219     }
 220 
 221     /**
 222      * Reads up to <code>len</code> bytes of data from the input stream into
 223      * an array of bytes.  An attempt is made to read as many as
 224      * <code>len</code> bytes, but a smaller number may be read.
 225      * The number of bytes actually read is returned as an integer.
 226      *
 227      * <p> This method blocks until input data is available, end of file is
 228      * detected, or an exception is thrown.
 229      *
 230      * <p> If <code>len</code> is zero, then no bytes are read and
 231      * <code>0</code> is returned; otherwise, there is an attempt to read at
 232      * least one byte. If no byte is available because the stream is at end of
 233      * file, the value <code>-1</code> is returned; otherwise, at least one
 234      * byte is read and stored into <code>b</code>.


 249      * for class <code>InputStream</code> simply calls the method
 250      * <code>read()</code> repeatedly. If the first such call results in an
 251      * <code>IOException</code>, that exception is returned from the call to
 252      * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
 253      * any subsequent call to <code>read()</code> results in a
 254      * <code>IOException</code>, the exception is caught and treated as if it
 255      * were end of file; the bytes read up to that point are stored into
 256      * <code>b</code> and the number of bytes read before the exception
 257      * occurred is returned. The default implementation of this method blocks
 258      * until the requested amount of input data <code>len</code> has been read,
 259      * end of file is detected, or an exception is thrown. Subclasses are
 260      * encouraged to provide a more efficient implementation of this method.
 261      *
 262      * @param      b     the buffer into which the data is read.
 263      * @param      off   the start offset in array <code>b</code>
 264      *                   at which the data is written.
 265      * @param      len   the maximum number of bytes to read.
 266      * @return     the total number of bytes read into the buffer, or
 267      *             <code>-1</code> if there is no more data because the end of
 268      *             the stream has been reached.
 269      * @exception  IOException If the first byte cannot be read for any reason
 270      * other than end of file, or if the input stream has been closed, or if
 271      * some other I/O error occurs.
 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      * @see        java.io.InputStream#read()
 277      */
 278     public int read(byte b[], int off, int len) throws IOException {
 279         Objects.checkFromIndexSize(off, len, b.length);
 280         if (len == 0) {
 281             return 0;
 282         }
 283 
 284         int c = read();
 285         if (c == -1) {
 286             return -1;
 287         }
 288         b[off] = (byte)c;
 289 
 290         int i = 1;
 291         try {
 292             for (; i < len ; i++) {
 293                 c = read();


 617      * another thread.  A single read or skip of this many bytes will not block,
 618      * but may read or skip fewer bytes.
 619      *
 620      * <p> Note that while some implementations of {@code InputStream} will
 621      * return the total number of bytes in the stream, many will not.  It is
 622      * never correct to use the return value of this method to allocate
 623      * a buffer intended to hold all data in this stream.
 624      *
 625      * <p> A subclass's implementation of this method may choose to throw an
 626      * {@link IOException} if this input stream has been closed by invoking the
 627      * {@link #close()} method.
 628      *
 629      * <p> The {@code available} method of {@code InputStream} always returns
 630      * {@code 0}.
 631      *
 632      * <p> This method should be overridden by subclasses.
 633      *
 634      * @return     an estimate of the number of bytes that can be read (or
 635      *             skipped over) from this input stream without blocking or
 636      *             {@code 0} when it reaches the end of the input stream.
 637      * @exception  IOException if an I/O error occurs.
 638      */
 639     public int available() throws IOException {
 640         return 0;
 641     }
 642 
 643     /**
 644      * Closes this input stream and releases any system resources associated
 645      * with the stream.
 646      *
 647      * <p> The <code>close</code> method of <code>InputStream</code> does
 648      * nothing.
 649      *
 650      * @exception  IOException  if an I/O error occurs.
 651      */
 652     public void close() throws IOException {}
 653 
 654     /**
 655      * Marks the current position in this input stream. A subsequent call to
 656      * the <code>reset</code> method repositions this stream at the last marked
 657      * position so that subsequent reads re-read the same bytes.
 658      *
 659      * <p> The <code>readlimit</code> arguments tells this input stream to
 660      * allow that many bytes to be read before the mark position gets
 661      * invalidated.
 662      *
 663      * <p> The general contract of <code>mark</code> is that, if the method
 664      * <code>markSupported</code> returns <code>true</code>, the stream somehow
 665      * remembers all the bytes read after the call to <code>mark</code> and
 666      * stands ready to supply those same bytes again if and whenever the method
 667      * <code>reset</code> is called.  However, the stream is not required to
 668      * remember any data at all if more than <code>readlimit</code> bytes are
 669      * read from the stream before <code>reset</code> is called.
 670      *


 701      *     file, if <code>mark</code> has not been called) will be resupplied
 702      *     to subsequent callers of the <code>read</code> method, followed by
 703      *     any bytes that otherwise would have been the next input data as of
 704      *     the time of the call to <code>reset</code>. </ul>
 705      *
 706      * <li> If the method <code>markSupported</code> returns
 707      * <code>false</code>, then:
 708      *
 709      *     <ul><li> The call to <code>reset</code> may throw an
 710      *     <code>IOException</code>.
 711      *
 712      *     <li> If an <code>IOException</code> is not thrown, then the stream
 713      *     is reset to a fixed state that depends on the particular type of the
 714      *     input stream and how it was created. The bytes that will be supplied
 715      *     to subsequent callers of the <code>read</code> method depend on the
 716      *     particular type of the input stream. </ul></ul>
 717      *
 718      * <p>The method <code>reset</code> for class <code>InputStream</code>
 719      * does nothing except throw an <code>IOException</code>.
 720      *
 721      * @exception  IOException  if this stream has not been marked or if the
 722      *               mark has been invalidated.
 723      * @see     java.io.InputStream#mark(int)
 724      * @see     java.io.IOException
 725      */
 726     public synchronized void reset() throws IOException {
 727         throw new IOException("mark/reset not supported");
 728     }
 729 
 730     /**
 731      * Tests if this input stream supports the <code>mark</code> and
 732      * <code>reset</code> methods. Whether or not <code>mark</code> and
 733      * <code>reset</code> are supported is an invariant property of a
 734      * particular input stream instance. The <code>markSupported</code> method
 735      * of <code>InputStream</code> returns <code>false</code>.
 736      *
 737      * @return  <code>true</code> if this stream instance supports the mark
 738      *          and reset methods; <code>false</code> otherwise.
 739      * @see     java.io.InputStream#mark(int)
 740      * @see     java.io.InputStream#reset()
 741      */




 160 
 161             @Override
 162             public void close() throws IOException {
 163                 closed = true;
 164             }
 165         };
 166     }
 167 
 168     /**
 169      * Reads the next byte of data from the input stream. The value byte is
 170      * returned as an <code>int</code> in the range <code>0</code> to
 171      * <code>255</code>. If no byte is available because the end of the stream
 172      * has been reached, the value <code>-1</code> is returned. This method
 173      * blocks until input data is available, the end of the stream is detected,
 174      * or an exception is thrown.
 175      *
 176      * <p> A subclass must provide an implementation of this method.
 177      *
 178      * @return     the next byte of data, or <code>-1</code> if the end of the
 179      *             stream is reached.
 180      * @throws     IOException  if an I/O error occurs.
 181      */
 182     public abstract int read() throws IOException;
 183 
 184     /**
 185      * Reads some number of bytes from the input stream and stores them into
 186      * the buffer array <code>b</code>. The number of bytes actually read is
 187      * returned as an integer.  This method blocks until input data is
 188      * available, end of file is detected, or an exception is thrown.
 189      *
 190      * <p> If the length of <code>b</code> is zero, then no bytes are read and
 191      * <code>0</code> is returned; otherwise, there is an attempt to read at
 192      * least one byte. If no byte is available because the stream is at the
 193      * end of the file, the value <code>-1</code> is returned; otherwise, at
 194      * least one byte is read and stored into <code>b</code>.
 195      *
 196      * <p> The first byte read is stored into element <code>b[0]</code>, the
 197      * next one into <code>b[1]</code>, and so on. The number of bytes read is,
 198      * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
 199      * number of bytes actually read; these bytes will be stored in elements
 200      * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
 201      * leaving elements <code>b[</code><i>k</i><code>]</code> through
 202      * <code>b[b.length-1]</code> unaffected.
 203      *
 204      * <p> The <code>read(b)</code> method for class <code>InputStream</code>
 205      * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
 206      *
 207      * @param      b   the buffer into which the data is read.
 208      * @return     the total number of bytes read into the buffer, or
 209      *             <code>-1</code> if there is no more data because the end of
 210      *             the stream has been reached.
 211      * @throws     IOException  If the first byte cannot be read for any reason
 212      *             other than the end of the file, if the input stream has been
 213      *             closed, or if some other I/O error occurs.
 214      * @throws     NullPointerException  if <code>b</code> is <code>null</code>.
 215      * @see        java.io.InputStream#read(byte[], int, int)
 216      */
 217     public int read(byte b[]) throws IOException {
 218         return read(b, 0, b.length);
 219     }
 220 
 221     /**
 222      * Reads up to <code>len</code> bytes of data from the input stream into
 223      * an array of bytes.  An attempt is made to read as many as
 224      * <code>len</code> bytes, but a smaller number may be read.
 225      * The number of bytes actually read is returned as an integer.
 226      *
 227      * <p> This method blocks until input data is available, end of file is
 228      * detected, or an exception is thrown.
 229      *
 230      * <p> If <code>len</code> is zero, then no bytes are read and
 231      * <code>0</code> is returned; otherwise, there is an attempt to read at
 232      * least one byte. If no byte is available because the stream is at end of
 233      * file, the value <code>-1</code> is returned; otherwise, at least one
 234      * byte is read and stored into <code>b</code>.


 249      * for class <code>InputStream</code> simply calls the method
 250      * <code>read()</code> repeatedly. If the first such call results in an
 251      * <code>IOException</code>, that exception is returned from the call to
 252      * the <code>read(b,</code> <code>off,</code> <code>len)</code> method.  If
 253      * any subsequent call to <code>read()</code> results in a
 254      * <code>IOException</code>, the exception is caught and treated as if it
 255      * were end of file; the bytes read up to that point are stored into
 256      * <code>b</code> and the number of bytes read before the exception
 257      * occurred is returned. The default implementation of this method blocks
 258      * until the requested amount of input data <code>len</code> has been read,
 259      * end of file is detected, or an exception is thrown. Subclasses are
 260      * encouraged to provide a more efficient implementation of this method.
 261      *
 262      * @param      b     the buffer into which the data is read.
 263      * @param      off   the start offset in array <code>b</code>
 264      *                   at which the data is written.
 265      * @param      len   the maximum number of bytes to read.
 266      * @return     the total number of bytes read into the buffer, or
 267      *             <code>-1</code> if there is no more data because the end of
 268      *             the stream has been reached.
 269      * @throws     IOException If the first byte cannot be read for any reason
 270      *             other than end of file, or if the input stream has been closed,
 271      *             or if some other I/O error occurs.
 272      * @throws     NullPointerException If <code>b</code> is <code>null</code>.
 273      * @throws     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      * @see        java.io.InputStream#read()
 277      */
 278     public int read(byte b[], int off, int len) throws IOException {
 279         Objects.checkFromIndexSize(off, len, b.length);
 280         if (len == 0) {
 281             return 0;
 282         }
 283 
 284         int c = read();
 285         if (c == -1) {
 286             return -1;
 287         }
 288         b[off] = (byte)c;
 289 
 290         int i = 1;
 291         try {
 292             for (; i < len ; i++) {
 293                 c = read();


 617      * another thread.  A single read or skip of this many bytes will not block,
 618      * but may read or skip fewer bytes.
 619      *
 620      * <p> Note that while some implementations of {@code InputStream} will
 621      * return the total number of bytes in the stream, many will not.  It is
 622      * never correct to use the return value of this method to allocate
 623      * a buffer intended to hold all data in this stream.
 624      *
 625      * <p> A subclass's implementation of this method may choose to throw an
 626      * {@link IOException} if this input stream has been closed by invoking the
 627      * {@link #close()} method.
 628      *
 629      * <p> The {@code available} method of {@code InputStream} always returns
 630      * {@code 0}.
 631      *
 632      * <p> This method should be overridden by subclasses.
 633      *
 634      * @return     an estimate of the number of bytes that can be read (or
 635      *             skipped over) from this input stream without blocking or
 636      *             {@code 0} when it reaches the end of the input stream.
 637      * @throws     IOException if an I/O error occurs.
 638      */
 639     public int available() throws IOException {
 640         return 0;
 641     }
 642 
 643     /**
 644      * Closes this input stream and releases any system resources associated
 645      * with the stream.
 646      *
 647      * <p> The <code>close</code> method of <code>InputStream</code> does
 648      * nothing.
 649      *
 650      * @throws     IOException  if an I/O error occurs.
 651      */
 652     public void close() throws IOException {}
 653 
 654     /**
 655      * Marks the current position in this input stream. A subsequent call to
 656      * the <code>reset</code> method repositions this stream at the last marked
 657      * position so that subsequent reads re-read the same bytes.
 658      *
 659      * <p> The <code>readlimit</code> arguments tells this input stream to
 660      * allow that many bytes to be read before the mark position gets
 661      * invalidated.
 662      *
 663      * <p> The general contract of <code>mark</code> is that, if the method
 664      * <code>markSupported</code> returns <code>true</code>, the stream somehow
 665      * remembers all the bytes read after the call to <code>mark</code> and
 666      * stands ready to supply those same bytes again if and whenever the method
 667      * <code>reset</code> is called.  However, the stream is not required to
 668      * remember any data at all if more than <code>readlimit</code> bytes are
 669      * read from the stream before <code>reset</code> is called.
 670      *


 701      *     file, if <code>mark</code> has not been called) will be resupplied
 702      *     to subsequent callers of the <code>read</code> method, followed by
 703      *     any bytes that otherwise would have been the next input data as of
 704      *     the time of the call to <code>reset</code>. </ul>
 705      *
 706      * <li> If the method <code>markSupported</code> returns
 707      * <code>false</code>, then:
 708      *
 709      *     <ul><li> The call to <code>reset</code> may throw an
 710      *     <code>IOException</code>.
 711      *
 712      *     <li> If an <code>IOException</code> is not thrown, then the stream
 713      *     is reset to a fixed state that depends on the particular type of the
 714      *     input stream and how it was created. The bytes that will be supplied
 715      *     to subsequent callers of the <code>read</code> method depend on the
 716      *     particular type of the input stream. </ul></ul>
 717      *
 718      * <p>The method <code>reset</code> for class <code>InputStream</code>
 719      * does nothing except throw an <code>IOException</code>.
 720      *
 721      * @throws  IOException  if this stream has not been marked or if the
 722      *          mark has been invalidated.
 723      * @see     java.io.InputStream#mark(int)
 724      * @see     java.io.IOException
 725      */
 726     public synchronized void reset() throws IOException {
 727         throw new IOException("mark/reset not supported");
 728     }
 729 
 730     /**
 731      * Tests if this input stream supports the <code>mark</code> and
 732      * <code>reset</code> methods. Whether or not <code>mark</code> and
 733      * <code>reset</code> are supported is an invariant property of a
 734      * particular input stream instance. The <code>markSupported</code> method
 735      * of <code>InputStream</code> returns <code>false</code>.
 736      *
 737      * @return  <code>true</code> if this stream instance supports the mark
 738      *          and reset methods; <code>false</code> otherwise.
 739      * @see     java.io.InputStream#mark(int)
 740      * @see     java.io.InputStream#reset()
 741      */


< prev index next >