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


Java ChannelBuffer类代码示例

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


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

示例1: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the BGP link attributes Opaque link attribute.
 *
 * @param cb Channel buffer
 * @return object of type BgpLinkAttrOpaqLnkAttrib
 * @throws BgpParseException while parsing BgpLinkAttrOpaqLnkAttrib
 */
public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb)
        throws BgpParseException {

    byte[] opaqueLinkAttribute;

    short lsAttrLength = cb.readShort();

    if (cb.readableBytes() < lsAttrLength) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                               BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                               lsAttrLength);
    }

    opaqueLinkAttribute = new byte[lsAttrLength];
    cb.readBytes(opaqueLinkAttribute);

    return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:BgpLinkAttrOpaqLnkAttrib.java

示例2: prepareBgpMessage

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Prepares BGP message.
 *
 * @param type the BGP message type
 * @param payload the message payload to transmit (BGP header excluded)
 * @return the message to transmit (BGP header included)
 */
static ChannelBuffer prepareBgpMessage(int type, ChannelBuffer payload) {
    ChannelBuffer message =
        ChannelBuffers.buffer(BgpConstants.BGP_HEADER_LENGTH +
                              payload.readableBytes());

    // Write the marker
    for (int i = 0; i < BgpConstants.BGP_HEADER_MARKER_LENGTH; i++) {
        message.writeByte(0xff);
    }

    // Write the rest of the BGP header
    message.writeShort(BgpConstants.BGP_HEADER_LENGTH +
                       payload.readableBytes());
    message.writeByte(type);

    // Write the payload
    message.writeBytes(payload);
    return message;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:BgpMessage.java

示例3: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the BGP link attributes of TE default metric.
 *
 * @param cb Channel buffer
 * @return object of type BgpLinkAttrTeDefaultMetric
 * @throws BgpParseException while parsing BgpLinkAttrTeDefaultMetric
 */
public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb)
        throws BgpParseException {
    int linkTeMetric;

    short lsAttrLength = cb.readShort();

    if ((lsAttrLength != TE_DATA_LEN)
            || (cb.readableBytes() < lsAttrLength)) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                               BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                               lsAttrLength);
    }

    linkTeMetric = cb.readInt();

    return new BgpLinkAttrTeDefaultMetric(linkTeMetric);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:BgpLinkAttrTeDefaultMetric.java

示例4: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the channel buffer and returns object.
 *
 * @param cb channelBuffer
 * @return object of flow spec packet length
 * @throws BgpParseException while parsing BgpFsPacketLength
 */
