adds 'nativeavailable()' and 'read(buf,offset,len)' methods into FileInputStream...
authoryeom <yeom>
Mon, 15 Aug 2011 01:13:10 +0000 (01:13 +0000)
committeryeom <yeom>
Mon, 15 Aug 2011 01:13:10 +0000 (01:13 +0000)
Robust/src/ClassLibrary/SSJava/FileInputStream.java
Robust/src/Runtime/file.c

index 44d888923eb697d4d1c7b5fd2987511a0e9970e4..c5b608dc67ee770dfdc75ce976c133508ad3b922 100644 (file)
@@ -16,6 +16,7 @@ public class FileInputStream extends InputStream {
   private static native int nativeRead(int fd, byte[] array, int numBytes);
   private static native int nativePeek(int fd);
   private static native void nativeClose(int fd);
   private static native int nativeRead(int fd, byte[] array, int numBytes);
   private static native int nativePeek(int fd);
   private static native void nativeClose(int fd);
+  private static native int nativeAvailable(int fd);
 
   public int read() {
     byte b[]=new byte[1];
 
   public int read() {
     byte b[]=new byte[1];
@@ -35,6 +36,18 @@ public class FileInputStream extends InputStream {
   public int peek() {
     return nativePeek(fd);
   }
   public int peek() {
     return nativePeek(fd);
   }
+  
+  public int read(byte[] b, int offset,  int len) {
+    if (offset < 0 || len < 0 || offset + len > b.length){
+      return -1;
+    }      
+    byte readbuf[]=new byte[len];
+    int rtr=nativeRead(fd, readbuf, len);
+    for(int i=offset;i<len+offset;i++){
+      b[i]=readbuf[i-offset];
+    }
+    return rtr;
+  }
 
   public int read(byte[] b) {
     return nativeRead(fd, b, b.length);
 
   public int read(byte[] b) {
     return nativeRead(fd, b, b.length);
@@ -72,4 +85,8 @@ public class FileInputStream extends InputStream {
   public void close() {
     nativeClose(fd);
   }
   public void close() {
     nativeClose(fd);
   }
+  
+  public int available(){
+    return nativeAvailable(fd);
+  }
 }
 }
index 46740b5cdc583afd0d43cc7b119cb771a40d7548..c8997a10601eff191ac8571c45fde704a8ad2b3b 100644 (file)
@@ -144,3 +144,17 @@ long long CALL01(___File______nativeLength_____AR_B, struct ArrayObject * ___pat
 #endif
 }
 #endif
 #endif
 }
 #endif
+
+#ifdef D___FileInputStream______nativeAvailable____I
+int CALL11(___FileInputStream______nativeAvailable____I, int fd, int fd) {
+#ifdef MULTICORE
+  return 0;
+#else
+  int avail;
+  int cur=lseek(fd, 0, SEEK_CUR);
+  int fsize = lseek(fd, 0, SEEK_END);
+  avail=fsize-cur;
+  return avail;
+#endif
+}
+#endif