6092N/A * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A <code>FileInputStream</code> obtains input bytes 0N/A * from a file in a file system. What files 0N/A * are available depends on the host environment. 0N/A * <p><code>FileInputStream</code> is meant for reading streams of raw bytes 0N/A * such as image data. For reading streams of characters, consider using 0N/A * <code>FileReader</code>. 0N/A * @author Arthur van Hoff 0N/A * @see java.io.FileDescriptor 0N/A * @see java.io.FileOutputStream 3471N/A * @see java.nio.file.Files#newInputStream 0N/A /* File Descriptor - handle to the open file */ 5503N/A /* The path of the referenced file (null if the stream is created with a file descriptor) */ 0N/A * Creates a <code>FileInputStream</code> by 0N/A * opening a connection to an actual file, 0N/A * the file named by the path name <code>name</code> 0N/A * in the file system. A new <code>FileDescriptor</code> 0N/A * object is created to represent this file 0N/A * First, if there is a security 0N/A * manager, its <code>checkRead</code> method 0N/A * is called with the <code>name</code> argument 0N/A * If the named file does not exist, is a directory rather than a regular 0N/A * file, or for some other reason cannot be opened for reading then a 0N/A * <code>FileNotFoundException</code> is thrown. 0N/A * @param name the system-dependent file name. 0N/A * @exception FileNotFoundException if the file does not exist, 0N/A * is a directory rather than a regular file, 0N/A * or for some other reason cannot be opened for 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkRead</code> method denies read access 0N/A * @see java.lang.SecurityManager#checkRead(java.lang.String) 0N/A * Creates a <code>FileInputStream</code> by 0N/A * opening a connection to an actual file, 0N/A * the file named by the <code>File</code> 0N/A * object <code>file</code> in the file system. 0N/A * A new <code>FileDescriptor</code> object 0N/A * is created to represent this file connection. 0N/A * First, if there is a security manager, 0N/A * its <code>checkRead</code> method is called 0N/A * with the path represented by the <code>file</code> 0N/A * argument as its argument. 0N/A * If the named file does not exist, is a directory rather than a regular 0N/A * file, or for some other reason cannot be opened for reading then a 0N/A * <code>FileNotFoundException</code> is thrown. 0N/A * @param file the file to be opened for reading. 0N/A * @exception FileNotFoundException if the file does not exist, 0N/A * is a directory rather than a regular file, 0N/A * or for some other reason cannot be opened for 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkRead</code> method denies read access to the file. 0N/A * @see java.io.File#getPath() 0N/A * @see java.lang.SecurityManager#checkRead(java.lang.String) 0N/A * Creates a <code>FileInputStream</code> by using the file descriptor 0N/A * <code>fdObj</code>, which represents an existing connection to an 0N/A * actual file in the file system. 0N/A * If there is a security manager, its <code>checkRead</code> method is 0N/A * called with the file descriptor <code>fdObj</code> as its argument to 0N/A * see if it's ok to read the file descriptor. If read access is denied 0N/A * to the file descriptor a <code>SecurityException</code> is thrown. 0N/A * If <code>fdObj</code> is null then a <code>NullPointerException</code> 0N/A * This constructor does not throw an exception if <code>fdObj</code> 23N/A * is {@link java.io.FileDescriptor#valid() invalid}. 0N/A * However, if the methods are invoked on the resulting stream to attempt 0N/A * I/O on the stream, an <code>IOException</code> is thrown. 0N/A * @param fdObj the file descriptor to be opened for reading. 0N/A * @throws SecurityException if a security manager exists and its 0N/A * <code>checkRead</code> method denies read access to the 0N/A * @see SecurityManager#checkRead(java.io.FileDescriptor) 0N/A * FileDescriptor is being shared by streams. 0N/A * Opens the specified file for reading. 0N/A * @param name the name of the file 0N/A * Reads a byte of data from this input stream. This method blocks 0N/A * if no input is yet available. 0N/A * @return the next byte of data, or <code>-1</code> if the end of the 0N/A * @exception IOException if an I/O error occurs. 0N/A * Reads a subarray as a sequence of bytes. 0N/A * @param b the data to be written 0N/A * @param off the start offset in the data 0N/A * @param len the number of bytes that are written 0N/A * @exception IOException If an I/O error has occurred. 0N/A * Reads up to <code>b.length</code> bytes of data from this input 0N/A * stream into an array of bytes. This method blocks until some input 0N/A * @param b the buffer into which the data is read. 0N/A * @return the total number of bytes read into the buffer, or 0N/A * <code>-1</code> if there is no more data because the end of 0N/A * the file has been reached. 0N/A * @exception IOException if an I/O error occurs. 0N/A * Reads up to <code>len</code> bytes of data from this input stream 0N/A * into an array of bytes. If <code>len</code> is not zero, the method 0N/A * blocks until some input is available; otherwise, no 0N/A * bytes are read and <code>0</code> is returned. 0N/A * @param b the buffer into which the data is read. 0N/A * @param off the start offset in the destination array <code>b</code> 0N/A * @param len the maximum number of bytes read. 0N/A * @return the total number of bytes read into the buffer, or 0N/A * <code>-1</code> if there is no more data because the end of 0N/A * the file has been reached. 0N/A * @exception NullPointerException If <code>b</code> is <code>null</code>. 0N/A * @exception IndexOutOfBoundsException If <code>off</code> is negative, 0N/A * <code>len</code> is negative, or <code>len</code> is greater than 0N/A * <code>b.length - off</code> 0N/A * @exception IOException if an I/O error occurs. 0N/A * Skips over and discards <code>n</code> bytes of data from the 0N/A * <p>The <code>skip</code> method may, for a variety of 0N/A * reasons, end up skipping over some smaller number of bytes, 0N/A * possibly <code>0</code>. If <code>n</code> is negative, an 0N/A * <code>IOException</code> is thrown, even though the <code>skip</code> 0N/A * method of the {@link InputStream} superclass does nothing in this case. 0N/A * The actual number of bytes skipped is returned. 0N/A * <p>This method may skip more bytes than are remaining in the backing 0N/A * file. This produces no exception and the number of bytes skipped 0N/A * may include some number of bytes that were beyond the EOF of the 0N/A * backing file. Attempting to read from the stream after skipping past 0N/A * the end will result in -1 indicating the end of the file. 0N/A * @param n the number of bytes to be skipped. 0N/A * @return the actual number of bytes skipped. 0N/A * @exception IOException if n is negative, if the stream does not 0N/A * support seek, or if an I/O error occurs. 0N/A * Returns an estimate of the number of remaining bytes that can be read (or 0N/A * skipped over) from this input stream without blocking by the next 0N/A * invocation of a method for this input stream. The next invocation might be 0N/A * the same thread or another thread. A single read or skip of this 0N/A * many bytes will not block, but may read or skip fewer bytes. 0N/A * <p> In some cases, a non-blocking read (or skip) may appear to be 0N/A * blocked when it is merely slow, for example when reading large 0N/A * files over slow networks. 0N/A * @return an estimate of the number of remaining bytes that can be read 0N/A * (or skipped over) from this input stream without blocking. 0N/A * @exception IOException if this file input stream has been closed by calling 0N/A * {@code close} or an I/O error occurs. 0N/A * Closes this file input stream and releases any system resources 0N/A * associated with the stream. 0N/A * <p> If this stream has an associated channel then the channel is closed 0N/A * @exception IOException if an I/O error occurs. 5182N/A * Decrement the FD use count associated with the channel 5182N/A * The use count is incremented whenever a new channel 5182N/A * is obtained from this stream. 5182N/A * Decrement the FD use count associated with this stream 5182N/A * If FileDescriptor is still in use by another stream, the finalizer 0N/A * Returns the <code>FileDescriptor</code> 0N/A * object that represents the connection to 0N/A * the actual file in the file system being 0N/A * used by this <code>FileInputStream</code>. 0N/A * @return the file descriptor object associated with this stream. 0N/A * @exception IOException if an I/O error occurs. 0N/A * @see java.io.FileDescriptor 0N/A * Returns the unique {@link java.nio.channels.FileChannel FileChannel} 0N/A * object associated with this file input stream. 0N/A * <p> The initial {@link java.nio.channels.FileChannel#position() 0N/A * </code>position<code>} of the returned channel will be equal to the 0N/A * number of bytes read from the file so far. Reading bytes from this 0N/A * stream will increment the channel's position. Changing the channel's 0N/A * position, either explicitly or by reading, will change this stream's 0N/A * @return the file channel associated with this file input stream 0N/A synchronized (
this) {
5182N/A * Increment fd's use count. Invoking the channel's close() 5182N/A * method will result in decrementing the use count set for 0N/A * Ensures that the <code>close</code> method of this file input stream is 0N/A * called when there are no more references to it. 0N/A * @exception IOException if an I/O error occurs. 0N/A * @see java.io.FileInputStream#close() 5182N/A * Finalizer should not release the FileDescriptor if another 5182N/A * stream is still using it. If the user directly invokes 5182N/A * close() then the FileDescriptor is also released.