Bug fix
[IRC.git] / Robust / src / ClassLibrary / FileInputStream.java
1 public class FileInputStream {
2     private int fd;
3
4     public FileInputStream(String pathname) {
5         fd=nativeOpen(pathname.getBytes());
6     }
7
8     public FileInputStream(File path) {
9         fd=nativeOpen(path.getPath().getBytes());
10     }
11
12     private static native int nativeOpen(byte[] filename);
13     private static native int nativeRead(int fd, byte[] array, int numBytes);
14     private static native void nativeClose(int fd);
15     
16     public int read() {
17         byte b[]=new byte[1];
18         int retval=read(b);
19         if (retval==-1)
20             return -1;
21         return b[0];
22     }
23
24     public int read(byte[] b) {
25         return nativeRead(fd, b, b.length);
26     }
27
28     public void close() {
29         nativeClose(fd);
30     }
31 }