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


Java Ints.fromByteArray方法代码示例

本文整理汇总了Java中com.google.common.primitives.Ints.fromByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Ints.fromByteArray方法的具体用法?Java Ints.fromByteArray怎么用?Java Ints.fromByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.primitives.Ints的用法示例。


在下文中一共展示了Ints.fromByteArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readRpcBody

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
private Message readRpcBody(ServletInputStream in,
                            Class<? extends Message> requestClass) throws Exception {
    byte chunkSize[] = new byte[4];
    in.read(chunkSize);
    int size = Ints.fromByteArray(chunkSize);
    if (size == 0) {
        return ProtobufUtil.newEmptyMessage(requestClass);
    }
    if (size > ProtobufUtil.MAX_BODY_CHUNK_SIZE) {
        String message = "Invalid body chunk size: " + size;
        throw new RpcReadException(chunkSize, in, message);
    }
    byte bodyData[] = readyFully(in, size);
    Message pbRequest = ProtobufUtil.byteArrayToProtobuf(bodyData, requestClass);
    return pbRequest;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:17,代码来源:ProtobufHandler.java

示例2: ProtobufRpcResponse

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
public ProtobufRpcResponse(byte[] data) throws RpcCallException {
    //we may get a json error even though we make a protobuf call
    if (data[0] == '{' && data[data.length - 1] == '}') {
        readRpcError(new String(data));
        return;
    }
    int headerLength = Ints.fromByteArray(data);
    if (headerLength < 0 || headerLength > MAX_HEADER_SIZE) {
        StringBuilder sb = new StringBuilder();
        sb.append("Unexpected header length: ").append(headerLength).
                append(", data: ").append(ensurePrintable(data, 256));
        String message = sb.toString();
        logger.warn(message);
        throw new RpcCallException(RpcCallException.Category.InternalServerError, message);
    }
    logger.debug("headerLength = {}", headerLength);
    int offset = 4;
    byte headerData[] = Arrays.copyOfRange(data, offset, offset + headerLength);
    offset += headerLength;
    byte payloadLengthBuffer[] = Arrays.copyOfRange(data, offset, offset + 4);
    offset += 4;
    int payloadLength = Ints.fromByteArray(payloadLengthBuffer);
    payloadData = Arrays.copyOfRange(data, offset, offset + payloadLength);
    RpcEnvelope.Response responseHeader = ProtobufUtil.
            byteArrayToProtobuf(headerData, RpcEnvelope.Response.class);
    serviceMethod = responseHeader.getServiceMethod();
    sequenceNumber = responseHeader.getSequenceNumber();
    errorMessage = responseHeader.getError();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:30,代码来源:ProtobufRpcResponse.java

示例3: readRpcEnvelope

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
private RpcEnvelope.Request readRpcEnvelope(ServletInputStream in) throws Exception {
    byte chunkSize[] = new byte[4];
    in.read(chunkSize);
    int size = Ints.fromByteArray(chunkSize);
    if (size <= 0 || size > ProtobufUtil.MAX_HEADER_CHUNK_SIZE) {
        String message = "Invalid header chunk size: " + size;
        throw new RpcReadException(chunkSize, in, message);
    }
    byte headerData[] = readyFully(in, size);
    RpcEnvelope.Request rpcRequest = RpcEnvelope.Request.parseFrom(headerData);
    return rpcRequest;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:13,代码来源:ProtobufHandler.java

示例4: handleIPv4

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/** Converts a string specifying an IPv4 address into an integer. The string can be either a single integer (representing
 *  the address) or a dot-separated 4-tuple of bytes.
 *
 * @param s the string to be converted.
 * @return the integer representing the IP address specified by s.
 * @throws ConfigurationException
 */
private int handleIPv4(final String s) throws ConfigurationException {
	try {
		if (!RuntimeConfiguration.DOTTED_ADDRESS.matcher(s).matches()) throw new ConfigurationException("Malformed IPv4 " + s + " for blacklisting");
		// Note that since we're sure this is a dotted-notation address, we pass directly through InetAddress.
		final byte[] address = InetAddress.getByName(s).getAddress();
		if (address.length > 4) throw new UnknownHostException("Not IPv4");
		return Ints.fromByteArray(address);
	} catch (final UnknownHostException e) {
		throw new ConfigurationException("Malformed IPv4 " + s + " for blacklisting", e);
	}
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:19,代码来源:RuntimeConfiguration.java

示例5: dataToTarget

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
@Override
protected HAServiceTarget dataToTarget(byte[] data) {
  int index = Ints.fromByteArray(data);
  return DummyHAService.getInstance(index);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:6,代码来源:MiniZKFCCluster.java

示例6: toInt

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
public static int toInt(byte[] bytes) {
	return Ints.fromByteArray(bytes);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:4,代码来源:NumberUtil.java


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