< prev index next > src/java.base/share/classes/java/io/FileInputStream.java
Print this page
package java.io;
import java.nio.channels.FileChannel;
import java.util.Arrays;
- import jdk.internal.misc.Blocker;
import jdk.internal.util.ArraysSupport;
import sun.nio.ch.FileChannelImpl;
/**
* A {@code FileInputStream} obtains input bytes
/**
* Opens the specified file for reading.
* @param name the name of the file
*/
private void open(String name) throws FileNotFoundException {
! long comp = Blocker.begin();
- try {
- open0(name);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Reads a byte of data from this input stream. This method blocks
* if no input is yet available.
/**
* Opens the specified file for reading.
* @param name the name of the file
*/
private void open(String name) throws FileNotFoundException {
! open0(name);
}
/**
* Reads a byte of data from this input stream. This method blocks
* if no input is yet available.
* file is reached.
* @throws IOException {@inheritDoc}
*/
@Override
public int read() throws IOException {
! long comp = Blocker.begin();
- try {
- return read0();
- } finally {
- Blocker.end(comp);
- }
}
private native int read0() throws IOException;
/**
* file is reached.
* @throws IOException {@inheritDoc}
*/
@Override
public int read() throws IOException {
! return read0();
}
private native int read0() throws IOException;
/**
* the file has been reached.
* @throws IOException if an I/O error occurs.
*/
@Override
public int read(byte[] b) throws IOException {
! long comp = Blocker.begin();
- try {
- return readBytes(b, 0, b.length);
- } finally {
- Blocker.end(comp);
- }
}
/**
* Reads up to {@code len} bytes of data from this input stream
* into an array of bytes. If {@code len} is not zero, the method
* the file has been reached.
* @throws IOException if an I/O error occurs.
*/
@Override
public int read(byte[] b) throws IOException {
! return readBytes(b, 0, b.length);
}
/**
* Reads up to {@code len} bytes of data from this input stream
* into an array of bytes. If {@code len} is not zero, the method
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws IOException if an I/O error occurs.
*/
@Override
public int read(byte[] b, int off, int len) throws IOException {
! long comp = Blocker.begin();
- try {
- return readBytes(b, off, len);
- } finally {
- Blocker.end(comp);
- }
}
@Override
public byte[] readAllBytes() throws IOException {
long length = length();
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws IOException if an I/O error occurs.
*/
@Override
public int read(byte[] b, int off, int len) throws IOException {
! return readBytes(b, off, len);
}
@Override
public byte[] readAllBytes() throws IOException {
long length = length();
return Long.MAX_VALUE;
}
}
private long length() throws IOException {
! long comp = Blocker.begin();
- try {
- return length0();
- } finally {
- Blocker.end(comp);
- }
}
private native long length0() throws IOException;
private long position() throws IOException {
! long comp = Blocker.begin();
- try {
- return position0();
- } finally {
- Blocker.end(comp);
- }
}
private native long position0() throws IOException;
/**
* Skips over and discards {@code n} bytes of data from the
return Long.MAX_VALUE;
}
}
private long length() throws IOException {
! return length0();
}
private native long length0() throws IOException;
private long position() throws IOException {
! return position0();
}
private native long position0() throws IOException;
/**
* Skips over and discards {@code n} bytes of data from the
* @throws IOException if n is negative, if the stream does not
* support seek, or if an I/O error occurs.
*/
@Override
public long skip(long n) throws IOException {
! long comp = Blocker.begin();
- try {
- return skip0(n);
- } finally {
- Blocker.end(comp);
- }
}
private native long skip0(long n) throws IOException;
/**
* @throws IOException if n is negative, if the stream does not
* support seek, or if an I/O error occurs.
*/
@Override
public long skip(long n) throws IOException {
! return skip0(n);
}
private native long skip0(long n) throws IOException;
/**
* @throws IOException if this file input stream has been closed by calling
* {@code close} or an I/O error occurs.
*/
@Override
public int available() throws IOException {
! long comp = Blocker.begin();
- try {
- return available0();
- } finally {
- Blocker.end(comp);
- }
}
private native int available0() throws IOException;
/**
* @throws IOException if this file input stream has been closed by calling
* {@code close} or an I/O error occurs.
*/
@Override
public int available() throws IOException {
! return available0();
}
private native int available0() throws IOException;
/**
FileChannel fc = this.channel;
if (fc == null) {
synchronized (this) {
fc = this.channel;
if (fc == null) {
! this.channel = fc = FileChannelImpl.open(fd, path, true,
! false, 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, true, false, 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 >