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


Java ChannelBuffer.indexOf方法代码示例

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


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

示例1: decode

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

    ChannelBuffer result = (ChannelBuffer) super.decode(ctx, channel, buf);

    if (result != null) {

        int index = result.indexOf(result.readerIndex(), result.writerIndex(), (byte) '$');
        if (index == -1) {
            return result;
        } else {
            result.skipBytes(index);
            return result.readBytes(result.readableBytes());
        }

    }

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

示例2: decode

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

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

    int spaceIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ' ');
    if (spaceIndex == -1) {
        return null;
    }

    int endIndex = buf.indexOf(spaceIndex, buf.writerIndex(), (byte) ',');
    if (endIndex == -1) {
        return null;
    }

    return buf.readBytes(endIndex + 1);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:JpKorjarFrameDecoder.java

示例3: 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;
    }

    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
    if (index != -1) {
        int length = index - buf.readerIndex() + Integer.parseInt(
                buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, StandardCharsets.US_ASCII));
        if (buf.readableBytes() >= length) {
            return buf.readBytes(length);
        }
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:20,代码来源:MeitrackFrameDecoder.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() < BINARY_HEADER) {
        return null;
    }

    if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
        buf.skipBytes(BINARY_HEADER);
    }

    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
    if (index != -1 && index + 1 < buf.writerIndex()) {
        ChannelBuffer result = buf.readBytes(index - buf.readerIndex());
        buf.skipBytes(2);
        return result;
    }

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

示例5: decode

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

    int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')') + 1;
    if (endIndex > 0) {

        ChannelBuffer frame = ChannelBuffers.dynamicBuffer();

        while (buf.readerIndex() < endIndex) {
            int b = buf.readByte();
            if (b == '=') {
                frame.writeByte(buf.readByte() ^ '=');
            } else {
                frame.writeByte(b);
            }
        }

        return frame;

    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:25,代码来源:Vt200FrameDecoder.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() < 80) {
        return null;
    }

    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
    if (index == -1) {
        index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
        if (index == -1) {
            return null;
        }
    }

    index += 2; // checksum

    if (buf.readableBytes() >= index - buf.readerIndex()) {
        return buf.readBytes(index - buf.readerIndex());
    }

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

示例7: decode

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

    ChannelBuffer buf = (ChannelBuffer) msg;

    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
    index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');

    String type = buf.toString(index + 1, 3, StandardCharsets.US_ASCII);
    switch (type) {
        case "D03":
            if (channel != null) {
                DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
                String imei = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId();
                String content = "D00,camera_picture.jpg,0";
                int length = 1 + imei.length() + 1 + content.length() + 5;
                String response = String.format("@@O%02d,%s,%s*", length, imei, content);
                response += Checksum.sum(response) + "\r\n";
                channel.write(response);
            }
            return null;
        case "CCC":
            return decodeBinaryMessage(channel, remoteAddress, buf);
        default:
            return decodeRegularMessage(channel, remoteAddress, buf);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:29,代码来源:MeitrackProtocolDecoder.java

示例8: readString

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private static String readString(ChannelBuffer buf) {
    String result = null;
    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
    if (index > buf.readerIndex()) {
        result = buf.readBytes(index - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
    }
    buf.readByte();
    return result;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:10,代码来源:AtrackProtocolDecoder.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;
    }

    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

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

示例11: 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;
    }

    int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("$$"));
    if (beginIndex == -1) {
        return null;
    } else if (beginIndex > buf.readerIndex()) {
        buf.readerIndex(beginIndex);
    }

    int length;

    int flagIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("AA"));
    if (flagIndex != -1 && flagIndex - beginIndex == 6) {
        length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 4, StandardCharsets.US_ASCII));
    } else {
        length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, StandardCharsets.US_ASCII), 16);
    }

    if (length <= buf.readableBytes()) {
        return buf.readBytes(length);
    }

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

示例12: decode

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

    int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
    if (endIndex > 0) {
        endIndex += 1 + 3;
        if (buf.writerIndex() >= endIndex) {
            return buf.readBytes(endIndex - buf.readerIndex());
        }
    }

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

示例13: decode

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

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

    int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x7e);
    if (index != -1) {
        ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());

        while (buf.readerIndex() <= index) {
            int b = buf.readUnsignedByte();
            if (b == 0x7d) {
                int ext = buf.readUnsignedByte();
                if (ext == 0x01) {
                    result.writeByte(0x7d);
                } else if (ext == 0x02) {
                    result.writeByte(0x7e);
                }
            } else {
                result.writeByte(b);
            }
        }

        return result;
    }

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

示例14: decode

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

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

    int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xC0);
    if (index != -1) {
        ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());

        while (buf.readerIndex() <= index) {
            int b = buf.readUnsignedByte();
            if (b == 0xDB) {
                int ext = buf.readUnsignedByte();
                if (ext == 0xDC) {
                    result.writeByte(0xC0);
                } else if (ext == 0xDD) {
                    result.writeByte(0xDB);
                }
            } else {
                result.writeByte(b);
            }
        }

        return result;
    }

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

示例15: decode

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

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

    long length = buf.getUnsignedInt(buf.readerIndex());

    if (length < 1024) {
        if (buf.readableBytes() >= length + 4) {
            buf.readUnsignedInt();
            return buf.readBytes((int) length);
        }
    } else {
        int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
        if (endIndex >= 0) {
            ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
            buf.readByte();
            if (frame.readableBytes() > 0) {
                return frame;
            }
        }
    }

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


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