本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.readableBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.readableBytes方法的具體用法?Java ChannelBuffer.readableBytes怎麽用?Java ChannelBuffer.readableBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.readableBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseLocalNodeDescriptors
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Parse local node descriptors.
*
* @param cb ChannelBuffer
* @param protocolId protocol identifier
* @return object of this BGPNodeLSIdentifier
* @throws BgpParseException while parsing local node descriptors
*/
public static BgpNodeLSIdentifier parseLocalNodeDescriptors(ChannelBuffer cb, byte protocolId)
throws BgpParseException {
log.debug("parse Local node descriptor");
ChannelBuffer tempBuf = cb.copy();
short type = cb.readShort();
short length = cb.readShort();
if (cb.readableBytes() < length) {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
tempBuf.readBytes(cb.readableBytes() + Constants.TYPE_AND_LEN));
}
NodeDescriptors nodeDescriptors = new NodeDescriptors();
ChannelBuffer tempCb = cb.readBytes(length);
if (type == NodeDescriptors.LOCAL_NODE_DES_TYPE) {
nodeDescriptors = NodeDescriptors.read(tempCb, length, type, protocolId);
} else {
throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.MALFORMED_ATTRIBUTE_LIST, null);
}
return new BgpNodeLSIdentifier(nodeDescriptors);
}
示例2: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads the BGP link attributes of Maximum link bandwidth.
*
* @param cb Channel buffer
* @param type type of this tlv
* @return object of type BgpLinkAttrMaxLinkBandwidth
* @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth
*/
public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type)
throws BgpParseException {
float maxBandwidth;
short lsAttrLength = cb.readShort();
if ((lsAttrLength != MAX_BANDWIDTH_LEN)
|| (cb.readableBytes() < lsAttrLength)) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS;
return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type);
}
示例3: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Check minimum length
if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
return null;
}
// Check for sync packet
if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
ChannelBuffer syncMessage = buf.readBytes(8);
if (channel != null) {
channel.write(syncMessage);
}
}
return super.decode(ctx, channel, buf);
}
示例4: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from channel buffer and populate instance.
*
* @param channelBuffer channel buffer instance
* @throws OspfParseException might throws exception while parsing buffer
*/
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
try {
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.setNetworkMask(Ip4Address.valueOf(tempByteArray));
//add all the attached routers
while (channelBuffer.readableBytes() > 0) {
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
this.addAttachedRouter(Ip4Address.valueOf(tempByteArray));
}
} catch (Exception e) {
log.debug("Error::NetworkLSA::readFrom:: {}", e.getMessage());
throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
}
}
示例5: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {
while (channelBuffer.readableBytes() >= OspfUtil.LSREQUEST_LENGTH) {
LsRequestPacket lsRequestPacket = new LsRequestPacket();
lsRequestPacket.setLsType(channelBuffer.readInt());
byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
lsRequestPacket.setLinkStateId(Ip4Address.valueOf(tempByteArray).toString());
tempByteArray = new byte[OspfUtil.FOUR_BYTES];
channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
lsRequestPacket.setOwnRouterId(Ip4Address.valueOf(tempByteArray).toString());
this.addLinkStateRequests(lsRequestPacket);
}
}
示例6: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
return null;
}
if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
ChannelBuffer heartbeat = buf.readBytes(12);
if (channel != null) {
channel.write(heartbeat);
}
}
return super.decode(ctx, channel, buf);
}
示例7: read
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads the Opaque Prefix Attribute.
*
* @param cb ChannelBuffer
* @return object of BgpPrefixAttrOpaqueData
* @throws BgpParseException while parsing BgpPrefixAttrOpaqueData
*/
public static BgpPrefixAttrOpaqueData read(ChannelBuffer cb)
throws BgpParseException {
byte[] opaquePrefixAttribute;
short lsAttrLength = cb.readShort();
opaquePrefixAttribute = new byte[lsAttrLength];
if (cb.readableBytes() < lsAttrLength) {
Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
lsAttrLength);
}
cb.readBytes(opaquePrefixAttribute);
return BgpPrefixAttrOpaqueData.of(opaquePrefixAttribute);
}
示例8: start
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private Status start(ChannelBuffer buffer, boolean last) {
logger.trace("start blob upload");
assert (transferId == null);
StartBlobRequest request = new StartBlobRequest(
index,
Hex.decodeHex(digest),
new BytesArray(buffer.array()),
last
);
transferId = request.transferId();
size += buffer.readableBytes();
startResponse = client.execute(StartBlobAction.INSTANCE, request).actionGet();
status = startResponse.status();
return status;
}
示例9: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
throws Exception {
if (!channel.isConnected()) {
return null;
}
if (buffer.readableBytes() < FpmHeader.FPM_HEADER_LENGTH) {
return null;
}
buffer.markReaderIndex();
short version = buffer.readUnsignedByte();
short type = buffer.readUnsignedByte();
int length = buffer.readUnsignedShort();
buffer.resetReaderIndex();
if (buffer.readableBytes() < length) {
// Not enough bytes to read a whole message
return null;
}
byte[] fpmMessage = new byte[length];
buffer.readBytes(fpmMessage);
return FpmHeader.decode(fpmMessage, 0, fpmMessage.length);
}
示例10: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void readFrom(ChannelBuffer channelBuffer) {
this.setAdjacencyType(channelBuffer.readByte());
this.setLocalCircuitId(channelBuffer.readInt());
if (channelBuffer.readableBytes() > 0) {
byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
this.setNeighborSystemId(IsisUtil.systemId(tempByteArray));
this.setNeighborLocalCircuitId(channelBuffer.readInt());
}
}
示例11: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public PcepReportMsg readFrom(ChannelBuffer cb) throws PcepParseException {
if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Received packet size " + cb.readableBytes()
+ " is less than the expected size: " + PACKET_MINIMUM_LENGTH);
}
llStateReportList = new LinkedList<>();
byte version = cb.readByte();
version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
if (version != PACKET_VERSION) {
throw new PcepParseException(" Invalid version: " + version);
}
byte type = cb.readByte();
if (type != MSG_TYPE.getType()) {
throw new PcepParseException("Unexpected type: " + type);
}
short length = cb.readShort();
if (length < PACKET_MINIMUM_LENGTH) {
throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
+ length);
}
// parse state report list
parseStateReportList(cb);
return new PcepReportMsgVer1(llStateReportList);
}
示例12: decode
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Skip Alive message
while (buf.readable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
buf.readByte();
}
// Check minimum length
if (buf.readableBytes() < 11) {
return null;
}
// Read flags
int version = buf.getUnsignedByte(buf.readerIndex() + 1);
int offset = 1 + 1 + 3;
if ((version & 0x80) != 0) {
offset += 4;
}
// Get data length
int length = buf.getUnsignedShort(buf.readerIndex() + offset);
offset += 2;
if ((version & 0x40) != 0) {
offset += 3;
}
length += offset; // add header
// Return buffer
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
return null;
}
示例13: parseRPList
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Parse RP List from the channel buffer.
*
* @param cb of type channel buffer
* @throws PcepParseException if mandatory fields are missing
*/
public void parseRPList(ChannelBuffer cb) throws PcepParseException {
byte yObjClass;
byte yObjType;
rpObjList = new LinkedList<>();
// caller should verify for RP object
if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
log.debug("Unable to find RP Object");
return;
}
cb.markReaderIndex();
PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
PcepRPObject rpObj;
while ((yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjType == PcepRPObjectVer1.RP_OBJ_TYPE)) {
rpObj = PcepRPObjectVer1.read(cb);
rpObjList.add(rpObj);
if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
cb.markReaderIndex();
tempObjHeader = PcepObjectHeader.read(cb);
cb.resetReaderIndex();
yObjClass = tempObjHeader.getObjClass();
yObjType = tempObjHeader.getObjType();
} else {
break;
}
}
}
示例14: processBgpKeepalive
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Processes BGP KEEPALIVE message.
*
* @param ctx the Channel Handler Context.
* @param message the message to process.
*/
private void processBgpKeepalive(ChannelHandlerContext ctx,
ChannelBuffer message) {
if (message.readableBytes() + BgpConstants.BGP_HEADER_LENGTH !=
BgpConstants.BGP_KEEPALIVE_EXPECTED_LENGTH) {
// ERROR: Bad Message Length. Close the channel.
ctx.getChannel().close();
return;
}
// BGP KEEPALIVE message successfully received
receivedKeepaliveMessageLatch.countDown();
}
示例15: readFrom
import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
* Reads from the channel buffer and populate this instance.
*
* @param channelBuffer channel buffer instance
*/
public void readFrom(ChannelBuffer channelBuffer) {
byte[] tempByteArray = new byte[IsisUtil.ID_PLUS_ONE_BYTE];
channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_PLUS_ONE_BYTE);
this.setNeighborId(IsisUtil.systemIdPlus(tempByteArray));
this.setMetric(channelBuffer.readUnsignedMedium());
int nTlvPresent = channelBuffer.readByte();
if (nTlvPresent > 0) {
while (channelBuffer.readableBytes() > IsisUtil.TWO_BYTES) {
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(channelBuffer.readByte());
tlvHeader.setTlvLength(channelBuffer.readByte());
SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType());
int tlvLength = tlvHeader.tlvLength();
if (tlvValue != null) {
if (channelBuffer.readableBytes() >= tlvLength) {
TrafficEngineeringSubTlv subTlv =
SubTlvFinder.findSubTlv(tlvHeader, channelBuffer.readBytes(tlvHeader.tlvLength()));
if (subTlv != null) {
this.addSubTlv(subTlv);
}
}
} else {
if (channelBuffer.readableBytes() >= tlvLength) {
channelBuffer.readBytes(tlvLength);
}
}
}
}
}