View Javadoc
1   /*
2    * junixsocket
3    *
4    * Copyright 2009-2024 Christian Kohlschütter
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.newsclub.net.unix;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  
24  import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
25  
26  /**
27   * An {@link OutputStream} for {@link AFSocket}, etc.
28   *
29   * @author Christian Kohlschütter
30   */
31  @IgnoreJRERequirement // see src/main/java8
32  public abstract class AFOutputStream extends OutputStream implements FileDescriptorAccess {
33    AFOutputStream() {
34      super();
35    }
36  
37    // IMPORTANT! also see src/main/java8/org/newsclub/net/unix/AFOutputStream shim
38  
39    /**
40     * Reads all bytes from the given input stream and writes the bytes to this output stream in the
41     * order that they are read. On return, this input stream will be at end of stream. This method
42     * does not close either stream.
43     *
44     * This method effectively is the reverse notation of
45     * {@link InputStream#transferTo(OutputStream)}, which may or may not be optimized for
46     * {@link AFSocket}s.
47     *
48     * @param in The {@link InputStream} to transfer from.
49     * @return The number of bytes transferred.
50     * @throws IOException on error.
51     */
52    public long transferFrom(InputStream in) throws IOException {
53      return in.transferTo(this);
54    }
55  }