@JRubyMethod(meta = true) public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) { byte[] bin = data.convertToString().getBytes(); RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); try { ret.builder.mergeFrom(bin); } catch (InvalidProtocolBufferException e) { throw context.runtime.newRuntimeError(e.getMessage()); } return ret; }
@JRubyMethod(name = "inflate", required = 1) public IRubyObject inflate(ThreadContext context, IRubyObject string, Block block) { ByteList data = null; if (!string.isNil()) { data = string.convertToString().getByteList(); } return inflate(context, data, block); }
public static PointerParameterStrategy stringParameterStrategy(IRubyObject parameter) { if (parameter instanceof RubyString) { return DIRECT_STRING_PARAMETER_STRATEGY; } else if (parameter.isNil()) { return NIL_POINTER_STRATEGY; } else { return stringParameterStrategy(parameter.convertToString()); } }
@JRubyMethod(name = {"update", "<<"}, required = 1) public IRubyObject update(IRubyObject obj) { ByteList bytes = obj.convertToString().getByteList(); algo.update(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize()); return this; }
@JRubyMethod public static IRubyObject resource_as_stream(final ThreadContext context, final IRubyObject self, final IRubyObject name) { final java.lang.Class klass = unwrapJavaObject(self); final String resName = name.convertToString().toString(); return convertJavaToUsableRubyObject(context.runtime, klass.getResourceAsStream(resName)); }
@JRubyMethod(name = "digest", required = 1, rest = true, meta = true) public static IRubyObject s_digest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); if (args.length < 1) { throw runtime.newArgumentError("no data given"); } RubyString str = args[0].convertToString(); IRubyObject[] newArgs = new IRubyObject[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); IRubyObject obj = ((RubyClass)recv).newInstance(ctx, newArgs, Block.NULL_BLOCK); return obj.callMethod(ctx, "digest", str); }
private static IRubyObject str_to_r_strict(ThreadContext context, IRubyObject recv) { RubyArray a = str_to_r_internal(context, recv); if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) { IRubyObject s = recv.callMethod(context, "inspect"); throw context.runtime.newArgumentError("invalid value for convert(): " + s.convertToString()); } return a.eltInternal(0); } }
public int read() throws IOException { if (in != null) { return in.read(); } final Ruby runtime = io.getRuntime(); IRubyObject readValue = readAdapter.call(runtime.getCurrentContext(), io, io, numOne); if (readValue.isNil()) return -1; return readValue.convertToString().getByteList().get(0) & 0xff; }
@JRubyMethod(visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject path) { if (path.respondsTo("to_path")) { path = path.callMethod(context, "to_path"); } RubyString str = path.convertToString(); if (str.getByteList().indexOf('\0') != -1) { throw context.runtime.newArgumentError("pathname contains null byte"); } infectBy(str); this.setPath((RubyString) str.dup()); return this; }
@JRubyMethod(name = "readpartial", required = 1, optional = 1) public IRubyObject readpartial(ThreadContext context, IRubyObject[] args) { // ruby bug 11885 if (args.length == 2) { args[1] = args[1].convertToString(); } IRubyObject value = getPartial(context, args, false, false); if (value.isNil()) { throw context.runtime.newEOFError(); } return value; }
protected IOOptions parseIOOptions19(IRubyObject arg) { Ruby runtime = getRuntime(); if (arg instanceof RubyFixnum) return newIOOptions(runtime, (int) RubyFixnum.fix2long(arg)); String modeString = arg.convertToString().toString(); try { return new IOOptions(runtime, modeString); } catch (InvalidValueException ive) { throw runtime.newArgumentError("invalid access mode " + modeString); } }
private static RubyNumeric str_to_r_strict(ThreadContext context, RubyString str) { IRubyObject[] ary = str_to_r_internal(context, str); if (ary[0] == context.nil || ary[1].convertToString().getByteList().length() > 0) { throw context.runtime.newArgumentError("invalid value for convert(): " + str.inspect(context.runtime)); } return (RubyNumeric) ary[0]; // (RubyRational) }
@JRubyMethod(name = "type_id=") public static IRubyObject set_type_id(IRubyObject self, IRubyObject type_id) { org.yecht.Node node = (org.yecht.Node)self.dataGetStructChecked(); if(!type_id.isNil()) { node.type_id = type_id.convertToString().toString(); } ((RubyObject)self).fastSetInstanceVariable("@type_id", type_id); return type_id; }
public static IRubyObject pack_sockaddr_in(ThreadContext context, IRubyObject port, IRubyObject host) { int portNum = port instanceof RubyString ? Integer.parseInt(port.convertToString().toString()) : RubyNumeric.fix2int(port); return Sockaddr.pack_sockaddr_in( context, portNum, host.isNil() ? null : host.convertToString().toString()); }
public static IRubyObject getaddress(ThreadContext context, IRubyObject hostname) { try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getByName(hostname.convertToString().toString()).getHostAddress()); } catch(UnknownHostException e) { throw sockerr(context.runtime, "getaddress: name or service not known"); } }
public static Encoding toEncoding(ThreadContext context, IRubyObject enc) { RubyString encStr = enc.convertToString(); if (!encStr.getEncoding().isAsciiCompatible()) { throw context.runtime.newArgumentError("invalid name encoding (non ASCII)"); } Encoding idx = context.runtime.getEncodingService().getEncodingFromObject(encStr); // check for missing encoding is in getEncodingFromObject return idx; }
@JRubyMethod(required = 4, visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject[] args) { family = SocketUtils.protocolFamilyFromArg(args[0]); level = SocketUtils.levelFromArg(args[1]); option = SocketUtils.optionFromArg(args[2]); data = args[3].convertToString().getByteList(); return this; }
@JRubyMethod public static IRubyObject resource_as_url(final ThreadContext context, final IRubyObject self, final IRubyObject name) { final java.lang.ClassLoader loader = unwrapIfJavaObject(self); final String resName = name.convertToString().toString(); return convertJavaToUsableRubyObject(context.runtime, loader.getResource(resName)); }
@JRubyMethod(name = "inflate", required = 1) public IRubyObject inflate(ThreadContext context, IRubyObject string, Block block) { ByteList data = null; if (!string.isNil()) { data = string.convertToString().getByteList(); } return inflate(context, data, block); }
@JRubyMethod(name = "digest", required = 1, rest = true, meta = true) public static IRubyObject s_digest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); if (args.length < 1) { throw runtime.newArgumentError("no data given"); } RubyString str = args[0].convertToString(); IRubyObject[] newArgs = new IRubyObject[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, args.length - 1); IRubyObject obj = ((RubyClass)recv).newInstance(ctx, newArgs, Block.NULL_BLOCK); return obj.callMethod(ctx, "digest", str); }