src/java.base/share/classes/java/io/PipedWriter.java
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
     1 /*
     1 /*
     2  * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    51      * Creates a piped writer connected to the specified piped
    51      * Creates a piped writer connected to the specified piped
    52      * reader. Data characters written to this stream will then be
    52      * reader. Data characters written to this stream will then be
    53      * available as input from <code>snk</code>.
    53      * available as input from <code>snk</code>.
    54      *
    54      *
    55      * @param      snk   The piped reader to connect to.
    55      * @param      snk   The piped reader to connect to.
    56      * @exception  IOException  if an I/O error occurs.
    56      * @throws     IOException  if an I/O error occurs.
    57      */
    57      */
    58     public PipedWriter(PipedReader snk)  throws IOException {
    58     public PipedWriter(PipedReader snk)  throws IOException {
    59         connect(snk);
    59         connect(snk);
    60     }
    60     }
    61 
    61 
    84      * <blockquote><pre>
    84      * <blockquote><pre>
    85      * snk.connect(src)</pre></blockquote>
    85      * snk.connect(src)</pre></blockquote>
    86      * The two calls have the same effect.
    86      * The two calls have the same effect.
    87      *
    87      *
    88      * @param      snk   the piped reader to connect to.
    88      * @param      snk   the piped reader to connect to.
    89      * @exception  IOException  if an I/O error occurs.
    89      * @throws     IOException  if an I/O error occurs.
    90      */
    90      */
    91     public synchronized void connect(PipedReader snk) throws IOException {
    91     public synchronized void connect(PipedReader snk) throws IOException {
    92         if (snk == null) {
    92         if (snk == null) {
    93             throw new NullPointerException();
    93             throw new NullPointerException();
    94         } else if (sink != null || snk.connected) {
    94         } else if (sink != null || snk.connected) {
   109      * stream, but the thread is no longer alive, then an
   109      * stream, but the thread is no longer alive, then an
   110      * <code>IOException</code> is thrown.
   110      * <code>IOException</code> is thrown.
   111      * <p>
   111      * <p>
   112      * Implements the <code>write</code> method of <code>Writer</code>.
   112      * Implements the <code>write</code> method of <code>Writer</code>.
   113      *
   113      *
   114      * @param      c   the <code>char</code> to be written.
   114      * @param   c   the <code>char</code> to be written.
   115      * @exception  IOException  if the pipe is
   115      * @throw   IOException  if the pipe is
   116      *          <a href=PipedOutputStream.html#BROKEN> <code>broken</code></a>,
   116      *          <a href=PipedOutputStream.html#BROKEN> <code>broken</code></a>,
   117      *          {@link #connect(java.io.PipedReader) unconnected}, closed
   117      *          {@link #connect(java.io.PipedReader) unconnected}, closed
   118      *          or an I/O error occurs.
   118      *          or an I/O error occurs.
   119      */
   119      */
   120     public void write(int c)  throws IOException {
   120     public void write(int c)  throws IOException {
   131      * stream.
   131      * stream.
   132      * If a thread was reading data characters from the connected piped input
   132      * If a thread was reading data characters from the connected piped input
   133      * stream, but the thread is no longer alive, then an
   133      * stream, but the thread is no longer alive, then an
   134      * {@code IOException} is thrown.
   134      * {@code IOException} is thrown.
   135      *
   135      *
   136      * @param      cbuf  the data.
   136      * @param   cbuf  the data.
   137      * @param      off   the start offset in the data.
   137      * @param   off   the start offset in the data.
   138      * @param      len   the number of characters to write.
   138      * @param   len   the number of characters to write.
   139      *
   139      *
   140      * @throws  IndexOutOfBoundsException
   140      * @throws  IndexOutOfBoundsException
   141      *          If {@code off} is negative, or {@code len} is negative,
   141      *          If {@code off} is negative, or {@code len} is negative,
   142      *          or {@code off + len} is negative or greater than the length
   142      *          or {@code off + len} is negative or greater than the length
   143      *          of the given array
   143      *          of the given array
   159     /**
   159     /**
   160      * Flushes this output stream and forces any buffered output characters
   160      * Flushes this output stream and forces any buffered output characters
   161      * to be written out.
   161      * to be written out.
   162      * This will notify any readers that characters are waiting in the pipe.
   162      * This will notify any readers that characters are waiting in the pipe.
   163      *
   163      *
   164      * @exception  IOException  if the pipe is closed, or an I/O error occurs.
   164      * @throws     IOException  if the pipe is closed, or an I/O error occurs.
   165      */
   165      */
   166     public synchronized void flush() throws IOException {
   166     public synchronized void flush() throws IOException {
   167         if (sink != null) {
   167         if (sink != null) {
   168             if (sink.closedByReader || closed) {
   168             if (sink.closedByReader || closed) {
   169                 throw new IOException("Pipe closed");
   169                 throw new IOException("Pipe closed");
   177     /**
   177     /**
   178      * Closes this piped output stream and releases any system resources
   178      * Closes this piped output stream and releases any system resources
   179      * associated with this stream. This stream may no longer be used for
   179      * associated with this stream. This stream may no longer be used for
   180      * writing characters.
   180      * writing characters.
   181      *
   181      *
   182      * @exception  IOException  if an I/O error occurs.
   182      * @throws     IOException  if an I/O error occurs.
   183      */
   183      */
   184     public void close()  throws IOException {
   184     public void close()  throws IOException {
   185         closed = true;
   185         closed = true;
   186         if (sink != null) {
   186         if (sink != null) {
   187             sink.receivedLast();
   187             sink.receivedLast();