本文整理匯總了Java中com.google.common.primitives.Ints.toByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Ints.toByteArray方法的具體用法?Java Ints.toByteArray怎麽用?Java Ints.toByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.primitives.Ints
的用法示例。
在下文中一共展示了Ints.toByteArray方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public void setUp() throws Exception {
super.setUp();
zkServer = getServer(serverFactory);
for (int i = 0; i < NUM_ELECTORS; i++) {
cbs[i] = Mockito.mock(ActiveStandbyElectorCallback.class);
appDatas[i] = Ints.toByteArray(i);
electors[i] = new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), cbs[i],
CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
}
}
示例2: setResponseException
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public void setResponseException(RpcCallException responseException) {
this.responseException = responseException;
if (featureFlag.equals("true")) {
when(httpResponse.getStatus()).thenReturn(responseException.getCategory().getHttpStatus());
}
String response = "{\"error\":" + responseException.toJson() + ",\"result\":{}}";
when(httpResponse.getContentAsString()).thenReturn(response);
RpcEnvelope.Response pbResponse = RpcEnvelope.Response.newBuilder().
setError(responseException.toJson().toString()).build();
byte[] responseArray = pbResponse.toByteArray();
byte[] headerLength = Ints.toByteArray(responseArray.length);
byte[] bodyLength = Ints.toByteArray(0);
byte[] overallPayload = concatAll(headerLength, responseArray, bodyLength);
when(httpResponse.getContent()).thenReturn(overallPayload);
}
示例3: testNegativeHeaderLength
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Test
public void testNegativeHeaderLength() throws Exception {
byte[] data = Ints.toByteArray(-1);
Throwable thrown = catchThrowable( () -> new ProtobufRpcResponse(data));
assertThat(thrown).isExactlyInstanceOf(RpcCallException.class);
assertThat(thrown).hasFieldOrPropertyWithValue("category", RpcCallException.Category.InternalServerError);
}
示例4: sendMessage
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
public void sendMessage(NSDictionary message) throws IOException {
byte[] messageBytes = BinaryPropertyListWriter.writeToArray(message);
byte[] lengthBytes = Ints.toByteArray(messageBytes.length);
socketOut.write(lengthBytes);
socketOut.write(messageBytes);
}
示例5: testReceiveMessage
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Test
public void testReceiveMessage() throws IOException {
NSDictionary inputMessage = new NSDictionary();
inputMessage.put("goodbye", "world");
byte[] messageBytes = BinaryPropertyListWriter.writeToArray(inputMessage);
byte[] lengthBytes = Ints.toByteArray(messageBytes.length);
byte[] inputBytes = new byte[messageBytes.length + 4];
System.arraycopy(lengthBytes, 0, inputBytes, 0, 4);
System.arraycopy(messageBytes, 0, inputBytes, 4, messageBytes.length);
FakeSocket fakeSocket = new FakeSocket(inputBytes);
try (InspectorSocket socket = new BinaryPlistSocket(fakeSocket)) {
assertThat(socket.receiveMessage().get()).isEqualTo(inputMessage);
}
}
示例6: testReceiveEOF
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Test
public void testReceiveEOF() throws IOException {
NSDictionary inputMessage = new NSDictionary();
inputMessage.put("goodbye", "world");
byte[] messageBytes = BinaryPropertyListWriter.writeToArray(inputMessage);
byte[] lengthBytes = Ints.toByteArray(messageBytes.length + 1);
byte[] inputBytes = new byte[messageBytes.length + 4];
System.arraycopy(lengthBytes, 0, inputBytes, 0, 4);
System.arraycopy(messageBytes, 0, inputBytes, 4, messageBytes.length);
FakeSocket fakeSocket = new FakeSocket(inputBytes);
try (InspectorSocket socket = new BinaryPlistSocket(fakeSocket)) {
assertThat(socket.receiveMessage().isPresent()).isFalse();
}
}
示例7: targetToData
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
@Override
protected byte[] targetToData(HAServiceTarget target) {
return Ints.toByteArray(((DummyHAService)target).index);
}
示例8: intToSwitchId
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public static String intToSwitchId(int i){
byte[] ib = Ints.toByteArray(i);
return String.format("DE:AD:BE:EF:%02x:%02x:%02x:%02x",ib[0],ib[1],ib[2],ib[3]);
}
示例9: toBytes
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
public static byte[] toBytes(int value) {
return Ints.toByteArray(value);
}
示例10: validateLen
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* Throws exception if length is not correct.
*
* @param errorCode Error code
* @param subErrCode Sub Error Code
* @param length erroneous length
* @throws BgpParseException for erroneous length
*/
public static void validateLen(byte errorCode, byte subErrCode, int length) throws BgpParseException {
byte[] errLen = Ints.toByteArray(length);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errLen);
throw new BgpParseException(errorCode, subErrCode, buffer);
}
示例11: validateType
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
/**
* Throws exception if type is not correct.
*
* @param errorCode Error code
* @param subErrCode Sub Error Code
* @param type erroneous type
* @throws BgpParseException for erroneous type
*/
public static void validateType(byte errorCode, byte subErrCode, int type) throws BgpParseException {
byte[] errType = Ints.toByteArray(type);
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(errType);
throw new BgpParseException(errorCode, subErrCode, buffer);
}