@Override public int offset(Object parameter) { return ((RubyString) parameter).getByteList().begin(); }
private static int javaStringHashCode(ByteList iso8859) { int h = 0; int length = iso8859.length(); if (length > 0) { byte val[] = iso8859.getUnsafeBytes(); int begin = iso8859.begin(); h = new String(val, begin, length, RubyEncoding.ISO).hashCode(); } return h; }
public int precise_mbclen() { byte[] data = lexb.getUnsafeBytes(); int begin = lexb.begin(); // we subtract one since we have read past first byte by time we are calling this. return current_enc.length(data, begin + lex_p - 1, begin + lex_pend); }
@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 void writeString(ByteList value) throws IOException { int len = value.length(); writeInt(len); out.write(value.unsafeBytes(), value.begin(), len); }
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); }
public void run() { memory.read(0, bl.unsafeBytes(), bl.begin(), strlen); } });
private void ungetbyteCommon(RubyString ungetBytes) { ByteList ungetByteList = ungetBytes.getByteList(); ungetbyteCommon(ungetByteList.unsafeBytes(), ungetByteList.begin(), ungetByteList.realSize()); }
@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(); } }
/** * Wraps a <tt>MemoryIO</tt> accessor around an existing <tt>ByteList</tt> * * @param buf The <tt>ByteList</tt> to wrap. * @return A new <tt>MemoryIO</tt> instance that can access the memory. */ static JNAMemoryIO wrap(ByteList buf) { return new BufferIO(ByteBuffer.wrap(buf.unsafeBytes(), buf.begin(), buf.length())); } public abstract Pointer getAddress();
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); }
private static int javaStringHashCode(ByteList iso8859) { int h = 0; int length = iso8859.length(); if (length > 0) { byte val[] = iso8859.getUnsafeBytes(); int begin = iso8859.begin(); h = new String(val, begin, length, RubyEncoding.ISO).hashCode(); } return h; }
public void run() { memory.read(0, bl.unsafeBytes(), bl.begin(), len); } });
private void ungetbyteCommon(RubyString ungetBytes) { ByteList ungetByteList = ungetBytes.getByteList(); ungetbyteCommon(ungetByteList.unsafeBytes(), ungetByteList.begin(), ungetByteList.realSize()); }
@Override public int offset(Object parameter) { return ((RubyString) parameter).getByteList().begin(); }
public int precise_mbclen() { byte[] data = lexb.getUnsafeBytes(); int begin = lexb.begin(); // we subtract one since we have read past first byte by time we are calling this. return current_enc.length(data, begin + lex_p - 1, begin + lex_pend); }
/** * Check whether input object's string value contains a null byte, and if so * throw SecurityError. * @param runtime * @param value */ public static final void checkStringSafety(Ruby runtime, IRubyObject value) { RubyString s = value.asString(); ByteList bl = s.getByteList(); final byte[] array = bl.getUnsafeBytes(); final int end = bl.length(); for (int i = bl.begin(); i < end; ++i) { if (array[i] == (byte) 0) { throw runtime.newSecurityError("string contains null byte"); } } }
public static final long byteListToLong(org.jruby.util.ByteList bytes) { return byteArrayToLong(bytes.unsafeBytes(), bytes.begin(), bytes.length(), 10, false); } /**
@JRubyMethod(name = "from_string", meta = true) public static IRubyObject from_string(ThreadContext context, IRubyObject klass, IRubyObject s) { org.jruby.util.ByteList bl = s.convertToString().getByteList(); MemoryPointer ptr = (MemoryPointer) ((RubyClass) klass).newInstance(context, context.runtime.newFixnum(bl.length() + 1), Block.NULL_BLOCK); ptr.getMemoryIO().putZeroTerminatedByteArray(0, bl.unsafeBytes(), bl.begin(), bl.length()); return ptr; }
public void writeString(ByteList value) throws IOException { int len = value.length(); writeInt(len); out.write(value.getUnsafeBytes(), value.begin(), len); }