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


Java Ints.toByteArray方法代码示例

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

示例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);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:16,代码来源:RpcClientIntegrationTest.java

示例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);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:10,代码来源:ProtobufRpcResponseTest.java

示例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);
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:8,代码来源:BinaryPlistSocket.java

示例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);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:16,代码来源:BinaryPlistSocketTest.java

示例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();
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:16,代码来源:BinaryPlistSocketTest.java

示例7: targetToData

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

示例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]);
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:5,代码来源:TopologyBuilder.java

示例9: toBytes

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

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

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


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