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());
15 private static native int nativeOpen(byte[] filename);
16 private static native int nativeRead(int fd, byte[] array, int numBytes);
17 private static native int nativePeek(int fd);
18 private static native void nativeClose(int fd);
23 if (retval==-1 || retval==0)
26 // if carriage return comes back, dump it
31 // otherwise return result
36 return nativePeek(fd);
39 public int read(byte[] b) {
40 return nativeRead(fd, b, b.length);
43 public String readLine() {
47 // if we're already at the end of the file
48 // or there is an error, don't even return
54 // ASCII 13 is carriage return, check for that also
55 while( c != '\n' && c != 13 && c > 0 ) {
60 // peek and consume characters that are carriage
61 // returns or line feeds so the whole line is read
62 // and returned, and none of the line-ending chars
64 while( c == '\n' || c == 13 ) {