1 /*
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
50 /**
51 * Whether the stream is closed; implicitly initialized to false.
52 */
53 private volatile boolean closed;
54
55 /**
56 * Object used to prevent a race on the 'closed' instance variable.
57 */
58 private final Object closeLock = new Object();
59
60 /**
61 * Creates an output stream filter built on top of the specified
62 * underlying output stream.
63 *
64 * @param out the underlying output stream to be assigned to
65 * the field {@code this.out} for later use, or
66 * <code>null</code> if this instance is to be
67 * created without an underlying stream.
68 */
69 public FilterOutputStream(OutputStream out) {
70 if (out == null) {
71 throw new NullPointerException();
72 }
73
74 this.out = out;
75 }
76
77 /**
78 * Writes the specified <code>byte</code> to this output stream.
79 * <p>
80 * The <code>write</code> method of <code>FilterOutputStream</code>
81 * calls the <code>write</code> method of its underlying output stream,
82 * that is, it performs {@code out.write(b)}.
83 * <p>
84 * Implements the abstract {@code write} method of {@code OutputStream}.
85 *
86 * @param b the <code>byte</code>.
87 * @exception IOException if an I/O error occurs.
88 */
89 @Override
90 public void write(int b) throws IOException {
91 out.write(b);
92 }
93
|
1 /*
2 * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
50 /**
51 * Whether the stream is closed; implicitly initialized to false.
52 */
53 private volatile boolean closed;
54
55 /**
56 * Object used to prevent a race on the 'closed' instance variable.
57 */
58 private final Object closeLock = new Object();
59
60 /**
61 * Creates an output stream filter built on top of the specified
62 * underlying output stream.
63 *
64 * @param out the underlying output stream to be assigned to
65 * the field {@code this.out} for later use, or
66 * <code>null</code> if this instance is to be
67 * created without an underlying stream.
68 */
69 public FilterOutputStream(OutputStream out) {
70 this.out = out;
71 }
72
73 /**
74 * Writes the specified <code>byte</code> to this output stream.
75 * <p>
76 * The <code>write</code> method of <code>FilterOutputStream</code>
77 * calls the <code>write</code> method of its underlying output stream,
78 * that is, it performs {@code out.write(b)}.
79 * <p>
80 * Implements the abstract {@code write} method of {@code OutputStream}.
81 *
82 * @param b the <code>byte</code>.
83 * @exception IOException if an I/O error occurs.
84 */
85 @Override
86 public void write(int b) throws IOException {
87 out.write(b);
88 }
89
|