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


Java ChannelBuffers类代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffers的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffers类的具体用法?Java ChannelBuffers怎么用?Java ChannelBuffers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: sendResponse

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
private static void sendResponse(Channel channel, int device, long id, int crc) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
        response.writeByte(device);
        response.writeByte(MSG_ACK);
        response.writeInt((int) id);
        response.writeShort(crc);
        response.writeShort(Checksum.crc16(
                Checksum.CRC16_XMODEM, response.toByteBuffer()));

        ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
        encoded.writeByte(0x01); // header
        while (response.readable()) {
            int b = response.readByte();
            if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
                encoded.writeByte(0x10);
                b += 0x20;
            }
            encoded.writeByte(b);
        }
        encoded.writeByte(0x04); // ending
        channel.write(encoded);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:25,代码来源:MxtProtocolDecoder.java

示例2: sendAcceptedReply

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
private void sendAcceptedReply(RpcCall call, SocketAddress remoteAddress,
    AcceptState acceptState, ChannelHandlerContext ctx) {
  RpcAcceptedReply reply = RpcAcceptedReply.getInstance(call.getXid(),
      acceptState, Verifier.VERIFIER_NONE);

  XDR out = new XDR();
  reply.write(out);
  if (acceptState == AcceptState.PROG_MISMATCH) {
    out.writeInt(lowProgVersion);
    out.writeInt(highProgVersion);
  }
  ChannelBuffer b = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(b, remoteAddress);
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:RpcProgram.java

示例3: testReadFromBuffer

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Tests readFromBuffer() method.
 */
@Test
public void testReadFromBuffer() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet1));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet2));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet3));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet4));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet5));
    ospfMessageReader.readFromBuffer(channelBuffer);
    assertThat(ospfMessageReader, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:OspfMessageReaderTest.java

示例4: testExtractBadEvent3

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Test bad event format 3: Empty priority - <>
 */
@Test
public void testExtractBadEvent3() {
  String badData1 = "<> bad bad data\n";
  SyslogUtils util = new SyslogUtils(false);
  ChannelBuffer buff = ChannelBuffers.buffer(100);
  buff.writeBytes(badData1.getBytes());
  Event e = util.extractEvent(buff);
  if (e == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers = e.getHeaders();
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
                      headers.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestSyslogUtils.java

示例5: encode

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    log.debug("Sending message");
    if (!(msg instanceof List)) {
        log.debug("Invalid msg.");
        return msg;
    }

    @SuppressWarnings("unchecked")
    List<PcepMessage> msglist = (List<PcepMessage>) msg;

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    for (PcepMessage pm : msglist) {
        pm.writeTo(buf);
    }

    HexDump.pcepHexDump(buf);

    return buf;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:PcepMessageEncoder.java

示例6: encodeContent

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeInt(0);
        buf.writeInt(content.length() + 10);
        buf.writeByte(TeltonikaProtocolDecoder.CODEC_12);
        buf.writeByte(1); // quantity
        buf.writeByte(5); // type
        buf.writeInt(content.length() + 2);
        buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
        buf.writeByte('\r');
        buf.writeByte('\n');
        buf.writeByte(1); // quantity
        buf.writeInt(Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer(8, buf.writerIndex() - 8)));

        return buf;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:TeltonikaProtocolEncoder.java

示例7: bgpUpdateMessageTest29

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * In this test case, update message without total Path Attribute Length field is given as
 * input and expecting an exception.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest29() throws BgpParseException {
    byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, //marker
            0x00, 0x16, 0x02, 0x00, 0x01, 0x00};

    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();

    message = reader.readFrom(buffer, bgpHeader);

    assertThat(message, instanceOf(BgpUpdateMsg.class));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:BgpUpdateMsgTest.java

示例8: encodeContent

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 12 + 56);

        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
        buf.writeByte(0);
        buf.writeShort(buf.capacity());
        buf.writeShort(NoranProtocolDecoder.MSG_CONTROL);
        buf.writeInt(0); // gis ip
        buf.writeShort(0); // gis port
        buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
        buf.writerIndex(buf.writerIndex() + 50 - content.length());
        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));

        return buf;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:NoranProtocolEncoder.java

