public static final byte[] doubleToByteArray(double d) { // TODO: develop an efficient method to do this directly and avoid all // the excess array allocating/copying (since we'll need to parse this // result anyway to format it for output). See sun.misc.FloatingDecimal. return org.jruby.util.ByteList.plain(Double.toString(d)); }
/** * Create a bytelist with ISO_8859_1 encoding from the provided CharSequence. * * @param s the source for new ByteList * @return the new ByteList */ public static ByteList create(CharSequence s) { return new ByteList(plain(s),false); }
private static InetAddress intoAddress(IRubyObject recv, String s) { try { byte[] bs = ByteList.plain(s); return InetAddress.getByAddress(bs); } catch(Exception e) { throw sockerr(recv, "strtoaddr: " + e.toString()); } }
public static InetAddress addressFromString(Ruby runtime, String s) { try { byte[] bs = ByteList.plain(s); return InetAddress.getByAddress(bs); } catch(Exception e) { throw sockerr(runtime, "strtoaddr: " + e.toString()); } }
public static InetAddress addressFromString(Ruby runtime, String s) { try { byte[] bs = ByteList.plain(s); return InetAddress.getByAddress(bs); } catch(Exception e) { throw sockerr(runtime, "strtoaddr: " + e.toString()); } }
/** * Mutator for internal string representation. * * @param value The new java.lang.String this RubyString should encapsulate * @deprecated */ public void setValue(CharSequence value) { view(ByteList.plain(value), false); }
public static String stringFromAddress(Ruby runtime, InetAddress as) { try { return new String(ByteList.plain(as.getAddress())); } catch(Exception e) { throw sockerr(runtime, "addrtostr: " + e.toString()); } }
public static String stringFromAddress(Ruby runtime, InetAddress as) { try { return new String(ByteList.plain(as.getAddress())); } catch(Exception e) { throw sockerr(runtime, "addrtostr: " + e.toString()); } }
/** * Mutator for internal string representation. * * @param value The new java.lang.String this RubyString should encapsulate * @deprecated */ public void setValue(CharSequence value) { view(ByteList.plain(value), false); }
/** * Create a bytelist with ISO_8859_1 encoding from the provided CharSequence. * * @param s the source for new ByteList * @return the new ByteList */ public static ByteList create(CharSequence s) { return new ByteList(plain(s),false); }
/** * Create a bytelist with ISO_8859_1 encoding from the provided CharSequence. * * @param s the source for new ByteList * @return the new ByteList */ public static ByteList create(CharSequence s) { return new ByteList(plain(s),false); }
/** * Mutator for internal string representation. * * @param value The new java.lang.String this RubyString should encapsulate * @deprecated */ public void setValue(CharSequence value) { view(ByteList.plain(value)); }
@Deprecated public static String convertToIdentifier(IRubyObject obj) { // Assume Symbol already returns ISO8859-1/raw bytes from asJavaString() // Assume all other objects cannot participate in providing raw bytes since we cannot // grab it's string representation without calling a method which properly encodes // the string. if (obj instanceof RubyString) { return new String(ByteList.plain(((RubyString) obj).getByteList()), RubyEncoding.ISO).intern(); } return obj.asJavaString().intern(); } /**
@JRubyMethod(name = "digest!") public IRubyObject digest_bang() { algo.reset(); byte[] digest = algo.digest(ByteList.plain(data)); reset(); return RubyString.newString(getRuntime(), digest); }
private static ByteList symbolBytesFromString(Ruby runtime, String internedSymbol) { if (runtime.is1_9()) { return new ByteList(ByteList.plain(internedSymbol), USASCIIEncoding.INSTANCE, false); } else { return ByteList.create(internedSymbol); } }
public Encoding getEncodingFromString(String string) { if (string == null) return null; ByteList name = new ByteList(ByteList.plain(string), false); checkAsciiEncodingName(name); SpecialEncoding special = SpecialEncoding.valueOf(name); if (special != null) { return special.toEncoding(runtime); } return findEncodingWithError(name); }
public int read(final char[] arr, final int off, final int len) { final IRubyObject read = io.callMethod(io.getRuntime().getCurrentContext(),"read", io.getRuntime().newFixnum(len)); if(read.isNil() || ((RubyString)read).getByteList().realSize == 0) { return -1; } else { final RubyString str = (RubyString)read; final org.jruby.util.ByteList val = str.getByteList(); System.arraycopy(org.jruby.util.ByteList.plain(val.bytes,val.begin,val.realSize),0,arr,off,val.realSize); return val.realSize; } } }// IOReader
@JRubyMethod() public static IRubyObject inspect(ThreadContext ctx, IRubyObject self) { return RubyString.newStringNoCopy(self.getRuntime(), ByteList.plain("#<" + self.getMetaClass().getRealClass().getName() + ": " + hexdigest(ctx, self, null) + ">")); }