1 /*
2 * Copyright (c) 1994, 2011, 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
105 * <code>FileNotFoundException</code> is thrown.
106 *
107 * @param file the file to be opened for reading.
108 * @exception FileNotFoundException if the file does not exist,
109 * is a directory rather than a regular file,
110 * or for some other reason cannot be opened for
111 * reading.
112 * @exception SecurityException if a security manager exists and its
113 * <code>checkRead</code> method denies read access to the file.
114 * @see java.io.File#getPath()
115 * @see java.lang.SecurityManager#checkRead(java.lang.String)
116 */
117 public FileInputStream(File file) throws FileNotFoundException {
118 String name = (file != null ? file.getPath() : null);
119 SecurityManager security = System.getSecurityManager();
120 if (security != null) {
121 security.checkRead(name);
122 }
123 if (name == null) {
124 throw new NullPointerException();
125 }
126 fd = new FileDescriptor();
127 fd.attach(this);
128 open(name);
129 }
130
131 /**
132 * Creates a <code>FileInputStream</code> by using the file descriptor
133 * <code>fdObj</code>, which represents an existing connection to an
134 * actual file in the file system.
135 * <p>
136 * If there is a security manager, its <code>checkRead</code> method is
137 * called with the file descriptor <code>fdObj</code> as its argument to
138 * see if it's ok to read the file descriptor. If read access is denied
139 * to the file descriptor a <code>SecurityException</code> is thrown.
140 * <p>
141 * If <code>fdObj</code> is null then a <code>NullPointerException</code>
142 * is thrown.
143 * <p>
144 * This constructor does not throw an exception if <code>fdObj</code>
|
1 /*
2 * Copyright (c) 1994, 2013, 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
105 * <code>FileNotFoundException</code> is thrown.
106 *
107 * @param file the file to be opened for reading.
108 * @exception FileNotFoundException if the file does not exist,
109 * is a directory rather than a regular file,
110 * or for some other reason cannot be opened for
111 * reading.
112 * @exception SecurityException if a security manager exists and its
113 * <code>checkRead</code> method denies read access to the file.
114 * @see java.io.File#getPath()
115 * @see java.lang.SecurityManager#checkRead(java.lang.String)
116 */
117 public FileInputStream(File file) throws FileNotFoundException {
118 String name = (file != null ? file.getPath() : null);
119 SecurityManager security = System.getSecurityManager();
120 if (security != null) {
121 security.checkRead(name);
122 }
123 if (name == null) {
124 throw new NullPointerException();
125 }
126 if (file.isInvalid()) {
127 throw new FileNotFoundException("Invalid file path");
128 }
129 fd = new FileDescriptor();
130 fd.attach(this);
131 open(name);
132 }
133
134 /**
135 * Creates a <code>FileInputStream</code> by using the file descriptor
136 * <code>fdObj</code>, which represents an existing connection to an
137 * actual file in the file system.
138 * <p>
139 * If there is a security manager, its <code>checkRead</code> method is
140 * called with the file descriptor <code>fdObj</code> as its argument to
141 * see if it's ok to read the file descriptor. If read access is denied
142 * to the file descriptor a <code>SecurityException</code> is thrown.
143 * <p>
144 * If <code>fdObj</code> is null then a <code>NullPointerException</code>
145 * is thrown.
146 * <p>
147 * This constructor does not throw an exception if <code>fdObj</code>
|