@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(name = "eos?") public RubyBoolean eos_p(ThreadContext context) { check(); return pos >= str.getByteList().getRealSize() ? context.tru : context.fals; }
@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 = "write_string") public IRubyObject write_string(ThreadContext context, IRubyObject strArg) { ByteList bl = strArg.convertToString().getByteList(); getMemoryIO().put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); return this; }
private RubyString strioSubstr(Ruby runtime, int pos, int len) { RubyString str = ptr.string; ByteList strByteList = str.getByteList(); byte[] strBytes = strByteList.getUnsafeBytes(); Encoding enc = str.getEncoding(); int rlen = str.size() - pos; if (len > rlen) len = rlen; if (len < 0) len = 0; if (len == 0) return RubyString.newEmptyString(runtime); return RubyString.newStringShared(runtime, strBytes, strByteList.getBegin() + pos, len, enc); }
@Override public ByteList gets() { IRubyObject result = io.callMethod(io.getRuntime().getCurrentContext(), "gets"); if (result.isNil()) return null; ByteList bytelist = result.convertToString().getByteList(); offset += bytelist.getRealSize(); bytelist.setEncoding(encoding); if (scriptLines != null) scriptLines.append(RubyString.newString(scriptLines.getRuntime(), bytelist)); return bytelist; }
@Deprecated public static Object coerceStringToType(RubyString string, Class target) { try { ByteList bytes = string.getByteList(); // 1.9 support for encodings // TODO: Fix charset use for JRUBY-4553 return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString()); } catch (UnsupportedEncodingException uee) { return string.toString(); } }
private void ungetbyteCommon(RubyString ungetBytes) { ByteList ungetByteList = ungetBytes.getByteList(); ungetbyteCommon(ungetByteList.unsafeBytes(), ungetByteList.begin(), ungetByteList.realSize()); }
@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(name = "write_string") public IRubyObject write_string(ThreadContext context, IRubyObject strArg) { ByteList bl = strArg.convertToString().getByteList(); getMemoryIO().put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); return this; }
@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(name = "rest?") public RubyBoolean rest_p(ThreadContext context) { check(); return pos >= str.getByteList().getRealSize() ? context.fals : context.tru; }
private RubyString strioSubstr(Ruby runtime, int pos, int len) { RubyString str = ptr.string; ByteList strByteList = str.getByteList(); byte[] strBytes = strByteList.getUnsafeBytes(); Encoding enc = str.getEncoding(); int rlen = str.size() - pos; if (len > rlen) len = rlen; if (len < 0) len = 0; if (len == 0) return RubyString.newEmptyString(runtime); return RubyString.newStringShared(runtime, strBytes, strByteList.getBegin() + pos, len, enc); }
@Deprecated public static Object coerceStringToType(RubyString string, Class target) { try { ByteList bytes = string.getByteList(); // 1.9 support for encodings // TODO: Fix charset use for JRUBY-4553 return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString()); } catch (UnsupportedEncodingException uee) { return string.toString(); } }
public long fwrite(ThreadContext context, IRubyObject str, boolean nosync) { // The System.console null check is our poor-man's isatty for Windows. See jruby/jruby#3292 if (Platform.IS_WINDOWS && isStdio() && System.console() != null) { return rbW32WriteConsole((RubyString)str); } str = doWriteconv(context, str); ByteList strByteList = ((RubyString)str).getByteList(); return binwrite(context, str, strByteList.unsafeBytes(), strByteList.begin(), strByteList.length(), nosync); }
@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(name = "write_string") public IRubyObject write_string(ThreadContext context, IRubyObject strArg) { ByteList bl = strArg.convertToString().getByteList(); getMemoryIO().put(0, bl.getUnsafeBytes(), bl.begin(), bl.length()); return this; }
@JRubyMethod public IRubyObject convert(ThreadContext context, IRubyObject srcBuffer) { RubyString srcString = srcBuffer.convertToString(); boolean is7BitAscii = srcString.isCodeRangeAsciiOnly(); ByteList srcBL = srcString.getByteList(); ByteList bytes = transcoder.convert(context, srcBL, is7BitAscii); return context.runtime.newString(bytes); }
@JRubyMethod(name = "eos?") public RubyBoolean eos_p(ThreadContext context) { check(); return pos >= str.getByteList().getRealSize() ? context.tru : context.fals; }
private RubyString strioSubstr(Ruby runtime, int pos, int len) { RubyString str = ptr.string; ByteList strByteList = str.getByteList(); byte[] strBytes = strByteList.getUnsafeBytes(); Encoding enc = str.getEncoding(); int rlen = str.size() - pos; if (len > rlen) len = rlen; if (len < 0) len = 0; if (len == 0) return RubyString.newEmptyString(runtime); return RubyString.newStringShared(runtime, strBytes, strByteList.getBegin() + pos, len, enc); }