本文整理汇总了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);
}
}
示例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);
}
示例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()));
}
示例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());
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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()));
}
示例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()));
}
示例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));
}
示例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));
}
示例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()));
}
示例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;
}
示例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));
}