platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyFile.java in rhodes-2.0.0.rc2 vs platform/shared/rubyJVM/src/com/xruby/runtime/builtin/RubyFile.java in rhodes-2.0.0
- old
+ new
@@ -3,10 +3,13 @@
* Distributed under the BSD License
*/
package com.xruby.runtime.builtin;
+import java.io.InputStream;
+
+import com.rho.RhoRuby;
import com.xruby.runtime.lang.*;
//import com.xruby.runtime.lang.annotation.RubyLevelClass;
//import com.xruby.runtime.lang.annotation.RubyLevelMethod;
import j2me.io.File;
@@ -152,9 +155,26 @@
}
//@RubyLevelMethod(name="size", singleton=true)
public static RubyValue size(RubyValue receiver, RubyValue arg) {
String fileName = arg.toStr();
+ InputStream stream = null;
+
+ if ( fileName.startsWith("/apps"))
+ {
+ try {
+ stream = RhoRuby.loadFile("/" + fileName);
+ if ( stream != null )
+ {
+ RubyValue res = ObjectFactory.createInteger(stream.available());
+ stream.close();
+ return res;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
File file = new File(fileName);
if (!file.isFile() && !file.isDirectory()) {
throw new RubyException(RubyRuntime.RuntimeErrorClass, "No such file or directory - " + fileName);
}
return RubyBignum.bignorm(HugeInt.valueOf(file.length()));