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


Java ChannelBuffer.getByte方法代碼示例

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


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

示例1: decode

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    ChannelBuffer buf = (ChannelBuffer) msg;
    char first = (char) buf.getByte(0);

    if (first == '$') {
        return decodeBinary(buf, channel, remoteAddress);
    } else if (first == '(') {
        String sentence = buf.toString(StandardCharsets.US_ASCII);
        if (sentence.contains("W01")) {
            return decodeW01(sentence, channel, remoteAddress);
        } else {
            return decodeU01(sentence, channel, remoteAddress);
        }
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:21,代碼來源:Jt600ProtocolDecoder.java

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

示例3: decode

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

    if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) {
        buf.skipBytes(HANDSHAKE_LENGTH);
        header = false;
    }

    int end = 8; // IMEI

    while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) {
        end += buf.getUnsignedShort(buf.readerIndex() + end) + 2;

        if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) {
            return buf.readBytes(end + 1);
        }
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:24,代碼來源:BceFrameDecoder.java

示例4: decode

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

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

    char type = (char) buf.getByte(buf.readerIndex());

    if (type == '$') {
        boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75;
        int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10;
        if (length >= buf.readableBytes()) {
            return buf.readBytes(length);
        }
    } else if (type == '(') {
        int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
        if (endIndex != -1) {
            return buf.readBytes(endIndex + 1);
        }
    } else {
        throw new ParseException(null, 0); // unknown message
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:28,代碼來源:Jt600FrameDecoder.java

示例5: encodeContent

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
        buf.writeByte('M');
        buf.writeByte('C');
        buf.writeByte('G');
        buf.writeByte('P');
        buf.writeByte(0);
        buf.writeInt(Integer.parseInt(getUniqueId(deviceId)));
        buf.writeByte(0); // command numerator
        buf.writeInt(0); // authentication code
        buf.writeByte(command);
        buf.writeByte(command);
        buf.writeByte(data1);
        buf.writeByte(data1);
        buf.writeByte(data2);
        buf.writeByte(data2);
        buf.writeInt(0); // command specific data

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

        return buf;
    }
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:28,代碼來源:CellocatorProtocolEncoder.java

示例6: decode

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

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

    int length = 2 + 2; // head and tail

    if (buf.getByte(buf.readerIndex()) == 0x78) {
        length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2);
    } else {
        length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2);
    }

    if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) {
        return buf.readBytes(length);
    }

    int endIndex = buf.readerIndex() - 1;
    do {
        endIndex = buf.indexOf(endIndex + 1, buf.writerIndex(), (byte) 0x0d);
        if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) {
            return buf.readBytes(endIndex + 2 - buf.readerIndex());
        }
    } while (endIndex > 0);

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:31,代碼來源:Gt06FrameDecoder.java

