当前位置: 首页>>代码示例>>Java>>正文


Java ByteList类代码示例

本文整理汇总了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));
    }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:19,代码来源:RubyMessage.java

示例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));
    }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:14,代码来源:RubyMap.java

示例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);
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:NokogiriHelpers.java

示例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();
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:12,代码来源:NokogiriHelpers.java

示例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();
}
 
开发者ID:gocd,项目名称:gocd,代码行数:9,代码来源:NokogiriHelpers.java

示例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));
  }
}
 
开发者ID:square,项目名称:rack-servlet,代码行数:8,代码来源:JRubyRackInput.java

示例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()));
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:6,代码来源:RubyMessage.java

示例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));
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:4,代码来源:RubyHelper.java


注:本文中的org.jruby.util.ByteList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。