From e497b0d05da3e13b5365cc477a6b7d792208b7f7 Mon Sep 17 00:00:00 2001 From: yeom Date: Mon, 15 Aug 2011 01:13:10 +0000 Subject: [PATCH] adds 'nativeavailable()' and 'read(buf,offset,len)' methods into FileInputStream. 'nativeavailable' returns the number of bytes that can be read from the current file. 'read(buf,offset,len)' reads up to 'len' bytes from the current file with the start offset to the destination array buf. --- .../ClassLibrary/SSJava/FileInputStream.java | 17 +++++++++++++++++ Robust/src/Runtime/file.c | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Robust/src/ClassLibrary/SSJava/FileInputStream.java b/Robust/src/ClassLibrary/SSJava/FileInputStream.java index 44d88892..c5b608dc 100644 --- a/Robust/src/ClassLibrary/SSJava/FileInputStream.java +++ b/Robust/src/ClassLibrary/SSJava/FileInputStream.java @@ -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 nativeAvailable(int fd); 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 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