src/java.base/share/classes/java/io/PushbackInputStream.java
changeset 58242 94bb65cb37d3
parent 55730 94f8a0b34117
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
    82      * <code>in</code>, for later use. Initially,
    82      * <code>in</code>, for later use. Initially,
    83      * the pushback buffer is empty.
    83      * the pushback buffer is empty.
    84      *
    84      *
    85      * @param  in    the input stream from which bytes will be read.
    85      * @param  in    the input stream from which bytes will be read.
    86      * @param  size  the size of the pushback buffer.
    86      * @param  size  the size of the pushback buffer.
    87      * @exception IllegalArgumentException if {@code size <= 0}
    87      * @throws IllegalArgumentException if {@code size <= 0}
    88      * @since  1.1
    88      * @since  1.1
    89      */
    89      */
    90     public PushbackInputStream(InputStream in, int size) {
    90     public PushbackInputStream(InputStream in, int size) {
    91         super(in);
    91         super(in);
    92         if (size <= 0) {
    92         if (size <= 0) {
   121      * one, and otherwise calls the <code>read</code> method of its underlying
   121      * one, and otherwise calls the <code>read</code> method of its underlying
   122      * input stream and returns whatever value that method returns.
   122      * input stream and returns whatever value that method returns.
   123      *
   123      *
   124      * @return     the next byte of data, or <code>-1</code> if the end of the
   124      * @return     the next byte of data, or <code>-1</code> if the end of the
   125      *             stream has been reached.
   125      *             stream has been reached.
   126      * @exception  IOException  if this input stream has been closed by
   126      * @throws     IOException  if this input stream has been closed by
   127      *             invoking its {@link #close()} method,
   127      *             invoking its {@link #close()} method,
   128      *             or an I/O error occurs.
   128      *             or an I/O error occurs.
   129      * @see        java.io.InputStream#read()
   129      * @see        java.io.InputStream#read()
   130      */
   130      */
   131     public int read() throws IOException {
   131     public int read() throws IOException {
   148      * @param      off   the start offset in the destination array <code>b</code>
   148      * @param      off   the start offset in the destination array <code>b</code>
   149      * @param      len   the maximum number of bytes read.
   149      * @param      len   the maximum number of bytes read.
   150      * @return     the total number of bytes read into the buffer, or
   150      * @return     the total number of bytes read into the buffer, or
   151      *             <code>-1</code> if there is no more data because the end of
   151      *             <code>-1</code> if there is no more data because the end of
   152      *             the stream has been reached.
   152      *             the stream has been reached.
   153      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   153      * @throws     NullPointerException If <code>b</code> is <code>null</code>.
   154      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   154      * @throws     IndexOutOfBoundsException If <code>off</code> is negative,
   155      * <code>len</code> is negative, or <code>len</code> is greater than
   155      *             <code>len</code> is negative, or <code>len</code> is greater than
   156      * <code>b.length - off</code>
   156      *             <code>b.length - off</code>
   157      * @exception  IOException  if this input stream has been closed by
   157      * @throws     IOException  if this input stream has been closed by
   158      *             invoking its {@link #close()} method,
   158      *             invoking its {@link #close()} method,
   159      *             or an I/O error occurs.
   159      *             or an I/O error occurs.
   160      * @see        java.io.InputStream#read(byte[], int, int)
   160      * @see        java.io.InputStream#read(byte[], int, int)
   161      */
   161      */
   162     public int read(byte[] b, int off, int len) throws IOException {
   162     public int read(byte[] b, int off, int len) throws IOException {
   194      * After this method returns, the next byte to be read will have the value
   194      * After this method returns, the next byte to be read will have the value
   195      * <code>(byte)b</code>.
   195      * <code>(byte)b</code>.
   196      *
   196      *
   197      * @param      b   the <code>int</code> value whose low-order
   197      * @param      b   the <code>int</code> value whose low-order
   198      *                  byte is to be pushed back.
   198      *                  byte is to be pushed back.
   199      * @exception IOException If there is not enough room in the pushback
   199      * @throws    IOException If there is not enough room in the pushback
   200      *            buffer for the byte, or this input stream has been closed by
   200      *            buffer for the byte, or this input stream has been closed by
   201      *            invoking its {@link #close()} method.
   201      *            invoking its {@link #close()} method.
   202      */
   202      */
   203     public void unread(int b) throws IOException {
   203     public void unread(int b) throws IOException {
   204         ensureOpen();
   204         ensureOpen();
   212      * Pushes back a portion of an array of bytes by copying it to the front
   212      * Pushes back a portion of an array of bytes by copying it to the front
   213      * of the pushback buffer.  After this method returns, the next byte to be
   213      * of the pushback buffer.  After this method returns, the next byte to be
   214      * read will have the value <code>b[off]</code>, the byte after that will
   214      * read will have the value <code>b[off]</code>, the byte after that will
   215      * have the value <code>b[off+1]</code>, and so forth.
   215      * have the value <code>b[off+1]</code>, and so forth.
   216      *
   216      *
   217      * @param b the byte array to push back.
   217      * @param     b the byte array to push back.
   218      * @param off the start offset of the data.
   218      * @param     off the start offset of the data.
   219      * @param len the number of bytes to push back.
   219      * @param     len the number of bytes to push back.
   220      * @exception NullPointerException If <code>b</code> is <code>null</code>.
   220      * @throws    NullPointerException If <code>b</code> is <code>null</code>.
   221      * @exception IOException If there is not enough room in the pushback
   221      * @throws    IOException If there is not enough room in the pushback
   222      *            buffer for the specified number of bytes,
   222      *            buffer for the specified number of bytes,
   223      *            or this input stream has been closed by
   223      *            or this input stream has been closed by
   224      *            invoking its {@link #close()} method.
   224      *            invoking its {@link #close()} method.
   225      * @since     1.1
   225      * @since     1.1
   226      */
   226      */
   237      * Pushes back an array of bytes by copying it to the front of the
   237      * Pushes back an array of bytes by copying it to the front of the
   238      * pushback buffer.  After this method returns, the next byte to be read
   238      * pushback buffer.  After this method returns, the next byte to be read
   239      * will have the value <code>b[0]</code>, the byte after that will have the
   239      * will have the value <code>b[0]</code>, the byte after that will have the
   240      * value <code>b[1]</code>, and so forth.
   240      * value <code>b[1]</code>, and so forth.
   241      *
   241      *
   242      * @param b the byte array to push back
   242      * @param     b the byte array to push back
   243      * @exception NullPointerException If <code>b</code> is <code>null</code>.
   243      * @throws    NullPointerException If <code>b</code> is <code>null</code>.
   244      * @exception IOException If there is not enough room in the pushback
   244      * @throws    IOException If there is not enough room in the pushback
   245      *            buffer for the specified number of bytes,
   245      *            buffer for the specified number of bytes,
   246      *            or this input stream has been closed by
   246      *            or this input stream has been closed by
   247      *            invoking its {@link #close()} method.
   247      *            invoking its {@link #close()} method.
   248      * @since     1.1
   248      * @since     1.1
   249      */
   249      */
   262      * pushed back and the value returned by {@link
   262      * pushed back and the value returned by {@link
   263      * java.io.FilterInputStream#available available}.
   263      * java.io.FilterInputStream#available available}.
   264      *
   264      *
   265      * @return     the number of bytes that can be read (or skipped over) from
   265      * @return     the number of bytes that can be read (or skipped over) from
   266      *             the input stream without blocking.
   266      *             the input stream without blocking.
   267      * @exception  IOException  if this input stream has been closed by
   267      * @throws     IOException  if this input stream has been closed by
   268      *             invoking its {@link #close()} method,
   268      *             invoking its {@link #close()} method,
   269      *             or an I/O error occurs.
   269      *             or an I/O error occurs.
   270      * @see        java.io.FilterInputStream#in
   270      * @see        java.io.FilterInputStream#in
   271      * @see        java.io.InputStream#available()
   271      * @see        java.io.InputStream#available()
   272      */
   272      */
   325      * Tests if this input stream supports the <code>mark</code> and
   325      * Tests if this input stream supports the <code>mark</code> and
   326      * <code>reset</code> methods, which it does not.
   326      * <code>reset</code> methods, which it does not.
   327      *
   327      *
   328      * @return   <code>false</code>, since this class does not support the
   328      * @return   <code>false</code>, since this class does not support the
   329      *           <code>mark</code> and <code>reset</code> methods.
   329      *           <code>mark</code> and <code>reset</code> methods.
   330      * @see     java.io.InputStream#mark(int)
   330      * @see      java.io.InputStream#mark(int)
   331      * @see     java.io.InputStream#reset()
   331      * @see      java.io.InputStream#reset()
   332      */
   332      */
   333     public boolean markSupported() {
   333     public boolean markSupported() {
   334         return false;
   334         return false;
   335     }
   335     }
   336 
   336 
   353      *
   353      *
   354      * <p> The method <code>reset</code> for class
   354      * <p> The method <code>reset</code> for class
   355      * <code>PushbackInputStream</code> does nothing except throw an
   355      * <code>PushbackInputStream</code> does nothing except throw an
   356      * <code>IOException</code>.
   356      * <code>IOException</code>.
   357      *
   357      *
   358      * @exception  IOException  if this method is invoked.
   358      * @throws  IOException  if this method is invoked.
   359      * @see     java.io.InputStream#mark(int)
   359      * @see     java.io.InputStream#mark(int)
   360      * @see     java.io.IOException
   360      * @see     java.io.IOException
   361      */
   361      */
   362     public synchronized void reset() throws IOException {
   362     public synchronized void reset() throws IOException {
   363         throw new IOException("mark/reset not supported");
   363         throw new IOException("mark/reset not supported");
   368      * associated with the stream.
   368      * associated with the stream.
   369      * Once the stream has been closed, further read(), unread(),
   369      * Once the stream has been closed, further read(), unread(),
   370      * available(), reset(), or skip() invocations will throw an IOException.
   370      * available(), reset(), or skip() invocations will throw an IOException.
   371      * Closing a previously closed stream has no effect.
   371      * Closing a previously closed stream has no effect.
   372      *
   372      *
   373      * @exception  IOException  if an I/O error occurs.
   373      * @throws     IOException  if an I/O error occurs.
   374      */
   374      */
   375     public synchronized void close() throws IOException {
   375     public synchronized void close() throws IOException {
   376         if (in == null)
   376         if (in == null)
   377             return;
   377             return;
   378         in.close();
   378         in.close();