< prev index next >

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

Print this page

354      * {@code PushbackInputStream} does nothing except throw an
355      * {@code IOException}.
356      *
357      * @throws  IOException  if this method is invoked.
358      * @see     java.io.InputStream#mark(int)
359      * @see     java.io.IOException
360      */
361     public synchronized void reset() throws IOException {
362         throw new IOException("mark/reset not supported");
363     }
364 
365     /**
366      * Closes this input stream and releases any system resources
367      * associated with the stream.
368      * Once the stream has been closed, further read(), unread(),
369      * available(), reset(), or skip() invocations will throw an IOException.
370      * Closing a previously closed stream has no effect.
371      *
372      * @throws     IOException  if an I/O error occurs.
373      */
374     public synchronized void close() throws IOException {
375         if (in == null)
376             return;
377         in.close();
378         in = null;
379         buf = null;



































380     }
381 }

354      * {@code PushbackInputStream} does nothing except throw an
355      * {@code IOException}.
356      *
357      * @throws  IOException  if this method is invoked.
358      * @see     java.io.InputStream#mark(int)
359      * @see     java.io.IOException
360      */
361     public synchronized void reset() throws IOException {
362         throw new IOException("mark/reset not supported");
363     }
364 
365     /**
366      * Closes this input stream and releases any system resources
367      * associated with the stream.
368      * Once the stream has been closed, further read(), unread(),
369      * available(), reset(), or skip() invocations will throw an IOException.
370      * Closing a previously closed stream has no effect.
371      *
372      * @throws     IOException  if an I/O error occurs.
373      */
374     public void close() throws IOException {
375         synchronized (this) {
376             waitIfClosing();
377             if (in == null) {
378                 // closed by another thread
379                 return;
380             }
381             closing = true;
382         }
383         try {
384             in.close();
385         } finally {
386             in = null;
387             buf = null;
388 
389             // notify anyone waiting for close
390             closing = false;
391             synchronized (this) {
392                 notifyAll();
393             }
394         }
395     }
396 
397     private volatile boolean closing;
398 
399     private void waitIfClosing() {
400         assert Thread.holdsLock(this);
401         boolean interrupted = false;
402         try {
403             while (closing) {
404                 try {
405                     wait();
406                 } catch (InterruptedException e) {
407                     interrupted = true;
408                 }
409             }
410         } finally {
411             if (interrupted) {
412                 Thread.currentThread().interrupt();
413             }
414         }
415     }
416 }
< prev index next >