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


Java ChannelBuffers.buffer方法代码示例

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


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

示例1: testExtractBadEvent1

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Test bad event format 1: Priority is not numeric
 */
@Test
public void testExtractBadEvent1() {
  String badData1 = "<10F> 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

示例2: testExtractBadEvent2

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Test bad event format 2: The first char is not <
 */
@Test
public void testExtractBadEvent2() {
  String badData1 = "hi guys! <10> 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

示例3: prepareBgpUpdateNotificationDataPayload

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Prepares BGP UPDATE Notification data payload.
 *
 * @param attrTypeCode the attribute type code
 * @param attrLen the attribute length (in octets)
 * @param attrFlags the attribute flags
 * @param message the message with the data
 * @return the buffer with the data payload for the BGP UPDATE Notification
 */
private static ChannelBuffer prepareBgpUpdateNotificationDataPayload(
                                    int attrTypeCode,
                                    int attrLen,
                                    int attrFlags,
                                    ChannelBuffer message) {
    // Compute the attribute length field octets
    boolean extendedLengthBit = ((0x10 & attrFlags) != 0);
    int attrLenOctets = 1;
    if (extendedLengthBit) {
        attrLenOctets = 2;
    }
    ChannelBuffer data =
        ChannelBuffers.buffer(attrLen + attrLenOctets + 1);
    data.writeByte(attrTypeCode);
    if (extendedLengthBit) {
        data.writeShort(attrLen);
    } else {
        data.writeByte(attrLen);
    }
    data.writeBytes(message, attrLen);
    return data;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:32,代码来源:BgpUpdate.java

示例4: testExtractBadEvent4

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Test bad event format 4: Priority too long
 */
@Test
public void testExtractBadEvent4() {
  String badData1 = "<123123123123123123123123123123> 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: testExtractGoodEvent

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Good event
 */
@Test
public void testExtractGoodEvent() {
  String priority = "<10>";
  String goodData1 = "Good good good data\n";
  SyslogUtils util = new SyslogUtils(false);
  ChannelBuffer buff = ChannelBuffers.buffer(100);
  buff.writeBytes((priority + goodData1).getBytes());
  Event e = util.extractEvent(buff);
  if (e == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers = e.getHeaders();
  Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(null, headers.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(priority + goodData1.trim(),
                      new String(e.getBody()).trim());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:TestSyslogUtils.java

示例6: encodePackedPrefixes

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Encodes a collection of IPv4 network prefixes in a packed format.
 * <p>
 * The IPv4 prefixes are encoded in the form:
 * <Length, Prefix> where Length is the length in bits of the IPv4 prefix,
 * and Prefix is the IPv4 prefix (padded with trailing bits to the end
 * of an octet).
 *
 * @param prefixes the prefixes to encode
 * @return the buffer with the encoded prefixes
 */
private ChannelBuffer encodePackedPrefixes(Collection<Ip4Prefix> prefixes) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    // Write each of the prefixes
    for (Ip4Prefix prefix : prefixes) {
        int prefixBitlen = prefix.prefixLength();
        int prefixBytelen = (prefixBitlen + 7) / 8;         // Round-up
        message.writeByte(prefixBitlen);

        Ip4Address address = prefix.address();
        long value = address.toInt() & 0xffffffffL;
        for (int i = 0; i < Ip4Address.BYTE_LENGTH; i++) {
            if (prefixBytelen-- == 0) {
                break;
            }
            long nextByte =
                (value >> ((Ip4Address.BYTE_LENGTH - i - 1) * 8)) & 0xff;
            message.writeByte((int) nextByte);
        }
    }

    return message;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:TestBgpPeerChannelHandler.java

示例7: prepareBgpOpen

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Prepares BGP OPEN message.
 *
 * @param localInfo the BGP Session local information to use
 * @return the message to transmit (BGP header included)
 */
static ChannelBuffer prepareBgpOpen(BgpSessionInfo localInfo) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    //
    // Prepare the OPEN message payload
    //
    message.writeByte(localInfo.bgpVersion());
    message.writeShort((int) localInfo.asNumber());
    message.writeShort((int) localInfo.holdtime());
    message.writeInt(localInfo.bgpId().toInt());

    // Prepare the optional BGP Capabilities
    ChannelBuffer capabilitiesMessage =
        prepareBgpOpenCapabilities(localInfo);
    message.writeByte(capabilitiesMessage.readableBytes());
    message.writeBytes(capabilitiesMessage);

    return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_OPEN,
                                        message);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:BgpOpen.java

示例8: sendResponse

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
private static void sendResponse(
        Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, ChannelBuffer msg) {

    if (channel != null) {
        ChannelBuffer buf = ChannelBuffers.buffer(
                2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2);

        buf.writeByte('@');
        buf.writeByte('@');
        buf.writeShort(buf.capacity());
        buf.writeBytes(id);
        buf.writeShort(type);
        buf.writeBytes(msg);
        buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
        buf.writeByte('\r');
        buf.writeByte('\n');

        channel.write(buf, remoteAddress);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:MeiligaoProtocolDecoder.java

示例9: 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

示例10: prepareBgpNotification

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Prepares BGP NOTIFICATION message.
 *
 * @param errorCode the BGP NOTIFICATION Error Code
 * @param errorSubcode the BGP NOTIFICATION Error Subcode if applicable,
 * otherwise BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC
 * @param data the BGP NOTIFICATION Data if applicable, otherwise null
 * @return the message to transmit (BGP header included)
 */
static ChannelBuffer prepareBgpNotification(int errorCode,
                                            int errorSubcode,
                                            ChannelBuffer data) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    //
    // Prepare the NOTIFICATION message payload
    //
    message.writeByte(errorCode);
    message.writeByte(errorSubcode);
    if (data != null) {
        message.writeBytes(data);
    }
    return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_NOTIFICATION,
                                        message);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:BgpNotification.java

示例11: handle

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestDelegationTokenRemoteFetcher.java

示例12: checkHeader

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
public static void checkHeader(String keepFields, String msg1, String stamp1, String format1,
                               String host1, String data1) throws ParseException {
  SyslogUtils util;
  if (keepFields == null || keepFields.isEmpty()) {
    util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE, new HashSet<String>(), false);
  } else {
    util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE,
                           SyslogUtils.chooseFieldsToKeep(keepFields),
                           false);
  }
  ChannelBuffer buff = ChannelBuffers.buffer(200);

  buff.writeBytes(msg1.getBytes());
  Event e = util.extractEvent(buff);
  if (e == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers2 = e.getHeaders();
  if (stamp1 == null) {
    Assert.assertFalse(headers2.containsKey("timestamp"));
  } else {
    SimpleDateFormat formater = new SimpleDateFormat(format1, Locale.ENGLISH);
    Assert.assertEquals(String.valueOf(formater.parse(stamp1).getTime()),
                        headers2.get("timestamp"));
  }
  if (host1 == null) {
    Assert.assertFalse(headers2.containsKey("host"));
  } else {
    String host2 = headers2.get("host");
    Assert.assertEquals(host2, host1);
  }
  Assert.assertEquals(data1, new String(e.getBody()));
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:34,代码来源:TestSyslogUtils.java

示例13: testBadEventBadEvent

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Test
public void testBadEventBadEvent() {
  String badData1 = "hi guys! <10F> bad bad data\n";
  SyslogUtils util = new SyslogUtils(false);
  ChannelBuffer buff = ChannelBuffers.buffer(100);
  buff.writeBytes(badData1.getBytes());
  String badData2 = "hi guys! <20> bad bad data\n";
  buff.writeBytes((badData2).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());

  Event e2 = util.extractEvent(buff);

  if (e2 == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers2 = e2.getHeaders();
  Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
                      headers2.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(badData2.trim(), new String(e2.getBody()).trim());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:33,代码来源:TestSyslogUtils.java

示例14: encode

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {

    byte[] byteMsg = (byte[]) msg;
    log.debug("Encoding ospfMessage of length {}", byteMsg.length);
    ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length);
    channelBuffer.writeBytes(byteMsg);

    return channelBuffer;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:11,代码来源:OspfMessageEncoder.java

示例15: prepareBgpKeepalive

import org.jboss.netty.buffer.ChannelBuffers; //导入方法依赖的package包/类
/**
 * Prepares BGP KEEPALIVE message.
 *
 * @return the message to transmit (BGP header included)
 */
static ChannelBuffer prepareBgpKeepalive() {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_MESSAGE_MAX_LENGTH);

    //
    // Prepare the KEEPALIVE message payload: nothing to do
    //
    return BgpMessage.prepareBgpMessage(BgpConstants.BGP_TYPE_KEEPALIVE,
                                        message);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:BgpKeepalive.java


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