示例7: checksum

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private static byte checksum(ChannelBuffer buf, int end) {
    byte result = 0;
    for (int i = 0; i < end; i++) {
        result += buf.getByte(buf.readerIndex() + i);
    }
    return result;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:8,代碼來源:BceFrameDecoder.java

示例8: isBinary

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
public static boolean isBinary(ChannelBuffer buf) {
    String header = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
    if (header.equals("+ACK")) {
        return buf.getByte(buf.readerIndex() + header.length()) != (byte) ':';
    } else {
        return BINARY_HEADERS.contains(header);
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:9,代碼來源:Gl200FrameDecoder.java

示例9: decode

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

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

    if (Character.isDigit(buf.getByte(buf.readerIndex()))) {
        int length = 4 + Integer.parseInt(buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII));
        if (buf.readableBytes() >= length) {
            return buf.readBytes(length);
        }
    } else {
        while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') {
            buf.skipBytes(1);
        }
        int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
        if (delimiter == -1) {
            delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!');
        }
        if (delimiter != -1) {
            ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex());
            buf.skipBytes(1);
            return result;
        }
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:31,代碼來源:MegastekFrameDecoder.java

示例10: bufferStartsWith

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
private boolean bufferStartsWith(ChannelBuffer buffer, int readerIndex, String method) {
    char[] chars = method.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (buffer.getByte(readerIndex + i) != chars[i]) {
            return false;
        }
    }

    return true;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,代碼來源:SizeHeaderFrameDecoder.java

示例11: isCompressed

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public boolean isCompressed(ChannelBuffer buffer) {
    if (buffer.readableBytes() < HEADER.length) {
        return false;
    }
    final int offset = buffer.readerIndex();
    for (int i = 0; i < HEADER.length; ++i) {
        if (buffer.getByte(offset + i) != HEADER[i]) {
            return false;
        }
    }
    return true;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:14,代碼來源:DeflateCompressor.java

示例12: isCompressed

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public boolean isCompressed(ChannelBuffer buffer) {
    int offset = buffer.readerIndex();
    return buffer.readableBytes() >= 3 &&
            buffer.getByte(offset) == LZFChunk.BYTE_Z &&
            buffer.getByte(offset + 1) == LZFChunk.BYTE_V &&
            (buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_COMPRESSED || buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_NON_COMPRESSED);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:9,代碼來源:LZFCompressor.java

示例13: readFrom

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException, PcepOutOfBoundMessageException {

    if (!bb.readable()) {
        throw new PcepParseException("Empty message received");
    }

    /*
     * 0                   1                   2                   3
     * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     * | Ver |  Flags  |                                               |
     * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     *
     * Currently Version 1 is supported
     * Currently no flags are used, it is all ignored
     */

    byte packetVersion = bb.getByte(bb.readerIndex());
    packetVersion = (byte) (packetVersion >> SHIFT_FLAG);
    PcepFactory factory;

    switch (packetVersion) {

    case 1:
        factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE;
        break;
    default:
        throw new PcepParseException("Unknown Packet version: " + packetVersion);
    }
    return factory.getReader().readFrom(bb);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:33,代碼來源:PcepFactories.java

示例14: decode

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

    char marker = (char) buf.getByte(buf.readerIndex());

    while (marker != '*' && marker != '$' && marker != 'X' && buf.readableBytes() > 0) {
        buf.skipBytes(1);
        if (buf.readableBytes() > 0) {
            marker = (char) buf.getByte(buf.readerIndex());
        }
    }

    switch (marker) {
        case '*':

            // Return text message
            int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
            if (index != -1) {
                ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex());
                while (buf.readable()
                        && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
                    buf.readByte(); // skip new line
                }
                return result;
            }

            break;

        case '$':

            if (messageLength == 0) {
                if (buf.readableBytes() == MESSAGE_LONG) {
                    messageLength = MESSAGE_LONG;
                } else {
                    messageLength = MESSAGE_SHORT;
                }
            }

            if (buf.readableBytes() >= messageLength) {
                return buf.readBytes(messageLength);
            }

            break;

        case 'X':

            if (buf.readableBytes() >= MESSAGE_SHORT) {
                return buf.readBytes(MESSAGE_SHORT);
            }

            break;

        default:

            return null;
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:61,代碼來源:H02FrameDecoder.java

示例15: decode

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    if (buffer.readableBytes() < 6) {
        return null;
    }

    int readerIndex = buffer.readerIndex();
    if (buffer.getByte(readerIndex) != 'E' || buffer.getByte(readerIndex + 1) != 'S') {
        // special handling for what is probably HTTP
        if (bufferStartsWith(buffer, readerIndex, "GET ") ||
            bufferStartsWith(buffer, readerIndex, "POST ") ||
            bufferStartsWith(buffer, readerIndex, "PUT ") ||
            bufferStartsWith(buffer, readerIndex, "HEAD ") ||
            bufferStartsWith(buffer, readerIndex, "DELETE ") ||
            bufferStartsWith(buffer, readerIndex, "OPTIONS ") ||
            bufferStartsWith(buffer, readerIndex, "PATCH ") ||
            bufferStartsWith(buffer, readerIndex, "TRACE ")) {

            throw new HttpOnTransportException("This is not a HTTP port");
        }

        // we have 6 readable bytes, show 4 (should be enough)
        throw new StreamCorruptedException("invalid internal transport message format, got ("
                + Integer.toHexString(buffer.getByte(readerIndex) & 0xFF) + ","
                + Integer.toHexString(buffer.getByte(readerIndex + 1) & 0xFF) + ","
                + Integer.toHexString(buffer.getByte(readerIndex + 2) & 0xFF) + ","
                + Integer.toHexString(buffer.getByte(readerIndex + 3) & 0xFF) + ")");
    }

    int dataLen = buffer.getInt(buffer.readerIndex() + 2);
    if (dataLen == NettyHeader.PING_DATA_SIZE) {
        // discard the messages we read and continue, this is achieved by skipping the bytes
        // and returning null
        buffer.skipBytes(6);
        return null;
    }
    if (dataLen <= 0) {
        throw new StreamCorruptedException("invalid data length: " + dataLen);
    }
    // safety against too large frames being sent
    if (dataLen > NINETY_PER_HEAP_SIZE) {
        throw new TooLongFrameException(
                "transport content length received [" + new ByteSizeValue(dataLen) + "] exceeded [" + new ByteSizeValue(NINETY_PER_HEAP_SIZE) + "]");
    }

    if (buffer.readableBytes() < dataLen + 6) {
        return null;
    }
    buffer.skipBytes(6);
    return buffer;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:52,代碼來源:SizeHeaderFrameDecoder.java


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