Showing the changes to java (4 of 4 files). Show all
Unified · Split
| @@ -0,0 +1,140 @@ | ||
| 1 | +implement FileInputStream_L; | |
| 2 | + | |
| 3 | +# javal v1.3 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + sys : import jni; | |
| 27 | + FALSE : import jni; | |
| 28 | + TRUE : import jni; | |
| 29 | +include "FileDescriptor_L.m"; | |
| 30 | + FileDescriptor_obj : import FileDescriptor_L; | |
| 31 | +#<< | |
| 32 | + | |
| 33 | +include "FileInputStream_L.m"; | |
| 34 | + | |
| 35 | +#>> extra post includes here | |
| 36 | +#<< | |
| 37 | + | |
| 38 | +init( jni_p : JNI ) | |
| 39 | +{ | |
| 40 | + # save java native inteface mod instance | |
| 41 | + jni = jni_p; | |
| 42 | + #>>extra initialization here | |
| 43 | + sys = jni->sys; | |
| 44 | + #<< | |
| 45 | +} | |
| 46 | + | |
| 47 | +open_rString_V( this : ref FileInputStream_obj, p0 : JString) | |
| 48 | +{#>> | |
| 49 | + # p0 == file name | |
| 50 | + | |
| 51 | + if ((p0 == nil) || (p0.str == nil)) | |
| 52 | + jni->ThrowException("java.lang.NullPointerException", "str is nil"); | |
| 53 | + | |
| 54 | + this.fd.fd = sys->open(p0.str, sys->OREAD); | |
| 55 | + if(this.fd.fd == nil) | |
| 56 | + jni->ThrowException("java.io.IOException", "open error"); | |
| 57 | +}#<< | |
| 58 | + | |
| 59 | +read_I( this : ref FileInputStream_obj) : int | |
| 60 | +{#>> | |
| 61 | + buf := array[1] of byte; | |
| 62 | + | |
| 63 | + if (this.fd.fd == nil) | |
| 64 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 65 | + readin := sys->read(this.fd.fd, buf, 1); | |
| 66 | + if (readin == 0) # EOF | |
| 67 | + return -1; | |
| 68 | + | |
| 69 | + if (readin < 0) | |
| 70 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 71 | + return (int buf[0]); | |
| 72 | + | |
| 73 | +}#<< | |
| 74 | + | |
| 75 | +readBytes_aB_I_I_I( this : ref FileInputStream_obj, p0 : JArrayB,p1 : int,p2 : int) : int | |
| 76 | +{#>> | |
| 77 | + # p0 == input buffer (array of bytes) | |
| 78 | + # p1 == offset | |
| 79 | + # p2 == length | |
| 80 | + # read p2 bytes from the file and place them at location (p0 + p1) | |
| 81 | + | |
| 82 | + if (this.fd == nil) | |
| 83 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 84 | + if ((p0 == nil) || (p0.ary == nil)) | |
| 85 | + jni->ThrowException("java.lang.NullPointerException", "nil buffer pointer"); | |
| 86 | + if ((p1 < 0) || (p1 > len p0.ary)) | |
| 87 | + jni->ThrowException("java.lang.ArrayIndexOutOfBoundsException", | |
| 88 | + jni->sys->sprint( "offset=%d len buf array=%d", p1, len p0.ary)); | |
| 89 | + | |
| 90 | + if ((p1 + p2) > len p0.ary) | |
| 91 | + p2 = (len p0.ary) - p1; | |
| 92 | + if (p2 <= 0) | |
| 93 | + return 0; | |
| 94 | + | |
| 95 | + n := sys->read(this.fd.fd, p0.ary[p1: len p0.ary], p2); | |
| 96 | + if (n == 0) # EOF | |
| 97 | + return -1; | |
| 98 | + | |
| 99 | + if (n < 0) | |
| 100 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 101 | + return n; | |
| 102 | +}#<< | |
| 103 | + | |
| 104 | +skip_J_J( this : ref FileInputStream_obj, p0 : big) : big | |
| 105 | +{#>> | |
| 106 | + # skip the next p0 bytes from the Input stream. First find out where you are in | |
| 107 | + # the stream. Next skip the bytes then return the "actual" bytes skipped. | |
| 108 | + | |
| 109 | + if (this.fd.fd == nil) | |
| 110 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 111 | + cur := sys->seek(this.fd.fd, big 0, sys->SEEKRELA); | |
| 112 | + end := sys->seek(this.fd.fd, p0, sys->SEEKRELA); | |
| 113 | + return big (end - cur); | |
| 114 | +}#<< | |
| 115 | + | |
| 116 | +available_I( this : ref FileInputStream_obj) : int | |
| 117 | +{#>> | |
| 118 | + if (this.fd.fd == nil) | |
| 119 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 120 | + cur := sys->seek(this.fd.fd, big 0, Sys->SEEKRELA); | |
| 121 | + end := sys->seek(this.fd.fd, big 0, Sys->SEEKEND); | |
| 122 | + sys->seek(this.fd.fd, cur, Sys->SEEKSTART); | |
| 123 | + | |
| 124 | + return int (end - cur); | |
| 125 | +}#<< | |
| 126 | + | |
| 127 | +close0_V( this : ref FileInputStream_obj) | |
| 128 | +{#>> | |
| 129 | + if (this.fd != nil) | |
| 130 | + this.fd.fd = nil; | |
| 131 | +}#<< | |
| 132 | + | |
| 133 | +initIDs_V( ) | |
| 134 | +{#>> | |
| 135 | + # No-op | |
| 136 | +}#<< | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| @@ -0,0 +1,20 @@ | ||
| 1 | +# javal v1.3 generated file: edit with care | |
| 2 | + | |
| 3 | +FileInputStream_L : module | |
| 4 | +{ | |
| 5 | + FileInputStream_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + fd : ref FileDescriptor_obj; | |
| 9 | + }; | |
| 10 | + | |
| 11 | + init : fn( jni_p : JNI ); | |
| 12 | + open_rString_V : fn( this : ref FileInputStream_obj, p0 : JString); | |
| 13 | + read_I : fn( this : ref FileInputStream_obj) : int; | |
| 14 | + readBytes_aB_I_I_I : fn( this : ref FileInputStream_obj, p0 : JArrayB,p1 : int,p2 : int) : int; | |
| 15 | + skip_J_J : fn( this : ref FileInputStream_obj, p0 : big) : big; | |
| 16 | + available_I : fn( this : ref FileInputStream_obj) : int; | |
| 17 | + close0_V : fn( this : ref FileInputStream_obj); | |
| 18 | + initIDs_V: fn( ); | |
| 19 | + | |
| 20 | +}; | |
| @@ -0,0 +1,120 @@ | ||
| 1 | +implement FileOutputStream_L; | |
| 2 | + | |
| 3 | +# javal v1.3 generated file: edit with care | |
| 4 | + | |
| 5 | +include "jni.m"; | |
| 6 | + jni : JNI; | |
| 7 | + ClassModule, | |
| 8 | + JString, | |
| 9 | + JArray, | |
| 10 | + JArrayI, | |
| 11 | + JArrayC, | |
| 12 | + JArrayB, | |
| 13 | + JArrayS, | |
| 14 | + JArrayJ, | |
| 15 | + JArrayF, | |
| 16 | + JArrayD, | |
| 17 | + JArrayZ, | |
| 18 | + JArrayJObject, | |
| 19 | + JArrayJClass, | |
| 20 | + JArrayJString, | |
| 21 | + JClass, | |
| 22 | + JThread, | |
| 23 | + JObject : import jni; | |
| 24 | + | |
| 25 | +#>> extra pre includes here | |
| 26 | + sys : import jni; | |
| 27 | + FALSE : import jni; | |
| 28 | + TRUE : import jni; | |
| 29 | +include "FileDescriptor_L.m"; | |
| 30 | + FileDescriptor_obj : import FileDescriptor_L; | |
| 31 | +#<< | |
| 32 | + | |
| 33 | +include "FileOutputStream_L.m"; | |
| 34 | + | |
| 35 | +#>> extra post includes here | |
| 36 | +#<< | |
| 37 | + | |
| 38 | +init( jni_p : JNI ) | |
| 39 | +{ | |
| 40 | + # save java native inteface mod instance | |
| 41 | + jni = jni_p; | |
| 42 | + #>>extra initialization here | |
| 43 | + sys = jni->sys; | |
| 44 | + #<< | |
| 45 | +} | |
| 46 | + | |
| 47 | +open_rString_V( this : ref FileOutputStream_obj, p0 : JString) | |
| 48 | +{#>> | |
| 49 | + # open file pointed to by p0. If it does not exists, create it and | |
| 50 | + # and open it with mode of 644. | |
| 51 | + | |
| 52 | + if ((p0 == nil) || (p0.str == nil)) | |
| 53 | + jni->ThrowException("java.lang.NullPointerException", "null file name"); | |
| 54 | + | |
| 55 | + this.fd.fd = sys->create(p0.str, sys->OWRITE, 8r666); | |
| 56 | + if(this.fd.fd == nil) | |
| 57 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 58 | +}#<< | |
| 59 | + | |
| 60 | +openAppend_rString_V( this : ref FileOutputStream_obj, p0 : JString) | |
| 61 | +{#>> | |
| 62 | + if ((p0 == nil) || (p0.str == nil)) | |
| 63 | + jni->ThrowException("java.lang.NullPointerException", "null filename"); | |
| 64 | + | |
| 65 | + this.fd.fd = sys->open(p0.str, sys->OWRITE); | |
| 66 | + if(this.fd.fd == nil) | |
| 67 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 68 | + sys->seek(this.fd.fd, big 0, sys->SEEKEND); | |
| 69 | +}#<< | |
| 70 | + | |
| 71 | +write_I_V( this : ref FileOutputStream_obj, p0 : int) | |
| 72 | +{#>> | |
| 73 | + # p0 == character to write | |
| 74 | + c := array[1] of byte; | |
| 75 | + c[0] = byte p0; | |
| 76 | + | |
| 77 | + if ((this.fd == nil) || (this.fd.fd == nil)) | |
| 78 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 79 | + | |
| 80 | + if (sys->write(this.fd.fd, c, 1) != 1) | |
| 81 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 82 | +}#<< | |
| 83 | + | |
| 84 | +writeBytes_aB_I_I_V( this : ref FileOutputStream_obj, p0 : JArrayB,p1 : int,p2 : int) | |
| 85 | +{#>> | |
| 86 | + # p0 == buffer array to write from | |
| 87 | + # p1 == offset in buffer | |
| 88 | + # p2 == length to write out | |
| 89 | + | |
| 90 | + if ((this.fd == nil) || (this.fd.fd == nil)) | |
| 91 | + jni->ThrowException("java.lang.NullPointerException", "null FileDescriptor"); | |
| 92 | + if ((p0 == nil) || (p0.ary == nil)) | |
| 93 | + jni->ThrowException("java.lang.NullPointerException", nil); | |
| 94 | + if ((p1 < 0) || (p2 < 0) || (p1 > (len p0.ary))) | |
| 95 | + jni->ThrowException("java.lang.ArrayIndexOutOfBoundsException", nil); | |
| 96 | + | |
| 97 | + n := 0; | |
| 98 | + while (p2 > 0) { | |
| 99 | + # you can also write the following line as..... | |
| 100 | + # n = sys->write(this.fd.fd, p0.ary[p1:], p2); | |
| 101 | + n = sys->write(this.fd.fd, p0.ary[p1:len p0.ary], p2); | |
| 102 | + if (n == -1) { | |
| 103 | + jni->ThrowException("java.io.IOException", sys->sprint("%r")); | |
| 104 | + break; | |
| 105 | + } | |
| 106 | + p1 += n; | |
| 107 | + p2 -= n; | |
| 108 | + } | |
| 109 | +}#<< | |
| 110 | + | |
| 111 | +close0_V( this : ref FileOutputStream_obj) | |
| 112 | +{#>> | |
| 113 | + if (this.fd != nil) | |
| 114 | + this.fd.fd = nil; | |
| 115 | +}#<< | |
| 116 | + | |
| 117 | +initIDs_V( ) | |
| 118 | +{#>> | |
| 119 | + # No-op | |
| 120 | +}#<< | |
| @@ -0,0 +1,19 @@ | ||
| 1 | +# javal v1.3 generated file: edit with care | |
| 2 | + | |
| 3 | +FileOutputStream_L : module | |
| 4 | +{ | |
| 5 | + FileOutputStream_obj : adt | |
| 6 | + { | |
| 7 | + cl_mod : ClassModule; | |
| 8 | + fd : ref FileDescriptor_obj; | |
| 9 | + }; | |
| 10 | + | |
| 11 | + init : fn( jni_p : JNI ); | |
| 12 | + open_rString_V : fn( this : ref FileOutputStream_obj, p0 : JString); | |
| 13 | + openAppend_rString_V : fn( this : ref FileOutputStream_obj, p0 : JString); | |
| 14 | + write_I_V : fn( this : ref FileOutputStream_obj, p0 : int); | |
| 15 | + writeBytes_aB_I_I_V : fn( this : ref FileOutputStream_obj, p0 : JArrayB,p1 : int,p2 : int); | |
| 16 | + close0_V : fn( this : ref FileOutputStream_obj); | |
| 17 | + initIDs_V: fn( ); | |
| 18 | + | |
| 19 | +}; | |