case STRING: Utils.validateStringEncoding(context, fieldDescriptor.getType(), value); val = ((RubyString) value).asJavaString(); break; case MESSAGE:
@Deprecated public static IRubyObject pack_sockaddr_un(ThreadContext context, IRubyObject filename) { String path = filename.convertToString().asJavaString(); return Sockaddr.pack_sockaddr_un(context, path); }
public static long rbW32WriteConsole(RubyString buffer) { // The actual port in MRI uses win32 APIs, but System.console seems to do what we want. See jruby/jruby#3292. // FIXME: This assumes the System.console() is the right one to write to. Can you have multiple active? System.console().printf("%s", buffer.asJavaString()); return buffer.size(); }
@JRubyMethod(name = "_load", required = 1, meta = true) public static RubyBigDecimal load(IRubyObject recv, IRubyObject from, Block block) { RubyBigDecimal rubyBigDecimal = (RubyBigDecimal) (((RubyClass)recv).allocate()); String precisionAndValue = from.convertToString().asJavaString(); String value = precisionAndValue.substring(precisionAndValue.indexOf(":")+1); rubyBigDecimal.value = new BigDecimal(value); return rubyBigDecimal; }
public static void failIfDirectory(Ruby runtime, RubyString pathStr) { if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) { if (Platform.IS_WINDOWS) { throw runtime.newErrnoEACCESError(pathStr.asJavaString()); } else { throw runtime.newErrnoEISDirError(pathStr.asJavaString()); } } }
public static void failIfDirectory(Ruby runtime, RubyString pathStr) { if (RubyFileTest.directory_p(runtime, pathStr).isTrue()) { if (Platform.IS_WINDOWS) { throw runtime.newErrnoEACCESError(pathStr.asJavaString()); } else { throw runtime.newErrnoEISDirError(pathStr.asJavaString()); } } }
@Override @JRubyMethod public IRubyObject inspect() { Ruby runtime = getRuntime(); StringBuilder part = new StringBuilder(); String cname = getMetaClass().getRealClass().getName(); part.append("#<").append(cname).append(":").append(path.asJavaString()).append(">"); return runtime.newString(part.toString()); }
@JRubyMethod(meta = true) public static RubyBigDecimal _load(ThreadContext context, IRubyObject recv, IRubyObject from) { String precisionAndValue = from.convertToString().asJavaString(); String value = precisionAndValue.substring(precisionAndValue.indexOf(':') + 1); return newInstance(context, recv, RubyString.newString(context.runtime, value)); }
@JRubyMethod public static IRubyObject to_java_string(ThreadContext context, IRubyObject self) { return Java.getInstance(context.runtime, self.convertToString().asJavaString()); } }
@JRubyMethod(name = {"pack_sockaddr_un", "sockaddr_un"}, meta = true) public static IRubyObject pack_sockaddr_un(ThreadContext context, IRubyObject recv, IRubyObject filename) { String path = filename.convertToString().asJavaString(); return Sockaddr.pack_sockaddr_un(context, path); }
/** * Creates the directory specified by <code>path</code>. Note that the * <code>mode</code> parameter is provided only to support existing Ruby * code, and is ignored. */ @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true) public static IRubyObject mkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) { Ruby runtime = context.runtime; RubyString path = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])); return mkdirCommon(runtime, path.asJavaString(), args); }
@JRubyMethod(name = {"rmdir", "unlink", "delete"}, required = 1, meta = true) public static IRubyObject rmdir19(ThreadContext context, IRubyObject recv, IRubyObject path) { Ruby runtime = context.runtime; RubyString cleanPath = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, path)); return rmdirCommon(runtime, cleanPath.asJavaString()); }
/** * Creates the directory specified by <code>path</code>. Note that the * <code>mode</code> parameter is provided only to support existing Ruby * code, and is ignored. */ @JRubyMethod(name = "mkdir", required = 1, optional = 1, meta = true) public static IRubyObject mkdir(ThreadContext context, IRubyObject recv, IRubyObject... args) { Ruby runtime = context.runtime; RubyString path = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])); return mkdirCommon(runtime, path.asJavaString(), args); }
/** * Returns an array containing all of the filenames in the given directory. */ @JRubyMethod(name = "entries", meta = true) public static RubyArray entries(ThreadContext context, IRubyObject recv, IRubyObject arg) { Ruby runtime = context.runtime; RubyString path = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, arg)); return entriesCommon(context, path.asJavaString(), runtime.getDefaultEncoding(), false); }
@JRubyMethod(required = 1, meta = true) public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRubyObject arg) { RubyString filename = get_path(context, arg); String jfilename = filename.asJavaString(); return context.runtime.newString(dirname(context, jfilename)).infectBy(filename); }
public IRubyObject parse(ThreadContext context, final String format, final RubyString text) { final List<StrptimeToken> compiledPattern = context.runtime.getCachedStrptimePattern(format); final StrptimeParser.FormatBag bag = new StrptimeParser().parse(compiledPattern, text.asJavaString()); return bag == null ? context.nil : convertFormatBagToHash(context, bag, text.getEncoding(), text.isTaint()); }
private static RubyArray childrenCommon(ThreadContext context, IRubyObject recv, IRubyObject arg, IRubyObject opts) { Encoding encoding = null; if (opts != context.nil) { IRubyObject encodingArg = ArgsUtil.extractKeywordArg(context, "encoding", opts); if (encodingArg != context.nil) { encoding = context.runtime.getEncodingService().getEncodingFromObject(encodingArg); } } if (encoding == null) encoding = context.runtime.getDefaultEncoding(); return entriesCommon(context, RubyFile.get_path(context, arg).asJavaString(), encoding, true); }
@JRubyMethod(required = 1, meta = true) public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRubyObject arg) { Ruby runtime = context.runtime; RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, arg)); String jfilename = filename.asJavaString(); return runtime.newString(dirname(context, jfilename)).infectBy(filename); }
@JRubyMethod(name = "__dir__", module = true, visibility = PRIVATE, reads = FILENAME) public static IRubyObject __dir__(ThreadContext context, IRubyObject recv) { // NOTE: not using __FILE__ = context.getFile() since it won't work with JIT final String __FILE__ = context.gatherCallerBacktrace()[1].getFileName(); RubyString path = RubyFile.expandPathInternal(context, RubyString.newString(context.runtime, __FILE__), null, false, true); return RubyString.newString(context.runtime, RubyFile.dirname(context, path.asJavaString())); }
@JRubyMethod(name = {"exists?", "exist?"}, meta = true, compat = RUBY1_9) public static IRubyObject exist(ThreadContext context, IRubyObject recv, IRubyObject arg) { // Capture previous exception if any. IRubyObject exception = context.runtime.getGlobalVariables().get("$!"); try { return context.runtime.newFileStat(RubyFile.get_path(context, arg).asJavaString(), false).directory_p(); } catch (Exception e) { // Restore $! context.runtime.getGlobalVariables().set("$!", exception); return context.runtime.newBoolean(false); } }