示例9: testReadFrom

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Tests readFrom()  method.
 */
@Test
public void testReadFrom() throws Exception {
    opqueHeader = new OpaqueLsaHeader();
    opqueHeader.setLsType(11);
    opqueHeader.setLsPacketLen(48);
    opqueHeader.setLsCheckSum(10);
    opqueHeader.setAge(4);
    opqueHeader.setOpaqueId(1);
    opqueHeader.setOpaqueType(11);
    opqueHeader.setLsSequenceNo(250);
    opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
    opqueHeader.setOptions(2);
    opaqueLsa11 = new OpaqueLsa11(opqueHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(packet);
    opaqueLsa11.readFrom(channelBuffer);
    assertThat(opaqueLsa11, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:OpaqueLsa11Test.java

示例10: testGetLsaBodyAsByteArray2

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Tests getLsaBodyAsByteArray() method.
 */
@Test(expected = Exception.class)
public void testGetLsaBodyAsByteArray2() throws Exception {
    opqueHeader = new OpaqueLsaHeader();
    opqueHeader.setLsType(10);
    opqueHeader.setLsPacketLen(48);
    opqueHeader.setLsCheckSum(10);
    opqueHeader.setAge(4);
    opqueHeader.setOpaqueId(1);
    opqueHeader.setOpaqueType(10);
    opqueHeader.setLsSequenceNo(250);
    opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
    opqueHeader.setOptions(2);
    opaqueLsa10 = new OpaqueLsa10(opqueHeader);
    linkTlv = new LinkTlv(new TlvHeader());
    opaqueLsa10.addValue(linkTlv);
    channelBuffer = ChannelBuffers.copiedBuffer(packet);
    opaqueLsa10.readFrom(channelBuffer);
    result = opaqueLsa10.getLsaBodyAsByteArray();
    assertThat(result, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:OpaqueLsa10Test.java

示例11: openMessageTest5

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * In this test case, Invalid version is given as input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void openMessageTest5() throws BgpParseException {

    // OPEN Message with invalid version number.
    byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, 0x00, 0x1d, 0x01, 0X05,
            (byte) 0xfe, 0x09, 0x00, (byte) 0xb4,
            (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f,
            0x00};

    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);

    assertThat(message, instanceOf(BgpOpenMsg.class));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:29,代码来源:BgpOpenMsgTest.java

示例12: testReadFrom

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(tlv);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv1);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv2);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv3);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:IpExtendedReachabilityTlvTest.java

示例13: testReadFrom

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    ospfExternalDestination = new OspfExternalDestination();
    ospfExternalDestination.setExternalRouterTag(2);
    ospfExternalDestination.setMetric(100);
    ospfExternalDestination.setType1orType2Metric(true);
    externalLsa.addExternalDestination(ospfExternalDestination);
    ospfExternalDestination1 = new OspfExternalDestination();
    ospfExternalDestination.setExternalRouterTag(3);
    ospfExternalDestination.setMetric(50);
    ospfExternalDestination.setType1orType2Metric(true);
    externalLsa.addExternalDestination(ospfExternalDestination1);
    ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
    inputByteArray = createByteForNetworkLsa();
    lsaHeader = createLsaHeader();
    externalLsa = new ExternalLsa(lsaHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
    externalLsa.readFrom(channelBuffer);
    assertThat(externalLsa, is(notNullValue()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:ExternalLsaTest.java

示例14: encodeContent

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeByte(0x67);
        buf.writeByte(0x67);
        buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK);
        buf.writeShort(2 + 1 + 4 + content.length()); // length
        buf.writeShort(0); // index

        buf.writeByte(0x01); // command
        buf.writeInt(0); // server id
        buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));

        return buf;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:17,代码来源:EelinkProtocolEncoder.java

示例15: pcepUpdateMsgTest17

import org.jboss.netty.buffer.ChannelBuffers; //导入依赖的package包/类
/**
 * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object,LSPA
 * metric object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest17() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00,
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object

    byte[] testupdateMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testupdateMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testupdateMsg = new byte[readLen];
    buf.readBytes(testupdateMsg, 0, readLen);

    assertThat(testupdateMsg, is(updateMsg));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:39,代码来源:PcepUpdateMsgExtTest.java


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