@@ -31,6 +31,7 @@ public void init() {
31
31
Functions .set ("fopen" , new fopen ());
32
32
Functions .set ("listFiles" , new listFiles ());
33
33
Functions .set ("delete" , new delete ());
34
+ Functions .set ("rename" , new rename ());
34
35
Functions .set ("exists" , new exists ());
35
36
Functions .set ("isDirectory" , new isDirectory ());
36
37
Functions .set ("isFile" , new isFile ());
@@ -51,6 +52,7 @@ public void init() {
51
52
Functions .set ("readText" , new readText ());
52
53
Functions .set ("writeBoolean" , new writeBoolean ());
53
54
Functions .set ("writeByte" , new writeByte ());
55
+ Functions .set ("writeBytes" , new writeBytes ());
54
56
Functions .set ("writeChar" , new writeChar ());
55
57
Functions .set ("writeShort" , new writeShort ());
56
58
Functions .set ("writeInt" , new writeInt ());
@@ -161,6 +163,16 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
161
163
return NumberValue .fromBoolean (fileInfo .file .mkdir ());
162
164
}
163
165
}
166
+
167
+ private static class rename extends FileFunction {
168
+ @ Override
169
+ protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
170
+ final File dest = files .get (args [1 ].asInt ()).file ;
171
+ System .out .println (fileInfo .file );
172
+ System .out .println (dest );
173
+ return NumberValue .fromBoolean (fileInfo .file .renameTo (dest ));
174
+ }
175
+ }
164
176
165
177
private static class fileSize extends FileFunction {
166
178
@ Override
@@ -306,6 +318,24 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
306
318
return NumberValue .ONE ;
307
319
}
308
320
}
321
+
322
+ private static class writeBytes extends FileFunction {
323
+ @ Override
324
+ protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
325
+ final ArrayValue array = (ArrayValue ) args [1 ];
326
+ int offset = 0 , length = array .size ();
327
+ final byte [] bytes = new byte [length ];
328
+ for (int i = 0 ; i < length ; i ++) {
329
+ bytes [i ] = (byte ) (array .get (i ).asInt () & 0xFF );
330
+ }
331
+ if (args .length > 3 ) {
332
+ offset = args [2 ].asInt ();
333
+ length = args [3 ].asInt ();
334
+ }
335
+ fileInfo .dos .write (bytes , offset , length );
336
+ return NumberValue .ONE ;
337
+ }
338
+ }
309
339
310
340
private static class writeChar extends FileFunction {
311
341
@ Override
0 commit comments