@@ -94,10 +94,11 @@ private Value process(File file, String mode) throws IOException {
94
94
95
95
DataOutputStream dos = null ;
96
96
BufferedWriter writer = null ;
97
+ final boolean append = mode .contains ("+" );
97
98
if (mode .contains ("wb" )) {
98
- dos = new DataOutputStream (new FileOutputStream (file ));
99
+ dos = new DataOutputStream (new FileOutputStream (file , append ));
99
100
} else if (mode .contains ("w" )) {
100
- writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (file ), "UTF-8" ));
101
+ writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (file , append ), "UTF-8" ));
101
102
}
102
103
103
104
final int key = files .size ();
@@ -115,7 +116,7 @@ public Value execute(Value... args) {
115
116
try {
116
117
return execute (files .get (key ), args );
117
118
} catch (IOException ioe ) {
118
- return NumberValue .ZERO ;
119
+ return NumberValue .MINUS_ONE ;
119
120
}
120
121
}
121
122
@@ -168,8 +169,6 @@ private static class rename extends FileFunction {
168
169
@ Override
169
170
protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
170
171
final File dest = files .get (args [1 ].asInt ()).file ;
171
- System .out .println (fileInfo .file );
172
- System .out .println (dest );
173
172
return NumberValue .fromBoolean (fileInfo .file .renameTo (dest ));
174
173
}
175
174
}
@@ -367,15 +366,27 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
367
366
private static class writeLong extends FileFunction {
368
367
@ Override
369
368
protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
370
- fileInfo .dos .writeLong ((long ) args [1 ].asNumber ());
369
+ final long value ;
370
+ if (args [1 ].type () == Types .NUMBER ) {
371
+ value = ((NumberValue )args [1 ]).asLong ();
372
+ } else {
373
+ value = (long ) args [1 ].asNumber ();
374
+ }
375
+ fileInfo .dos .writeLong (value );
371
376
return NumberValue .ONE ;
372
377
}
373
378
}
374
379
375
380
private static class writeFloat extends FileFunction {
376
381
@ Override
377
382
protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
378
- fileInfo .dos .writeFloat ((float ) args [1 ].asNumber ());
383
+ final float value ;
384
+ if (args [1 ].type () == Types .NUMBER ) {
385
+ value = ((NumberValue )args [1 ]).asFloat ();
386
+ } else {
387
+ value = (float ) args [1 ].asNumber ();
388
+ }
389
+ fileInfo .dos .writeFloat (value );
379
390
return NumberValue .ONE ;
380
391
}
381
392
}
0 commit comments