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 file output stream is an output stream for writing data to a 0N/A * <code>File</code> or to a <code>FileDescriptor</code>. Whether or not 0N/A * a file is available or may be created depends upon the underlying 0N/A * platform. Some platforms, in particular, allow a file to be opened 0N/A * for writing by only one <tt>FileOutputStream</tt> (or other 0N/A * file-writing object) at a time. In such situations the constructors in 0N/A * this class will fail if the file involved is already open. 0N/A * <p><code>FileOutputStream</code> is meant for writing streams of raw bytes 0N/A * such as image data. For writing streams of characters, consider using 0N/A * <code>FileWriter</code>. 0N/A * @author Arthur van Hoff 0N/A * @see java.io.FileDescriptor 0N/A * @see java.io.FileInputStream 3471N/A * @see java.nio.file.Files#newOutputStream 23N/A * The system dependent file descriptor. 5503N/A * The path of the referenced file (null if the stream is created with a file descriptor) 3200N/A * True if the file is opened for append. 4474N/A * The associated channel, initalized lazily. 23N/A * Creates a file output stream to write to the file with the 0N/A * specified name. A new <code>FileDescriptor</code> object is 0N/A * created to represent this file connection. 0N/A * First, if there is a security manager, its <code>checkWrite</code> 0N/A * method is called with <code>name</code> as its argument. 0N/A * If the file exists but is a directory rather than a regular file, does 0N/A * not exist but cannot be created, or cannot be opened for any other 0N/A * reason then a <code>FileNotFoundException</code> is thrown. 0N/A * @param name the system-dependent filename 0N/A * @exception FileNotFoundException if the file exists but is a directory 0N/A * rather than a regular file, does not exist but cannot 0N/A * be created, or cannot be opened for any other reason 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkWrite</code> method denies write access 0N/A * @see java.lang.SecurityManager#checkWrite(java.lang.String) 23N/A * Creates a file output stream to write to the file with the specified 23N/A * name. If the second argument is <code>true</code>, then 0N/A * bytes will be written to the end of the file rather than the beginning. 0N/A * A new <code>FileDescriptor</code> object is created to represent this 0N/A * First, if there is a security manager, its <code>checkWrite</code> 0N/A * method is called with <code>name</code> as its argument. 0N/A * If the file exists but is a directory rather than a regular file, does 0N/A * not exist but cannot be created, or cannot be opened for any other 0N/A * reason then a <code>FileNotFoundException</code> is thrown. 0N/A * @param name the system-dependent file name 0N/A * @param append if <code>true</code>, then bytes will be written 0N/A * to the end of the file rather than the beginning 0N/A * @exception FileNotFoundException if the file exists but is a directory 0N/A * rather than a regular file, does not exist but cannot 0N/A * be created, or cannot be opened for any other reason. 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkWrite</code> method denies write access 0N/A * @see java.lang.SecurityManager#checkWrite(java.lang.String) 0N/A * Creates a file output stream to write to the file represented by 0N/A * the specified <code>File</code> object. A new 0N/A * <code>FileDescriptor</code> object is created to represent this 0N/A * First, if there is a security manager, its <code>checkWrite</code> 0N/A * method is called with the path represented by the <code>file</code> 0N/A * argument as its argument. 0N/A * If the file exists but is a directory rather than a regular file, does 0N/A * not exist but cannot be created, or cannot be opened for any other 0N/A * reason then a <code>FileNotFoundException</code> is thrown. 0N/A * @param file the file to be opened for writing. 0N/A * @exception FileNotFoundException if the file exists but is a directory 0N/A * rather than a regular file, does not exist but cannot 0N/A * be created, or cannot be opened for any other reason 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkWrite</code> method denies write access 0N/A * @see java.io.File#getPath() 0N/A * @see java.lang.SecurityException 0N/A * @see java.lang.SecurityManager#checkWrite(java.lang.String) 0N/A * Creates a file output stream to write to the file represented by 0N/A * the specified <code>File</code> object. If the second argument is 0N/A * <code>true</code>, then bytes will be written to the end of the file 0N/A * rather than the beginning. A new <code>FileDescriptor</code> object is 0N/A * created to represent this file connection. 0N/A * First, if there is a security manager, its <code>checkWrite</code> 0N/A * method is called with the path represented by the <code>file</code> 0N/A * argument as its argument. 0N/A * If the file exists but is a directory rather than a regular file, does 0N/A * not exist but cannot be created, or cannot be opened for any other 0N/A * reason then a <code>FileNotFoundException</code> is thrown. 0N/A * @param file the file to be opened for writing. 0N/A * @param append if <code>true</code>, then bytes will be written 0N/A * to the end of the file rather than the beginning 0N/A * @exception FileNotFoundException if the file exists but is a directory 0N/A * rather than a regular file, does not exist but cannot 0N/A * be created, or cannot be opened for any other reason 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkWrite</code> method denies write access 0N/A * @see java.io.File#getPath() 0N/A * @see java.lang.SecurityException 0N/A * @see java.lang.SecurityManager#checkWrite(java.lang.String) 23N/A * Creates a file output stream to write to the specified file 0N/A * descriptor, which represents an existing connection to an actual 0N/A * file in the file system. 0N/A * First, if there is a security manager, its <code>checkWrite</code> 0N/A * method is called with the file descriptor <code>fdObj</code> 0N/A * argument as its argument. 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 writing 0N/A * @exception SecurityException if a security manager exists and its 0N/A * <code>checkWrite</code> method denies 0N/A * write access to the file descriptor 0N/A * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) 5182N/A * FileDescriptor is being shared by streams. 24N/A * Opens a file, with the specified name, for overwriting or appending. 0N/A * @param name name of file to be opened 24N/A * @param append whether the file is to be opened in append mode 3200N/A * Writes the specified byte to this file output stream. 3200N/A * @param b the byte to be written. 3200N/A * @param append {@code true} if the write operation first 3200N/A * advances the position to the end of file 0N/A * Writes the specified byte to this file output stream. Implements 0N/A * the <code>write</code> method of <code>OutputStream</code>. 0N/A * @param b the byte to be written. 0N/A * @exception IOException if an I/O error occurs. 0N/A * Writes a sub array 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 3200N/A * @param append {@code true} to first advance the position to the 0N/A * @exception IOException If an I/O error has occurred. 0N/A * Writes <code>b.length</code> bytes from the specified byte array 0N/A * to this file output stream. 0N/A * @param b the data. 0N/A * @exception IOException if an I/O error occurs. 0N/A * Writes <code>len</code> bytes from the specified byte array 0N/A * starting at offset <code>off</code> to this file output stream. 0N/A * @param b the data. 0N/A * @param off the start offset in the data. 0N/A * @param len the number of bytes to write. 0N/A * @exception IOException if an I/O error occurs. 0N/A * Closes this file output stream and releases any system resources 0N/A * associated with this stream. This file output stream may no longer 0N/A * be used for writing bytes. 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 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 FD use count associated with this stream 5182N/A * If FileDescriptor is still in use by another stream, the finalizer 0N/A * Returns the file descriptor associated with this stream. 0N/A * @return the <code>FileDescriptor</code> object that represents 0N/A * the connection to the file in the file system being used 0N/A * by this <code>FileOutputStream</code> object. 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 output stream. </p> 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 written to the file so far unless this stream is in 0N/A * append mode, in which case it will be equal to the size of the file. 0N/A * Writing bytes to this stream will increment the channel's position 0N/A * accordingly. Changing the channel's position, either explicitly or by 0N/A * writing, will change this stream's file position. 0N/A * @return the file channel associated with this file output 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 * Cleans up the connection to the file, and ensures that the 0N/A * <code>close</code> method of this file output stream is 0N/A * called when there are no more references to this stream. 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.