private long sizeInternal() { // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
private long sizeInternal() { checkInitialized(); // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
private long sizeInternal() { checkInitialized(); // Workaround for JRUBY-4149 if (Platform.IS_WINDOWS && file != null) { try { return file.length(); } catch (SecurityException ex) { return 0L; } } else { return stat.st_size(); } }
@JRubyMethod(name = "zero?", required = 1, module = true) public static RubyBoolean zero_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile)) { filename = get_path(context, filename); } FileResource file = fileResource(filename); if (file.exists()) { if (file.isDirectory()) { // MRI behavior, enforced by RubySpecs. return runtime.newBoolean(Platform.IS_WINDOWS); } else { return runtime.newBoolean(file.length() == 0L); } } else { return runtime.getFalse(); } }
@JRubyMethod(name = "size", required = 1, module = true) public static IRubyObject size(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = recv.getRuntime(); if (!(filename instanceof RubyFile)) { if (filename.respondsTo("to_io")) { filename = (RubyIO) TypeConverter.convertToType(filename, runtime.getIO(), "to_io"); } else { filename = get_path(context, filename); } } FileResource file = fileResource(filename); if (!file.exists()) { noFileError(filename); } return runtime.newFixnum(file.length()); }
@JRubyMethod(name = "size?", required = 1, module = true) public static IRubyObject size_p(ThreadContext context, IRubyObject recv, IRubyObject filename) { Ruby runtime = context.runtime; if (!(filename instanceof RubyFile)) { if (filename.respondsTo("to_io")) { filename = (RubyIO) TypeConverter.convertToType(filename, runtime.getIO(), "to_io"); } else { filename = get_path(context, filename); } } FileResource file = fileResource(filename); if (!file.exists()) { return runtime.getNil(); } long length = file.length(); if (length > 0) { return runtime.newFixnum(length); } else { return runtime.getNil(); } }