< prev index next > src/java.base/share/classes/java/io/FileOutputStream.java
Print this page
package java.io;
import java.nio.channels.FileChannel;
import jdk.internal.access.SharedSecrets;
import jdk.internal.access.JavaIOFileDescriptorAccess;
- import jdk.internal.misc.Blocker;
import sun.nio.ch.FileChannelImpl;
/**
* A file output stream is an output stream for writing data to a
* Opens a file, with the specified name, for overwriting or appending.
* @param name name of file to be opened
* @param append whether the file is to be opened in append mode
*/
private void open(String name, boolean append) throws FileNotFoundException {
! long comp = Blocker.begin();
- try {
- open0(name, append);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Writes the specified byte to this file output stream.
*
* Opens a file, with the specified name, for overwriting or appending.
* @param name name of file to be opened
* @param append whether the file is to be opened in append mode
*/
private void open(String name, boolean append) throws FileNotFoundException {
! open0(name, append);
}
/**
* Writes the specified byte to this file output stream.
*
* @throws IOException if an I/O error occurs.
*/
@Override
public void write(int b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! long comp = Blocker.begin();
- try {
- write(b, append);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Writes a sub array as a sequence of bytes.
* @param b the data to be written
* @throws IOException if an I/O error occurs.
*/
@Override
public void write(int b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! write(b, append);
}
/**
* Writes a sub array as a sequence of bytes.
* @param b the data to be written
* @throws IOException {@inheritDoc}
*/
@Override
public void write(byte[] b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! long comp = Blocker.begin();
- try {
- writeBytes(b, 0, b.length, append);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Writes {@code len} bytes from the specified byte array
* starting at offset {@code off} to this file output stream.
* @throws IOException {@inheritDoc}
*/
@Override
public void write(byte[] b) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! writeBytes(b, 0, b.length, append);
}
/**
* Writes {@code len} bytes from the specified byte array
* starting at offset {@code off} to this file output stream.
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! long comp = Blocker.begin();
- try {
- writeBytes(b, off, len, append);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Closes this file output stream and releases any system resources
* associated with this stream. This file output stream may no longer
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
boolean append = FD_ACCESS.getAppend(fd);
! writeBytes(b, off, len, append);
}
/**
* Closes this file output stream and releases any system resources
* associated with this stream. This file output stream may no longer
FileChannel fc = this.channel;
if (fc == null) {
synchronized (this) {
fc = this.channel;
if (fc == null) {
! this.channel = fc = FileChannelImpl.open(fd, path, false,
! true, false, this);
if (closed) {
try {
// possible race with close(), benign since
// FileChannel.close is final and idempotent
fc.close();
FileChannel fc = this.channel;
if (fc == null) {
synchronized (this) {
fc = this.channel;
if (fc == null) {
! fc = FileChannelImpl.open(fd, path, false, true, false, false, this);
! this.channel = fc;
if (closed) {
try {
// possible race with close(), benign since
// FileChannel.close is final and idempotent
fc.close();
< prev index next >