public static BgpFsPacketLength read(ChannelBuffer cb) throws BgpParseException {
    List<BgpFsOperatorValue> operatorValue = new LinkedList<>();
    byte option;
    short packetLen;

    do {
        option = (byte) cb.readByte();
        int len = (option & Constants.BGP_FLOW_SPEC_LEN_MASK) >> 4;
        if ((1 << len) == 1) {
            packetLen = cb.readByte();
            operatorValue.add(new BgpFsOperatorValue(option, new byte[] {(byte) packetLen}));
        } else {
            packetLen = cb.readShort();
            operatorValue.add(new BgpFsOperatorValue(option,
                              new byte[] {(byte) (packetLen >> 8), (byte) packetLen}));
        }
    } while ((option & Constants.BGP_FLOW_SPEC_END_OF_LIST_MASK) == 0);

    return new BgpFsPacketLength(operatorValue);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:BgpFsPacketLength.java

示例5: run

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
@Override
public void run(Timeout timeout) throws Exception {
    if (timeout.isCancelled()) {
        return;
    }
    if (!ctx.getChannel().isOpen()) {
        return;
    }

    log.debug("BGP Session Timeout: peer {}", remoteInfo.address());
    //
    // ERROR: Invalid Optional Parameter Length field: Unspecific
    //
    // Send NOTIFICATION and close the connection
    int errorCode = BgpConstants.Notifications.HoldTimerExpired.ERROR_CODE;
    int errorSubcode = BgpConstants.Notifications.ERROR_SUBCODE_UNSPECIFIC;
    ChannelBuffer txMessage =
        BgpNotification.prepareBgpNotification(errorCode, errorSubcode,
                                               null);
    ctx.getChannel().write(txMessage);
    closeChannel(ctx);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:BgpSession.java

示例6: bgpUpdateMessageTest23

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * In this test case, Mandatory attributes are not given in input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest23() 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, 0x00, 0x29, 0x02, 0x00, 0x00, //withdrawn len
            0x00, 0x12, //path attribute len
            0x0e, 0x01, 0x01, 0x00, //origin
            0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path
            (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; //med

    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,代码行数:26,代码来源:BgpUpdateMsgTest.java

示例7: parseIdentification

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {

        int length = buf.readUnsignedShort();
        String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII);
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);

        if (channel != null) {
            ChannelBuffer response = ChannelBuffers.directBuffer(1);
            if (deviceSession != null) {
                response.writeByte(1);
            } else {
                response.writeByte(0);
            }
            channel.write(response);
        }
        return deviceSession;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:TeltonikaProtocolDecoder.java

示例8: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the LS attribute node name.
 *
 * @param cb ChannelBuffer
 * @return object of BgpAttrNodeName
 * @throws BgpParseException while parsing BgpAttrNodeName
 */
public static BgpAttrNodeName read(ChannelBuffer cb)
        throws BgpParseException {
    byte[] nodeName;

    short lsAttrLength = cb.readShort();

    if (cb.readableBytes() < lsAttrLength) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                               BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                               lsAttrLength);
    }

    nodeName = new byte[lsAttrLength];
    cb.readBytes(nodeName);
    return BgpAttrNodeName.of(nodeName);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:BgpAttrNodeName.java

示例9: write

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
@Override
public void write(ChannelBuffer cb, PcepKeepaliveMsgVer1 message) {
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer
    int msgLenIndex = cb.writerIndex();
    cb.writeShort((short) 0);
    // update message length field
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:PcepKeepaliveMsgVer1.java

示例10: sendReply

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28);
    reply.writeByte('M');
    reply.writeByte('C');
    reply.writeByte('G');
    reply.writeByte('P');
    reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
    reply.writeInt((int) deviceId);
    reply.writeByte(commandCount++);
    reply.writeInt(0); // authentication code
    reply.writeByte(0);
    reply.writeByte(packetNumber);
    reply.writeZero(11);

    byte checksum = 0;
    for (int i = 4; i < 27; i++) {
        checksum += reply.getByte(i);
    }
    reply.writeByte(checksum);

    if (channel != null) {
        channel.write(reply, remoteAddress);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:25,代码来源:CellocatorProtocolDecoder.java

示例11: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the channel buffer and returns object.
 *
 * @param cb channelBuffer
 * @return object of flow spec TCP flags
 * @throws BgpParseException while parsing BgpFsTcpFlags
 */
public static BgpFsTcpFlags read(ChannelBuffer cb) throws BgpParseException {
    List<BgpFsOperatorValue> operatorValue = new LinkedList<>();
    byte option;
    short tcpFlag;

    do {
        option = (byte) cb.readByte();
        int len = (option & Constants.BGP_FLOW_SPEC_LEN_MASK) >> 4;
        if ((1 << len) == 1) {
            tcpFlag = cb.readByte();
            operatorValue.add(new BgpFsOperatorValue(option, new byte[] {(byte) tcpFlag}));
        } else {
            tcpFlag = cb.readShort();
            operatorValue.add(new BgpFsOperatorValue(option, new byte[] {(byte) (tcpFlag >> 8), (byte) tcpFlag}));
        }

    } while ((option & Constants.BGP_FLOW_SPEC_END_OF_LIST_MASK) == 0);

    return new BgpFsTcpFlags(operatorValue);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:28,代码来源:BgpFsTcpFlags.java

示例12: writeFile

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
public String writeFile(String uniqueId, ChannelBuffer buf, String extension) {
    int size = buf.readableBytes();
    String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + "." + extension;
    try (FileOutputStream output = new FileOutputStream(createFile(uniqueId, name));
            FileChannel fileChannel = output.getChannel()) {
        ByteBuffer byteBuffer = buf.toByteBuffer();
        int written = 0;
        while (written < size) {
            written += fileChannel.write(byteBuffer);
        }
        fileChannel.force(false);
        return name;
    } catch (IOException e) {
        Log.warning(e);
    }
    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:MediaManager.java

示例13: encodeContent

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

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeByte('S');
        buf.writeByte('S');
        buf.writeShort(2 + 2 + 2 + content.readableBytes() + 4 + 2 + 2);
        buf.writeShort(type);
        buf.writeBytes(content);
        buf.writeInt(0x0B);
        buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
        buf.writeByte('\r');
        buf.writeByte('\n');

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

示例14: parseCommandResponse

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
private Position parseCommandResponse(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
    if (deviceSession == null) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());

    getLastLocation(position, null);

    int responseTextLength = buf.bytesBefore((byte) 0);
    if (responseTextLength < 0) {
        responseTextLength = CMD_RESPONSE_SIZE - 3;
    }
    position.set(Position.KEY_RESULT, buf.readBytes(responseTextLength).toString(StandardCharsets.UTF_8));

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

示例15: read

import org.jboss.netty.buffer.ChannelBuffer; //导入依赖的package包/类
/**
 * Reads the channel buffer and returns object of IPReachabilityInformationTlv.
 *
 * @param cb ChannelBuffer
 * @param length of value field
 * @return object of IPReachabilityInformationTlv
 */
public static IPReachabilityInformationTlv read(ChannelBuffer cb, short length) {
    byte preficLen = cb.readByte();
    byte[] prefix;
    if (preficLen == 0) {
        prefix = new byte[] {0};
    } else {
        int len = preficLen / ONE_BYTE_LEN;
        int reminder = preficLen % ONE_BYTE_LEN;
        if (reminder > 0) {
            len = len + 1;
        }
        prefix = new byte[len];
        cb.readBytes(prefix, 0, len);
    }
    return IPReachabilityInformationTlv.of(preficLen, prefix, length);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:IPReachabilityInformationTlv.java


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