@@ -31,6 +31,7 @@ public void init() {
3131 Functions .set ("fopen" , new fopen ());
3232 Functions .set ("listFiles" , new listFiles ());
3333 Functions .set ("delete" , new delete ());
34+ Functions .set ("rename" , new rename ());
3435 Functions .set ("exists" , new exists ());
3536 Functions .set ("isDirectory" , new isDirectory ());
3637 Functions .set ("isFile" , new isFile ());
@@ -51,6 +52,7 @@ public void init() {
5152 Functions .set ("readText" , new readText ());
5253 Functions .set ("writeBoolean" , new writeBoolean ());
5354 Functions .set ("writeByte" , new writeByte ());
55+ Functions .set ("writeBytes" , new writeBytes ());
5456 Functions .set ("writeChar" , new writeChar ());
5557 Functions .set ("writeShort" , new writeShort ());
5658 Functions .set ("writeInt" , new writeInt ());
@@ -161,6 +163,16 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
161163 return NumberValue .fromBoolean (fileInfo .file .mkdir ());
162164 }
163165 }
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+ }
164176
165177 private static class fileSize extends FileFunction {
166178 @ Override
@@ -306,6 +318,24 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
306318 return NumberValue .ONE ;
307319 }
308320 }
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+ }
309339
310340 private static class writeChar extends FileFunction {
311341 @ Override
0 commit comments