src/java.base/share/classes/java/io/PipedOutputStream.java
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 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
    56      * Creates a piped output stream connected to the specified piped
    56      * Creates a piped output stream connected to the specified piped
    57      * input stream. Data bytes written to this stream will then be
    57      * input stream. Data bytes written to this stream will then be
    58      * available as input from <code>snk</code>.
    58      * available as input from <code>snk</code>.
    59      *
    59      *
    60      * @param      snk   The piped input stream to connect to.
    60      * @param      snk   The piped input stream to connect to.
    61      * @exception  IOException  if an I/O error occurs.
    61      * @throws     IOException  if an I/O error occurs.
    62      */
    62      */
    63     public PipedOutputStream(PipedInputStream snk)  throws IOException {
    63     public PipedOutputStream(PipedInputStream snk)  throws IOException {
    64         connect(snk);
    64         connect(snk);
    65     }
    65     }
    66 
    66 
    89      * <blockquote><pre>
    89      * <blockquote><pre>
    90      * snk.connect(src)</pre></blockquote>
    90      * snk.connect(src)</pre></blockquote>
    91      * The two calls have the same effect.
    91      * The two calls have the same effect.
    92      *
    92      *
    93      * @param      snk   the piped input stream to connect to.
    93      * @param      snk   the piped input stream to connect to.
    94      * @exception  IOException  if an I/O error occurs.
    94      * @throws     IOException  if an I/O error occurs.
    95      */
    95      */
    96     public synchronized void connect(PipedInputStream snk) throws IOException {
    96     public synchronized void connect(PipedInputStream snk) throws IOException {
    97         if (snk == null) {
    97         if (snk == null) {
    98             throw new NullPointerException();
    98             throw new NullPointerException();
    99         } else if (sink != null || snk.connected) {
    99         } else if (sink != null || snk.connected) {
   108     /**
   108     /**
   109      * Writes the specified <code>byte</code> to the piped output stream.
   109      * Writes the specified <code>byte</code> to the piped output stream.
   110      * <p>
   110      * <p>
   111      * Implements the <code>write</code> method of <code>OutputStream</code>.
   111      * Implements the <code>write</code> method of <code>OutputStream</code>.
   112      *
   112      *
   113      * @param      b   the <code>byte</code> to be written.
   113      * @param   b   the <code>byte</code> to be written.
   114      * @exception IOException if the pipe is <a href=#BROKEN> broken</a>,
   114      * @throws  IOException if the pipe is <a href=#BROKEN> broken</a>,
   115      *          {@link #connect(java.io.PipedInputStream) unconnected},
   115      *          {@link #connect(java.io.PipedInputStream) unconnected},
   116      *          closed, or if an I/O error occurs.
   116      *          closed, or if an I/O error occurs.
   117      */
   117      */
   118     public void write(int b)  throws IOException {
   118     public void write(int b)  throws IOException {
   119         if (sink == null) {
   119         if (sink == null) {
   126      * Writes <code>len</code> bytes from the specified byte array
   126      * Writes <code>len</code> bytes from the specified byte array
   127      * starting at offset <code>off</code> to this piped output stream.
   127      * starting at offset <code>off</code> to this piped output stream.
   128      * This method blocks until all the bytes are written to the output
   128      * This method blocks until all the bytes are written to the output
   129      * stream.
   129      * stream.
   130      *
   130      *
   131      * @param      b     the data.
   131      * @param   b     the data.
   132      * @param      off   the start offset in the data.
   132      * @param   off   the start offset in the data.
   133      * @param      len   the number of bytes to write.
   133      * @param   len   the number of bytes to write.
   134      * @exception IOException if the pipe is <a href=#BROKEN> broken</a>,
   134      * @throws  IOException if the pipe is <a href=#BROKEN> broken</a>,
   135      *          {@link #connect(java.io.PipedInputStream) unconnected},
   135      *          {@link #connect(java.io.PipedInputStream) unconnected},
   136      *          closed, or if an I/O error occurs.
   136      *          closed, or if an I/O error occurs.
   137      */
   137      */
   138     public void write(byte b[], int off, int len) throws IOException {
   138     public void write(byte b[], int off, int len) throws IOException {
   139         if (sink == null) {
   139         if (sink == null) {
   152     /**
   152     /**
   153      * Flushes this output stream and forces any buffered output bytes
   153      * Flushes this output stream and forces any buffered output bytes
   154      * to be written out.
   154      * to be written out.
   155      * This will notify any readers that bytes are waiting in the pipe.
   155      * This will notify any readers that bytes are waiting in the pipe.
   156      *
   156      *
   157      * @exception IOException if an I/O error occurs.
   157      * @throws    IOException if an I/O error occurs.
   158      */
   158      */
   159     public synchronized void flush() throws IOException {
   159     public synchronized void flush() throws IOException {
   160         if (sink != null) {
   160         if (sink != null) {
   161             synchronized (sink) {
   161             synchronized (sink) {
   162                 sink.notifyAll();
   162                 sink.notifyAll();
   167     /**
   167     /**
   168      * Closes this piped output stream and releases any system resources
   168      * Closes this piped output stream and releases any system resources
   169      * associated with this stream. This stream may no longer be used for
   169      * associated with this stream. This stream may no longer be used for
   170      * writing bytes.
   170      * writing bytes.
   171      *
   171      *
   172      * @exception  IOException  if an I/O error occurs.
   172      * @throws     IOException  if an I/O error occurs.
   173      */
   173      */
   174     public void close()  throws IOException {
   174     public void close()  throws IOException {
   175         if (sink != null) {
   175         if (sink != null) {
   176             sink.receivedLast();
   176             sink.receivedLast();
   177         }
   177         }