1 public class FileInputStream extends InputStream {
4 public FileInputStream(String pathname) {
5 fd = nativeOpen(pathname.getBytes());
8 public FileInputStream(File path) {
9 fd = nativeOpen(path.getPath().getBytes());
16 private static native int nativeOpen(byte[] filename);
18 private static native int nativeRead(int fd, byte[] array, int numBytes);
20 private static native int nativePeek(int fd);
22 private static native void nativeClose(int fd);
24 private static native int nativeAvailable(int fd);
27 byte b[] = new byte[1];
29 if (retval == -1 || retval == 0)
32 // if carriage return comes back, dump it
37 // otherwise return result
42 return nativePeek(fd);
45 public int read(byte[] b, int offset, int len) {
46 if (offset < 0 || len < 0 || offset + len > b.length) {
49 byte readbuf[] = new byte[len];
50 int rtr = nativeRead(fd, readbuf, len);
51 System.arraycopy(readbuf, 0, b, offset, len);
55 public int read(byte[] b) {
56 return nativeRead(fd, b, b.length);
59 public String readLine() {
63 // if we're already at the end of the file
64 // or there is an error, don't even return
70 // ASCII 13 is carriage return, check for that also
71 while (c != '\n' && c != 13 && c > 0) {
76 // peek and consume characters that are carriage
77 // returns or line feeds so the whole line is read
78 // and returned, and none of the line-ending chars
80 while (c == '\n' || c == 13) {
92 public int available() {
93 return nativeAvailable(fd);