當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelBuffer.markReaderIndex方法代碼示例

本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.markReaderIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.markReaderIndex方法的具體用法?Java ChannelBuffer.markReaderIndex怎麽用?Java ChannelBuffer.markReaderIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.markReaderIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public void read(ChannelBuffer cb) throws PcepParseException {
    PcepObjectHeader tempObjHeader;

    while (0 < cb.readableBytes()) {
        cb.markReaderIndex();
        tempObjHeader = PcepObjectHeader.read(cb);
        cb.resetReaderIndex();
        byte yObjClass = tempObjHeader.getObjClass();
        if ((yObjClass != PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjClass != PcepLSObjectVer1.LS_OBJ_CLASS)
                && (yObjClass != PcepErrorObjectVer1.ERROR_OBJ_CLASS)) {
            throw new PcepParseException("Unknown Object is present in PCEP-ERROR. Object Class: " + yObjClass);
        }

        this.errList.add(PcepErrorVer1.read(cb));
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:18,代碼來源:PcepErrorInfoVer1.java

示例2: parseErrorObjectList

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse error-obj-list.
 *
 * @param llErrObjList error object list output
 * @param cb channel buffer input
 * @throws PcepParseException if mandatory fields are missing
 * @return error object header
 */
public PcepObjectHeader parseErrorObjectList(List<PcepErrorObject> llErrObjList, ChannelBuffer cb)
        throws PcepParseException {
    PcepObjectHeader tempObjHeader = null;

    while (0 < cb.readableBytes()) {
        cb.markReaderIndex();
        tempObjHeader = PcepObjectHeader.read(cb);
        cb.resetReaderIndex();
        if (tempObjHeader.getObjClass() == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
            llErrObjList.add(PcepErrorObjectVer1.read(cb));
        } else {
            break;
        }
    }
    return tempObjHeader;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:PcepErrorMsgVer1.java

示例3: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads channel buffer and returns object of StatefulRsvpErrorSpecTlv.
 *
 * @param cb of type channel buffer
 * @return object of StatefulRsvpErrorSpecTlv
 * @throws PcepParseException while parsing this tlv from channel buffer
 */
public static PcepValueType read(ChannelBuffer cb) throws PcepParseException {

    PcepRsvpErrorSpec rsvpErrSpecObj = null;
    PcepRsvpSpecObjHeader rsvpErrSpecObjHeader;

    cb.markReaderIndex();
    rsvpErrSpecObjHeader = PcepRsvpSpecObjHeader.read(cb);
    cb.resetReaderIndex();

    if (PcepRsvpIpv4ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
            && PcepRsvpIpv4ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
        rsvpErrSpecObj = PcepRsvpIpv4ErrorSpec.read(cb);
    } else if (PcepRsvpIpv6ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
            && PcepRsvpIpv6ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
        rsvpErrSpecObj = PcepRsvpIpv6ErrorSpec.read(cb);
    } else if (PcepRsvpUserErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
            && PcepRsvpUserErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
        rsvpErrSpecObj = PcepRsvpUserErrorSpec.read(cb);
    }
    return new StatefulRsvpErrorSpecTlv(rsvpErrSpecObj);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:StatefulRsvpErrorSpecTlv.java

示例4: dump

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Dump the buffer content in hex format.
 *
 * @param buff buffer content to dump in hex format
 */
public static void dump(ChannelBuffer buff) {
    buff.markReaderIndex();
    try {
        do {
            StringBuilder sb = new StringBuilder();
            for (int k = 0; (k < 16) && (buff.readableBytes() != 0); ++k) {
                if (0 == k % 4) {
                    sb.append(String.format(" ")); // blank after 4 bytes
                }
                sb.append(String.format("%02X ", buff.readByte()));
            }
            log.debug(sb.toString());
        } while (buff.readableBytes() != 0);
    } catch (Exception e) {
        log.error("[HexDump] Invalid buffer: " + e.toString());
    }
    buff.resetReaderIndex();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:HexDump.java

示例5: ChannelBufferStreamInput

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
public ChannelBufferStreamInput(ChannelBuffer buffer, int length) {
    if (length > buffer.readableBytes()) {
        throw new IndexOutOfBoundsException();
    }
    this.buffer = buffer;
    startIndex = buffer.readerIndex();
    endIndex = startIndex + length;
    buffer.markReaderIndex();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:10,代碼來源:ChannelBufferStreamInput.java

示例6: decode

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
    ChannelBuffer buf) {

  if (buf.readableBytes() < 4)
    return null;

  buf.markReaderIndex();

  byte[] fragmentHeader = new byte[4];
  buf.readBytes(fragmentHeader);
  int length = XDR.fragmentSize(fragmentHeader);
  boolean isLast = XDR.isLastFragment(fragmentHeader);

  if (buf.readableBytes() < length) {
    buf.resetReaderIndex();
    return null;
  }

  ChannelBuffer newFragment = buf.readSlice(length);
  if (currentFrame == null) {
    currentFrame = newFragment;
  } else {
    currentFrame = ChannelBuffers.wrappedBuffer(currentFrame, newFragment);
  }

  if (isLast) {
    ChannelBuffer completeFrame = currentFrame;
    currentFrame = null;
    return completeFrame;
  } else {
    return null;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:RpcUtil.java

示例7: decode

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
        ChannelBuffer buffer) throws Exception {
    log.debug("Message received.");
    if (!channel.isConnected()) {
        log.info("Channel is not connected.");
        // In testing, I see decode being called AFTER decode last.
        // This check avoids that from reading corrupted frames
        return null;
    }

    HexDump.pcepHexDump(buffer);

    // Buffer can contain multiple messages, also may contain out of bound message.
    // Read the message one by one from buffer and parse it. If it encountered out of bound message,
    // then mark the reader index and again take the next chunk of messages from the channel
    // and parse again from the marked reader index.
    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    List<PcepMessage> msgList = (List<PcepMessage>) ctx.getAttachment();

    if (msgList == null) {
        msgList = new LinkedList<>();
    }

    try {
        while (buffer.readableBytes() > 0) {
            buffer.markReaderIndex();
            PcepMessage message = reader.readFrom(buffer);
            msgList.add(message);
        }
        ctx.setAttachment(null);
        return msgList;
    } catch (PcepOutOfBoundMessageException e) {
        log.debug("PCEP message decode error");
        buffer.resetReaderIndex();
        buffer.discardReadBytes();
        ctx.setAttachment(msgList);
    }
    return null;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:41,代碼來源:PcepMessageDecoder.java

示例8: parseMetricList

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse list for MeticObject.
 *
 * @param cb of type channel buffer
 * @return true if parsing metric list is success
 * @throws PcepParseException when a non metric object is received
 */
public boolean parseMetricList(ChannelBuffer cb) throws PcepParseException {

    if (llMetricList == null) {
        llMetricList = new LinkedList<>();
    }

    PcepMetricObject metriclist;

    //caller should verify for metric object
    byte yObjClass = PcepMetricObjectVer1.METRIC_OBJ_CLASS;
    byte yObjType = PcepMetricObjectVer1.METRIC_OBJ_TYPE;

    while ((yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS)
            && (yObjType == PcepMetricObjectVer1.METRIC_OBJ_TYPE)) {

        metriclist = PcepMetricObjectVer1.read(cb);
        llMetricList.add(metriclist);
        yObjClass = 0;
        yObjType = 0;

        if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
            cb.markReaderIndex();
            PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
            cb.resetReaderIndex();
            yObjClass = tempObjHeader.getObjClass();
            yObjType = tempObjHeader.getObjType();
        }
    }
    return true;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:38,代碼來源:PcepAttributeVer1.java

示例9: checkNextObject

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Checks whether there is a more object or not.
 *
 * @param cb of type channel buffer
 * @return instance of object header
 */
private static byte checkNextObject(ChannelBuffer cb) {
    if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
        return 0;
    }
    cb.markReaderIndex();
    PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
    cb.resetReaderIndex();
    return tempObjHeader.getObjClass();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:PcepAttributeVer1.java

示例10: 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;
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:40,代碼來源:PcepErrorVer1.java

示例11: parseLSList

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Parse LS List from the channel buffer.
 *
 * @param cb of type channel buffer
 * @throws PcepParseException if mandatory fields are missing
 */
public void parseLSList(ChannelBuffer cb) throws PcepParseException {
    byte yObjClass;
    byte yObjType;

    lsObjList = new LinkedList<>();

    // caller should verify for LS object
    if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
        log.debug("Unable to find LS Object");
        return;
    }

    cb.markReaderIndex();
    PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
    cb.resetReaderIndex();
    yObjClass = tempObjHeader.getObjClass();
    yObjType = tempObjHeader.getObjType();
    PcepLSObject lsObj;
    while ((yObjClass == PcepLSObjectVer1.LS_OBJ_CLASS) && ((yObjType == PcepLSObjectVer1.LS_OBJ_TYPE_NODE_VALUE)
            || (yObjType == PcepLSObjectVer1.LS_OBJ_TYPE_LINK_VALUE))) {
        lsObj = PcepLSObjectVer1.read(cb);
        lsObjList.add(lsObj);

        if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
            cb.markReaderIndex();
            tempObjHeader = PcepObjectHeader.read(cb);
            cb.resetReaderIndex();
            yObjClass = tempObjHeader.getObjClass();
            yObjType = tempObjHeader.getObjType();
        } else {
            break;
        }
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:41,代碼來源:PcepErrorVer1.java

示例12: parseErrObjList

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * parseErrObjList from the channel buffer.
 *
 * @param cb of type channel buffer
 * @throws PcepParseException if mandatory fields are missing
 */
public void parseErrObjList(ChannelBuffer cb) throws PcepParseException {
    byte yObjClass;
    byte yObjType;
    boolean bIsErrorObjFound = false;

    errObjList = new LinkedList<>();

    // caller should verify for RP object
    if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
        throw new PcepParseException("Unable to find PCEP-ERROR Object");
    }

    cb.markReaderIndex();
    PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
    cb.resetReaderIndex();
    yObjClass = tempObjHeader.getObjClass();
    yObjType = tempObjHeader.getObjType();
    PcepErrorObject errorObject;
    while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) {
        errorObject = PcepErrorObjectVer1.read(cb);
        errObjList.add(errorObject);
        bIsErrorObjFound = true;

        if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
            cb.markReaderIndex();
            tempObjHeader = PcepObjectHeader.read(cb);
            cb.resetReaderIndex();
            yObjClass = tempObjHeader.getObjClass();
            yObjType = tempObjHeader.getObjType();
        } else {
            break;
        }
    }

    if (!bIsErrorObjFound) {
        throw new PcepParseException("At least one PCEP-ERROR Object should be present.");
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:45,代碼來源:PcepErrorVer1.java

示例13: read

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Reads the byte stream of PcepError from channel buffer.
 *
 * @param cb of type channel buffer
 * @return PcepError error part of PCEP-ERROR
 * @throws PcepParseException if mandatory fields are missing
 */
public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException {
    if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
        throw new PcepParseException("Unknown Object");
    }

    PcepErrorVer1 pcepError = new PcepErrorVer1();
    // check whether any PCEP Error Info is present
    cb.markReaderIndex();
    PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
    cb.resetReaderIndex();
    byte yObjClass = tempObjHeader.getObjClass();

    //If RPlist present then store it.RPList and LSList are optional
    if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) {
        log.debug("RP_LIST");
        pcepError.parseRPList(cb);
        yObjClass = checkNextObject(cb);
    } else if (yObjClass == PcepLSObjectVer1.LS_OBJ_CLASS) {
        log.debug("LS_LIST");
        pcepError.parseLSList(cb);
        yObjClass = checkNextObject(cb);
    }

    if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
        log.debug("PCEP-ERROR obj list");
        pcepError.parseErrObjList(cb);
        yObjClass = checkNextObject(cb);
    }

    return pcepError;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:39,代碼來源:PcepErrorVer1.java

示例14: checkNextObject

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
/**
 * Checks Next Object.
 *
 * @param cb of type channel buffer.
 * @return object type class.
 */
private static byte checkNextObject(ChannelBuffer cb) {
    if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
        return 0;
    }
    cb.markReaderIndex();
    PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
    cb.resetReaderIndex();
    return tempObjHeader.getObjClass();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:PcepErrorVer1.java

示例15: decode

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    log.debug("MESSAGE IS RECEIVED.");
    if (!channel.isConnected()) {
        log.info("Channel is not connected.");
        return null;
    }

    HexDump.dump(buffer);

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    List<BgpMessage> msgList = (List<BgpMessage>) ctx.getAttachment();

    if (msgList == null) {
        msgList = new LinkedList<>();
    }

    try {
        while (buffer.readableBytes() > 0) {
            buffer.markReaderIndex();
            BgpHeader bgpHeader = new BgpHeader();
            BgpMessage message = reader.readFrom(buffer, bgpHeader);
            msgList.add(message);
        }

        return msgList;
    } catch (Exception e) {
        log.debug("Bgp protocol message decode error");
        buffer.resetReaderIndex();
        buffer.discardReadBytes();
        ctx.setAttachment(msgList);
    }
    return null;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:35,代碼來源:BgpMessageDecoder.java


注:本文中的org.jboss.netty.buffer.ChannelBuffer.markReaderIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。