本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例5: dataToTarget
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
protected HAServiceTarget dataToTarget(byte[] data) {
int index = Ints.fromByteArray(data);
return DummyHAService.getInstance(index);
}
示例6: toInt
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public static int toInt(byte[] bytes) {
return Ints.fromByteArray(bytes);
}