@@ -69,7 +69,7 @@ public Value execute(Value... args) {
6969 }
7070 return process (file , "r" );
7171 } catch (IOException ioe ) {
72- return new NumberValue (- 1 ) ;
72+ return NumberValue . MINUS_ONE ;
7373 }
7474 }
7575
@@ -101,7 +101,7 @@ private static abstract class FileFunction implements Function {
101101 @ Override
102102 public Value execute (Value ... args ) {
103103 if (args .length < 1 ) throw new ArgumentsMismatchException ("File descriptor expected" );
104- final int key = ( int ) args [0 ].asNumber ();
104+ final int key = args [0 ].asInt ();
105105 try {
106106 return execute (files .get (key ), args );
107107 } catch (IOException ioe ) {
@@ -115,7 +115,7 @@ public Value execute(Value... args) {
115115 private static class readBoolean extends FileFunction {
116116 @ Override
117117 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
118- return new NumberValue (fileInfo .dis .readBoolean () ? 1 : 0 );
118+ return NumberValue . fromBoolean (fileInfo .dis .readBoolean ());
119119 }
120120 }
121121
@@ -132,8 +132,8 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
132132 final ArrayValue array = (ArrayValue ) args [1 ];
133133 int offset = 0 , length = array .size ();
134134 if (args .length > 3 ) {
135- offset = ( int ) args [2 ].asNumber ();
136- length = ( int ) args [3 ].asNumber ();
135+ offset = args [2 ].asInt ();
136+ length = args [3 ].asInt ();
137137 }
138138
139139 final byte [] buffer = new byte [length ];
@@ -170,7 +170,7 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
170170 private static class readChar extends FileFunction {
171171 @ Override
172172 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
173- return new NumberValue (fileInfo .dis .readChar ());
173+ return new NumberValue (( short ) fileInfo .dis .readChar ());
174174 }
175175 }
176176
@@ -239,15 +239,15 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
239239 private static class writeBoolean extends FileFunction {
240240 @ Override
241241 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
242- fileInfo .dos .writeBoolean (args [1 ].asNumber () != 0 );
242+ fileInfo .dos .writeBoolean (args [1 ].asInt () != 0 );
243243 return NumberValue .ONE ;
244244 }
245245 }
246246
247247 private static class writeByte extends FileFunction {
248248 @ Override
249249 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
250- fileInfo .dos .writeByte ((byte ) args [1 ].asNumber ());
250+ fileInfo .dos .writeByte ((byte ) args [1 ].asInt ());
251251 return NumberValue .ONE ;
252252 }
253253 }
@@ -256,7 +256,7 @@ private static class writeChar extends FileFunction {
256256 @ Override
257257 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
258258 final char ch = (args [1 ].type () == Types .NUMBER )
259- ? ((char ) args [1 ].asNumber ())
259+ ? ((char ) args [1 ].asInt ())
260260 : args [1 ].asString ().charAt (0 );
261261 fileInfo .dos .writeChar (ch );
262262 return NumberValue .ONE ;
@@ -266,15 +266,15 @@ protected Value execute(FileInfo fileInfo, Value[] args) throws IOException {
266266 private static class writeShort extends FileFunction {
267267 @ Override
268268 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
269- fileInfo .dos .writeShort ((short ) args [1 ].asNumber ());
269+ fileInfo .dos .writeShort ((short ) args [1 ].asInt ());
270270 return NumberValue .ONE ;
271271 }
272272 }
273273
274274 private static class writeInt extends FileFunction {
275275 @ Override
276276 protected Value execute (FileInfo fileInfo , Value [] args ) throws IOException {
277- fileInfo .dos .writeInt (( int ) args [1 ].asNumber ());
277+ fileInfo .dos .writeInt (args [1 ].asInt ());
278278 return NumberValue .ONE ;
279279 }
280280 }
0 commit comments