本文整理汇总了Java中org.jruby.util.ByteList类的典型用法代码示例。如果您正苦于以下问题:Java ByteList类的具体用法?Java ByteList怎么用?Java ByteList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteList类属于org.jruby.util包,在下文中一共展示了ByteList类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hash
import org.jruby.util.ByteList; //导入依赖的package包/类
@JRubyMethod
public IRubyObject hash(ThreadContext context) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
for (RubyMap map : maps.values()) {
digest.update((byte) map.hashCode());
}
for (RubyRepeatedField repeatedField : repeatedFields.values()) {
digest.update((byte) repeatedFields.hashCode());
}
for (IRubyObject field : fields.values()) {
digest.update((byte) field.hashCode());
}
return context.runtime.newString(new ByteList(digest.digest()));
} catch (NoSuchAlgorithmException ignore) {
return context.runtime.newFixnum(System.identityHashCode(this));
}
}
示例2: hash
import org.jruby.util.ByteList; //导入依赖的package包/类
@JRubyMethod
public IRubyObject hash(ThreadContext context) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
for (IRubyObject key : table.keySet()) {
digest.update((byte) key.hashCode());
digest.update((byte) table.get(key).hashCode());
}
return context.runtime.newString(new ByteList(digest.digest()));
} catch (NoSuchAlgorithmException ignore) {
return context.runtime.newFixnum(System.identityHashCode(table));
}
}
示例3: convertJavaStringToRuby
import org.jruby.util.ByteList; //导入依赖的package包/类
private static IRubyObject convertJavaStringToRuby(Ruby runtime, String str) {
if (runtime.is1_9()) {
ByteList bytes = new ByteList(str.getBytes(RubyEncoding.UTF8), UTF8Encoding.INSTANCE);
return RubyString.newString(runtime, bytes);
} else {
return RubyString.newString(runtime, str);
}
}
示例4: toJavaString
import org.jruby.util.ByteList; //导入依赖的package包/类
private static String toJavaString(RubyString str) {
ByteList value = str.getByteList();
try {
if (str.getRuntime().is1_9()) {
return new String(value.getUnsafeBytes(), value.begin(), value.length(), str.getEncoding().toString());
}
return RubyEncoding.decodeUTF8(value.getUnsafeBytes(), value.begin(), value.length());
} catch (UnsupportedEncodingException uee) {
return str.toString();
}
}
示例5: rubyStringToString
import org.jruby.util.ByteList; //导入依赖的package包/类
public static String rubyStringToString(RubyString str) {
ByteList byteList = str.getByteList();
byte[] data = byteList.unsafeBytes();
int offset = byteList.begin();
int len = byteList.length();
ByteBuffer buf = ByteBuffer.wrap(data, offset, len);
return getCharsetUTF8().decode(buf).toString();
}
示例6: toRubyString
import org.jruby.util.ByteList; //导入依赖的package包/类
private IRubyObject toRubyString(byte[] bytes) {
if (bytes == null) {
return getRuntime().getNil();
} else {
return RubyString.newString(getRuntime(), new ByteList(bytes, ascii8bitEncoding));
}
}
示例7: encode
import org.jruby.util.ByteList; //导入依赖的package包/类
@JRubyMethod(meta = true)
public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) {
RubyMessage message = (RubyMessage) value;
return context.runtime.newString(new ByteList(message.build(context).toByteArray()));
}
示例8: toUsAsciiRubyString
import org.jruby.util.ByteList; //导入依赖的package包/类
public static final RubyString toUsAsciiRubyString(final Ruby runtime, final byte[] bytes) {
return RubyString.newString(runtime, new ByteList(bytes, USASCIIEncoding.INSTANCE, false));
}