corda/classpath/java/io/FileInputStream.java

48 lines
1.0 KiB
Java
Raw Normal View History

2007-07-25 00:34:45 +00:00
package java.io;
public class FileInputStream extends InputStream {
2007-07-27 02:39:53 +00:00
private int fd;
2007-07-25 00:34:45 +00:00
public FileInputStream(FileDescriptor fd) {
this.fd = fd.value;
2007-07-25 00:34:45 +00:00
}
public FileInputStream(String path) throws IOException {
fd = open(path);
}
public FileInputStream(File file) throws IOException {
this(file.getPath());
}
private static native int open(String path) throws IOException;
private static native int read(int fd) throws IOException;
2007-07-25 00:34:45 +00:00
private static native int read(int fd, byte[] b, int offset, int length)
throws IOException;
2007-07-25 00:34:45 +00:00
public static native void close(int fd) throws IOException;
public int read() throws IOException {
return read(fd);
}
public int read(byte[] b, int offset, int length) throws IOException {
if (b == null) {
throw new NullPointerException();
}
if (offset < 0 || offset + length > b.length) {
throw new ArrayIndexOutOfBoundsException();
}
return read(fd, b, offset, length);
}
public void close() throws IOException {
close(fd);
2007-07-27 02:39:53 +00:00
fd = -1;
}
2007-07-25 00:34:45 +00:00
}