From 6ab14362e92becbdd2dae34951cf2009cbcdccd8 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 24 Oct 2006 20:15:35 +0000 Subject: [PATCH] Support for reading/writing files via FileInputStream and FileOutputStream.java classes. --- Robust/src/ClassLibrary/FileInputStream.java | 27 +++++++++++ Robust/src/ClassLibrary/FileOutputStream.java | 25 ++++++++++ Robust/src/ClassLibrary/String.java | 9 ++-- Robust/src/Main/Main.java | 2 + Robust/src/Runtime/file.c | 48 +++++++++++++++++++ Robust/src/Tests/ReadFile.java | 12 +++++ Robust/src/buildscript | 2 +- Robust/src/buildscriptrepair | 1 + Robust/src/buildscripttask | 2 +- 9 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 Robust/src/ClassLibrary/FileInputStream.java create mode 100644 Robust/src/ClassLibrary/FileOutputStream.java create mode 100644 Robust/src/Runtime/file.c create mode 100644 Robust/src/Tests/ReadFile.java diff --git a/Robust/src/ClassLibrary/FileInputStream.java b/Robust/src/ClassLibrary/FileInputStream.java new file mode 100644 index 00000000..0a17f998 --- /dev/null +++ b/Robust/src/ClassLibrary/FileInputStream.java @@ -0,0 +1,27 @@ +public class FileInputStream { + private int fd; + + public FileInputStream(String pathname) { + fd=nativeOpen(pathname.getBytes()); + } + + private static native int nativeOpen(byte[] filename); + private static native int nativeRead(int fd, byte[] array, int numBytes); + private static native void nativeClose(int fd); + + public int read() { + byte b[]=new byte[1]; + int retval=read(b); + if (retval==-1) + return -1; + return b[0]; + } + + public int read(byte[] b) { + return nativeRead(fd, b, b.length); + } + + public void close() { + nativeClose(fd); + } +} diff --git a/Robust/src/ClassLibrary/FileOutputStream.java b/Robust/src/ClassLibrary/FileOutputStream.java new file mode 100644 index 00000000..eea7eef9 --- /dev/null +++ b/Robust/src/ClassLibrary/FileOutputStream.java @@ -0,0 +1,25 @@ +public class FileOutputStream { + private int fd; + + public FileOutputStream(String pathname) { + fd=nativeOpen(pathname.getBytes()); + } + + private static native int nativeOpen(byte[] filename); + private static native void nativeWrite(int fd, byte[] array); + private static native void nativeClose(int fd); + + public void write(int ch) { + byte b[]=new byte[1]; + b[0]=(byte)ch; + write(b); + } + + public void write(byte[] b) { + nativeWrite(fd, b); + } + + public void close() { + nativeClose(fd); + } +} diff --git a/Robust/src/ClassLibrary/String.java b/Robust/src/ClassLibrary/String.java index 722f61f8..ad1530b7 100644 --- a/Robust/src/ClassLibrary/String.java +++ b/Robust/src/ClassLibrary/String.java @@ -1,14 +1,17 @@ public class String { char string[]; - public String(char string[]) { - this.string=string; + public String(char str[]) { + char charstr[]=new char[str.length]; + for(int i=0;i +#include +#include +#include +#include +#include "structdefs.h" +#include "mem.h" + + +void ___FileOutputStream______nativeWrite____I__AR_B(int fd, struct ArrayObject * ao) { + int length=ao->___length___; + char * string= (((char *)& ao->___length___)+sizeof(int)); + int status=write(fd, string, length); +} + +void ___FileOutputStream______nativeClose____I(int fd) { + close(fd); +} + +int ___FileOutputStream______nativeOpen_____AR_B(struct ArrayObject * ao) { + int length=ao->___length___; + char* filename= (((char *)& ao->___length___)+sizeof(int)); + int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); + return fd; +} + +int ___FileInputStream______nativeOpen_____AR_B(struct ArrayObject * ao) { + int length=ao->___length___; + char* filename= (((char *)& ao->___length___)+sizeof(int)); + int fd=open(filename, O_RDONLY, 0); + return fd; +} + +void ___FileInputStream______nativeClose____I(int fd) { + close(fd); +} + +int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject * ao, int numBytes) { + int toread=ao->___length___; + char* string= (((char *)& ao->___length___)+sizeof(int)); + int status; + + if (numBytes