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);
19 private static native int nativeAvailable(int fd);
24 if (retval==-1 || retval==0)
27 // if carriage return comes back, dump it
32 // otherwise return result
37 return nativePeek(fd);
40 public int read(byte[] b, int offset, int len) {
41 if (offset < 0 || len < 0 || offset + len > b.length){
44 byte readbuf[]=new byte[len];
45 int rtr=nativeRead(fd, readbuf, len);
46 for(int i=offset;i<len+offset;i++){
47 b[i]=readbuf[i-offset];
52 public int read(byte[] b) {
53 return nativeRead(fd, b, b.length);
56 public String readLine() {
60 // if we're already at the end of the file
61 // or there is an error, don't even return
67 // ASCII 13 is carriage return, check for that also
68 while( c != '\n' && c != 13 && c > 0 ) {
73 // peek and consume characters that are carriage
74 // returns or line feeds so the whole line is read
75 // and returned, and none of the line-ending chars
77 while( c == '\n' || c == 13 ) {
89 public int available(){
90 return nativeAvailable(fd);