author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58288 | 48e480e56aad |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
2 |
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.io; |
|
27 |
||
28 |
import java.nio.channels.FileChannel; |
|
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
52149
diff
changeset
|
29 |
import jdk.internal.access.SharedSecrets; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
52149
diff
changeset
|
30 |
import jdk.internal.access.JavaIOFileDescriptorAccess; |
2 | 31 |
import sun.nio.ch.FileChannelImpl; |
32 |
||
33 |
||
34 |
/** |
|
35 |
* A file output stream is an output stream for writing data to a |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
36 |
* {@code File} or to a {@code FileDescriptor}. Whether or not |
2 | 37 |
* a file is available or may be created depends upon the underlying |
38 |
* platform. Some platforms, in particular, allow a file to be opened |
|
32033
bf24e33c7919
8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents:
28062
diff
changeset
|
39 |
* for writing by only one {@code FileOutputStream} (or other |
2 | 40 |
* file-writing object) at a time. In such situations the constructors in |
41 |
* this class will fail if the file involved is already open. |
|
42 |
* |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
43 |
* <p>{@code FileOutputStream} is meant for writing streams of raw bytes |
2 | 44 |
* such as image data. For writing streams of characters, consider using |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
45 |
* {@code FileWriter}. |
2 | 46 |
* |
48224
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
47 |
* @apiNote |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
48 |
* To release resources used by this stream {@link #close} should be called |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
49 |
* directly or by try-with-resources. Subclasses are responsible for the cleanup |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
50 |
* of resources acquired by the subclass. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
51 |
* Subclasses that override {@link #finalize} in order to perform cleanup |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
52 |
* should be modified to use alternative cleanup mechanisms such as |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
53 |
* {@link java.lang.ref.Cleaner} and remove the overriding {@code finalize} method. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
54 |
* |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
55 |
* @implSpec |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
56 |
* If this FileOutputStream has been subclassed and the {@link #close} |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
57 |
* method has been overridden, the {@link #close} method will be |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
58 |
* called when the FileInputStream is unreachable. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
59 |
* Otherwise, it is implementation specific how the resource cleanup described in |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
60 |
* {@link #close} is performed. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
61 |
* |
2 | 62 |
* @author Arthur van Hoff |
63 |
* @see java.io.File |
|
64 |
* @see java.io.FileDescriptor |
|
65 |
* @see java.io.FileInputStream |
|
8158 | 66 |
* @see java.nio.file.Files#newOutputStream |
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22945
diff
changeset
|
67 |
* @since 1.0 |
2 | 68 |
*/ |
69 |
public |
|
70 |
class FileOutputStream extends OutputStream |
|
71 |
{ |
|
72 |
/** |
|
27263
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
73 |
* Access to FileDescriptor internals. |
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
74 |
*/ |
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
75 |
private static final JavaIOFileDescriptorAccess fdAccess = |
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
76 |
SharedSecrets.getJavaIOFileDescriptorAccess(); |
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
77 |
|
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
78 |
/** |
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
79 |
* The system dependent file descriptor. |
2 | 80 |
*/ |
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
81 |
private final FileDescriptor fd; |
2 | 82 |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
83 |
/** |
10586
6e20ecfec8ed
7082769: FileInputStream/FileOutputStream/RandomAccessFile allow file descriptor be closed when still in use
coffeys
parents:
9035
diff
changeset
|
84 |
* The associated channel, initialized lazily. |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
85 |
*/ |
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
86 |
private volatile FileChannel channel; |
2 | 87 |
|
22945
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
88 |
/** |
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
89 |
* The path of the referenced file |
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
90 |
* (null if the stream is created with a file descriptor) |
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
91 |
*/ |
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
92 |
private final String path; |
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
93 |
|
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
94 |
private final Object closeLock = new Object(); |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
95 |
|
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
96 |
private volatile boolean closed; |
2 | 97 |
|
98 |
/** |
|
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
99 |
* Creates a file output stream to write to the file with the |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
100 |
* specified name. A new {@code FileDescriptor} object is |
2 | 101 |
* created to represent this file connection. |
102 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
103 |
* First, if there is a security manager, its {@code checkWrite} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
104 |
* method is called with {@code name} as its argument. |
2 | 105 |
* <p> |
106 |
* If the file exists but is a directory rather than a regular file, does |
|
107 |
* not exist but cannot be created, or cannot be opened for any other |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
108 |
* reason then a {@code FileNotFoundException} is thrown. |
47117
2e7eed499598
8187021: Remove 2 redundant <p> tags in java.base API docs
jjg
parents:
45330
diff
changeset
|
109 |
* |
45330
d33052a04c7b
8180353: FileOutputStream documentation does not indicate properly whether files get truncated or not
bpb
parents:
44534
diff
changeset
|
110 |
* @implSpec Invoking this constructor with the parameter {@code name} is |
d33052a04c7b
8180353: FileOutputStream documentation does not indicate properly whether files get truncated or not
bpb
parents:
44534
diff
changeset
|
111 |
* equivalent to invoking {@link #FileOutputStream(String,boolean) |
d33052a04c7b
8180353: FileOutputStream documentation does not indicate properly whether files get truncated or not
bpb
parents:
44534
diff
changeset
|
112 |
* new FileOutputStream(name, false)}. |
2 | 113 |
* |
114 |
* @param name the system-dependent filename |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
115 |
* @throws FileNotFoundException if the file exists but is a directory |
2 | 116 |
* rather than a regular file, does not exist but cannot |
117 |
* be created, or cannot be opened for any other reason |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
118 |
* @throws SecurityException if a security manager exists and its |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
119 |
* {@code checkWrite} method denies write access |
2 | 120 |
* to the file. |
121 |
* @see java.lang.SecurityManager#checkWrite(java.lang.String) |
|
122 |
*/ |
|
123 |
public FileOutputStream(String name) throws FileNotFoundException { |
|
124 |
this(name != null ? new File(name) : null, false); |
|
125 |
} |
|
126 |
||
127 |
/** |
|
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
128 |
* Creates a file output stream to write to the file with the specified |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
129 |
* name. If the second argument is {@code true}, then |
2 | 130 |
* bytes will be written to the end of the file rather than the beginning. |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
131 |
* A new {@code FileDescriptor} object is created to represent this |
2 | 132 |
* file connection. |
133 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
134 |
* First, if there is a security manager, its {@code checkWrite} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
135 |
* method is called with {@code name} as its argument. |
2 | 136 |
* <p> |
137 |
* If the file exists but is a directory rather than a regular file, does |
|
138 |
* not exist but cannot be created, or cannot be opened for any other |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
139 |
* reason then a {@code FileNotFoundException} is thrown. |
2 | 140 |
* |
141 |
* @param name the system-dependent file name |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
142 |
* @param append if {@code true}, then bytes will be written |
2 | 143 |
* to the end of the file rather than the beginning |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
144 |
* @throws FileNotFoundException if the file exists but is a directory |
2 | 145 |
* rather than a regular file, does not exist but cannot |
146 |
* be created, or cannot be opened for any other reason. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
147 |
* @throws SecurityException if a security manager exists and its |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
148 |
* {@code checkWrite} method denies write access |
2 | 149 |
* to the file. |
150 |
* @see java.lang.SecurityManager#checkWrite(java.lang.String) |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
22945
diff
changeset
|
151 |
* @since 1.1 |
2 | 152 |
*/ |
153 |
public FileOutputStream(String name, boolean append) |
|
154 |
throws FileNotFoundException |
|
155 |
{ |
|
156 |
this(name != null ? new File(name) : null, append); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
* Creates a file output stream to write to the file represented by |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
161 |
* the specified {@code File} object. A new |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
162 |
* {@code FileDescriptor} object is created to represent this |
2 | 163 |
* file connection. |
164 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
165 |
* First, if there is a security manager, its {@code checkWrite} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
166 |
* method is called with the path represented by the {@code file} |
2 | 167 |
* argument as its argument. |
168 |
* <p> |
|
169 |
* If the file exists but is a directory rather than a regular file, does |
|
170 |
* not exist but cannot be created, or cannot be opened for any other |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
171 |
* reason then a {@code FileNotFoundException} is thrown. |
2 | 172 |
* |
173 |
* @param file the file to be opened for writing. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
174 |
* @throws FileNotFoundException if the file exists but is a directory |
2 | 175 |
* rather than a regular file, does not exist but cannot |
176 |
* be created, or cannot be opened for any other reason |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
177 |
* @throws SecurityException if a security manager exists and its |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
178 |
* {@code checkWrite} method denies write access |
2 | 179 |
* to the file. |
180 |
* @see java.io.File#getPath() |
|
181 |
* @see java.lang.SecurityException |
|
182 |
* @see java.lang.SecurityManager#checkWrite(java.lang.String) |
|
183 |
*/ |
|
184 |
public FileOutputStream(File file) throws FileNotFoundException { |
|
185 |
this(file, false); |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* Creates a file output stream to write to the file represented by |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
190 |
* the specified {@code File} object. If the second argument is |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
191 |
* {@code true}, then bytes will be written to the end of the file |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
192 |
* rather than the beginning. A new {@code FileDescriptor} object is |
2 | 193 |
* created to represent this file connection. |
194 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
195 |
* First, if there is a security manager, its {@code checkWrite} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
196 |
* method is called with the path represented by the {@code file} |
2 | 197 |
* argument as its argument. |
198 |
* <p> |
|
199 |
* If the file exists but is a directory rather than a regular file, does |
|
200 |
* not exist but cannot be created, or cannot be opened for any other |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
201 |
* reason then a {@code FileNotFoundException} is thrown. |
2 | 202 |
* |
203 |
* @param file the file to be opened for writing. |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
204 |
* @param append if {@code true}, then bytes will be written |
2 | 205 |
* to the end of the file rather than the beginning |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
206 |
* @throws FileNotFoundException if the file exists but is a directory |
2 | 207 |
* rather than a regular file, does not exist but cannot |
208 |
* be created, or cannot be opened for any other reason |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
209 |
* @throws SecurityException if a security manager exists and its |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
210 |
* {@code checkWrite} method denies write access |
2 | 211 |
* to the file. |
212 |
* @see java.io.File#getPath() |
|
213 |
* @see java.lang.SecurityException |
|
214 |
* @see java.lang.SecurityManager#checkWrite(java.lang.String) |
|
215 |
* @since 1.4 |
|
216 |
*/ |
|
217 |
public FileOutputStream(File file, boolean append) |
|
218 |
throws FileNotFoundException |
|
219 |
{ |
|
220 |
String name = (file != null ? file.getPath() : null); |
|
221 |
SecurityManager security = System.getSecurityManager(); |
|
222 |
if (security != null) { |
|
223 |
security.checkWrite(name); |
|
224 |
} |
|
225 |
if (name == null) { |
|
226 |
throw new NullPointerException(); |
|
227 |
} |
|
17430
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
11017
diff
changeset
|
228 |
if (file.isInvalid()) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
11017
diff
changeset
|
229 |
throw new FileNotFoundException("Invalid file path"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
11017
diff
changeset
|
230 |
} |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
231 |
this.fd = new FileDescriptor(); |
11017
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
232 |
fd.attach(this); |
22945
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
233 |
this.path = name; |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
234 |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
46
diff
changeset
|
235 |
open(name, append); |
52149
0edbbc64393c
8192939: Remove Finalize methods from FileInputStream and FileOutputStream
rriggs
parents:
49900
diff
changeset
|
236 |
FileCleanable.register(fd); // open sets the fd, register the cleanup |
2 | 237 |
} |
238 |
||
239 |
/** |
|
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
240 |
* Creates a file output stream to write to the specified file |
2 | 241 |
* descriptor, which represents an existing connection to an actual |
242 |
* file in the file system. |
|
243 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
244 |
* First, if there is a security manager, its {@code checkWrite} |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
245 |
* method is called with the file descriptor {@code fdObj} |
2 | 246 |
* argument as its argument. |
247 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
248 |
* If {@code fdObj} is null then a {@code NullPointerException} |
2 | 249 |
* is thrown. |
250 |
* <p> |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
251 |
* This constructor does not throw an exception if {@code fdObj} |
46
ddf5deb2a633
6631437: File{In,Out}putStream minor improvements to spec and stylistic improvements to code
martin
parents:
2
diff
changeset
|
252 |
* is {@link java.io.FileDescriptor#valid() invalid}. |
2 | 253 |
* However, if the methods are invoked on the resulting stream to attempt |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
254 |
* I/O on the stream, an {@code IOException} is thrown. |
2 | 255 |
* |
256 |
* @param fdObj the file descriptor to be opened for writing |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
257 |
* @throws SecurityException if a security manager exists and its |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
258 |
* {@code checkWrite} method denies |
2 | 259 |
* write access to the file descriptor |
260 |
* @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) |
|
261 |
*/ |
|
262 |
public FileOutputStream(FileDescriptor fdObj) { |
|
263 |
SecurityManager security = System.getSecurityManager(); |
|
264 |
if (fdObj == null) { |
|
265 |
throw new NullPointerException(); |
|
266 |
} |
|
267 |
if (security != null) { |
|
268 |
security.checkWrite(fdObj); |
|
269 |
} |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
270 |
this.fd = fdObj; |
22945
89dd803515d8
8033917: Keep track of file paths in file streams and channels for instrumentation purposes
sla
parents:
18786
diff
changeset
|
271 |
this.path = null; |
2 | 272 |
|
11017
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
273 |
fd.attach(this); |
2 | 274 |
} |
275 |
||
276 |
/** |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
46
diff
changeset
|
277 |
* Opens a file, with the specified name, for overwriting or appending. |
2 | 278 |
* @param name name of file to be opened |
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
46
diff
changeset
|
279 |
* @param append whether the file is to be opened in append mode |
2 | 280 |
*/ |
26190
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
281 |
private native void open0(String name, boolean append) |
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
46
diff
changeset
|
282 |
throws FileNotFoundException; |
2 | 283 |
|
26190
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
284 |
// wrap native call to allow instrumentation |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
285 |
/** |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
286 |
* Opens a file, with the specified name, for overwriting or appending. |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
287 |
* @param name name of file to be opened |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
288 |
* @param append whether the file is to be opened in append mode |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
289 |
*/ |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
290 |
private void open(String name, boolean append) |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
291 |
throws FileNotFoundException { |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
292 |
open0(name, append); |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
293 |
} |
d183677673d9
8054720: Modifications of I/O methods for instrumentation purposes
bpb
parents:
25859
diff
changeset
|
294 |
|
2 | 295 |
/** |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
296 |
* Writes the specified byte to this file output stream. |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
297 |
* |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
298 |
* @param b the byte to be written. |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
299 |
* @param append {@code true} if the write operation first |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
300 |
* advances the position to the end of file |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
301 |
*/ |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
302 |
private native void write(int b, boolean append) throws IOException; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
303 |
|
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
304 |
/** |
2 | 305 |
* Writes the specified byte to this file output stream. Implements |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
306 |
* the {@code write} method of {@code OutputStream}. |
2 | 307 |
* |
308 |
* @param b the byte to be written. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
309 |
* @throws IOException if an I/O error occurs. |
2 | 310 |
*/ |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
311 |
public void write(int b) throws IOException { |
27263
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
312 |
write(b, fdAccess.getAppend(fd)); |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
313 |
} |
2 | 314 |
|
315 |
/** |
|
316 |
* Writes a sub array as a sequence of bytes. |
|
317 |
* @param b the data to be written |
|
318 |
* @param off the start offset in the data |
|
319 |
* @param len the number of bytes that are written |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
320 |
* @param append {@code true} to first advance the position to the |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
321 |
* end of file |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
322 |
* @throws IOException If an I/O error has occurred. |
2 | 323 |
*/ |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
324 |
private native void writeBytes(byte b[], int off, int len, boolean append) |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
5506
diff
changeset
|
325 |
throws IOException; |
2 | 326 |
|
327 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
328 |
* Writes {@code b.length} bytes from the specified byte array |
2 | 329 |
* to this file output stream. |
330 |
* |
|
331 |
* @param b the data. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
332 |
* @throws IOException if an I/O error occurs. |
2 | 333 |
*/ |
334 |
public void write(byte b[]) throws IOException { |
|
27263
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
335 |
writeBytes(b, 0, b.length, fdAccess.getAppend(fd)); |
2 | 336 |
} |
337 |
||
338 |
/** |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
339 |
* Writes {@code len} bytes from the specified byte array |
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
340 |
* starting at offset {@code off} to this file output stream. |
2 | 341 |
* |
342 |
* @param b the data. |
|
343 |
* @param off the start offset in the data. |
|
344 |
* @param len the number of bytes to write. |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
345 |
* @throws IOException if an I/O error occurs. |
2 | 346 |
*/ |
347 |
public void write(byte b[], int off, int len) throws IOException { |
|
27263
819f5f87d485
8023173: FileDescriptor should respect append flag
igerasim
parents:
26190
diff
changeset
|
348 |
writeBytes(b, off, len, fdAccess.getAppend(fd)); |
2 | 349 |
} |
350 |
||
351 |
/** |
|
352 |
* Closes this file output stream and releases any system resources |
|
353 |
* associated with this stream. This file output stream may no longer |
|
354 |
* be used for writing bytes. |
|
355 |
* |
|
356 |
* <p> If this stream has an associated channel then the channel is closed |
|
357 |
* as well. |
|
358 |
* |
|
48224
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
359 |
* @apiNote |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
360 |
* Overriding {@link #close} to perform cleanup actions is reliable |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
361 |
* only when called directly or when called by try-with-resources. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
362 |
* Do not depend on finalization to invoke {@code close}; |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
363 |
* finalization is not reliable and is deprecated. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
364 |
* If cleanup of native resources is needed, other mechanisms such as |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
365 |
* {@linkplain java.lang.ref.Cleaner} should be used. |
be0df5ab3093
8080225: FileInput/OutputStream/FileChannel cleanup should be improved
rriggs
parents:
47460
diff
changeset
|
366 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
367 |
* @throws IOException if an I/O error occurs. |
2 | 368 |
* |
369 |
* @revised 1.4 |
|
370 |
* @spec JSR-51 |
|
371 |
*/ |
|
372 |
public void close() throws IOException { |
|
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
373 |
if (closed) { |
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
374 |
return; |
2 | 375 |
} |
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
376 |
synchronized (closeLock) { |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
377 |
if (closed) { |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
378 |
return; |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
379 |
} |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
380 |
closed = true; |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
381 |
} |
2 | 382 |
|
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
383 |
FileChannel fc = channel; |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
384 |
if (fc != null) { |
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
385 |
// possible race with getChannel(), benign since |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
386 |
// FileChannel.close is final and idempotent |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
387 |
fc.close(); |
2 | 388 |
} |
389 |
||
11017
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
390 |
fd.closeAll(new Closeable() { |
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
391 |
public void close() throws IOException { |
47235
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
392 |
fd.close(); |
11017
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
393 |
} |
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
394 |
}); |
2 | 395 |
} |
396 |
||
397 |
/** |
|
398 |
* Returns the file descriptor associated with this stream. |
|
399 |
* |
|
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
400 |
* @return the {@code FileDescriptor} object that represents |
2 | 401 |
* the connection to the file in the file system being used |
58288
48e480e56aad
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents:
58242
diff
changeset
|
402 |
* by this {@code FileOutputStream} object. |
2 | 403 |
* |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
52427
diff
changeset
|
404 |
* @throws IOException if an I/O error occurs. |
2 | 405 |
* @see java.io.FileDescriptor |
406 |
*/ |
|
407 |
public final FileDescriptor getFD() throws IOException { |
|
11017
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
408 |
if (fd != null) { |
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
409 |
return fd; |
353f81426721
7105952: Improve finalisation for FileInputStream/FileOutputStream/RandomAccessFile
coffeys
parents:
10586
diff
changeset
|
410 |
} |
2 | 411 |
throw new IOException(); |
412 |
} |
|
413 |
||
414 |
/** |
|
415 |
* Returns the unique {@link java.nio.channels.FileChannel FileChannel} |
|
18786 | 416 |
* object associated with this file output stream. |
2 | 417 |
* |
418 |
* <p> The initial {@link java.nio.channels.FileChannel#position() |
|
18786 | 419 |
* position} of the returned channel will be equal to the |
2 | 420 |
* number of bytes written to the file so far unless this stream is in |
421 |
* append mode, in which case it will be equal to the size of the file. |
|
422 |
* Writing bytes to this stream will increment the channel's position |
|
423 |
* accordingly. Changing the channel's position, either explicitly or by |
|
424 |
* writing, will change this stream's file position. |
|
425 |
* |
|
426 |
* @return the file channel associated with this file output stream |
|
427 |
* |
|
428 |
* @since 1.4 |
|
429 |
* @spec JSR-51 |
|
430 |
*/ |
|
431 |
public FileChannel getChannel() { |
|
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
432 |
FileChannel fc = this.channel; |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
433 |
if (fc == null) { |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
434 |
synchronized (this) { |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
435 |
fc = this.channel; |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
436 |
if (fc == null) { |
47460
b6d959fae9ef
8189963: Remove version of FileChannelImpl::open without the 'direct' parameter
bpb
parents:
47235
diff
changeset
|
437 |
this.channel = fc = FileChannelImpl.open(fd, path, false, |
b6d959fae9ef
8189963: Remove version of FileChannelImpl::open without the 'direct' parameter
bpb
parents:
47235
diff
changeset
|
438 |
true, false, this); |
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
439 |
if (closed) { |
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
440 |
try { |
41769
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
441 |
// possible race with close(), benign since |
f6f8a00fdba9
8168640: (fc) Avoiding AtomicBoolean in FileInput/-OutputStream improves startup
redestad
parents:
32834
diff
changeset
|
442 |
// FileChannel.close is final and idempotent |
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
443 |
fc.close(); |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
444 |
} catch (IOException ioe) { |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
445 |
throw new InternalError(ioe); // should not happen |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
446 |
} |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
447 |
} |
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
448 |
} |
2 | 449 |
} |
450 |
} |
|
28062
52b80a88a63b
8025619: (fc) FileInputStream.getChannel on closed stream returns FileChannel that doesn't know that stream is closed
bpb
parents:
27263
diff
changeset
|
451 |
return fc; |
2 | 452 |
} |
453 |
||
454 |
private static native void initIDs(); |
|
455 |
||
456 |
static { |
|
457 |
initIDs(); |
|
458 |
} |
|
459 |
} |