change
[IRC.git] / Robust / src / ClassLibrary / FileInputStream.java
1 public class FileInputStream extends InputStream {
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   public int getfd() {
12     return fd;
13   }
14
15   private static native int nativeOpen(byte[] filename);
16   private static native int nativeRead(int fd, byte[] array, int numBytes);
17   private static native void nativeClose(int fd);
18
19   public int read() {
20     byte b[]=new byte[1];
21     int retval=read(b);
22     if (retval==-1)
23       return -1;
24     return b[0];
25   }
26
27   public int read(byte[] b) {
28     return nativeRead(fd, b, b.length);
29   }
30
31   public void close() {
32     nativeClose(fd);
33   }
34 }