diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/helper/ChannelBufferTools.java | 31 | ||||
-rw-r--r-- | src/org/traccar/protocol/WondexFrameDecoder.java | 9 |
2 files changed, 4 insertions, 36 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index ae6dfc830..d8d74b6ea 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -25,37 +25,6 @@ public final class ChannelBufferTools { } /** - * Find string in network buffer - */ - public static Integer find( - ChannelBuffer buf, - Integer start, - Integer finish, - String subString) { - - int index = start; - boolean match; - - for (; index < finish; index++) { - match = true; - - for (int i = 0; i < subString.length(); i++) { - char c = (char) buf.getByte(index + i); - if (c != subString.charAt(i)) { - match = false; - break; - } - } - - if (match) { - return index; - } - } - - return null; - } - - /** * Convert hex to integer (length in hex digits) */ public static int readHexInteger(ChannelBuffer buf, int length) { diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java index 1a66c9373..eee112e9d 100644 --- a/src/org/traccar/protocol/WondexFrameDecoder.java +++ b/src/org/traccar/protocol/WondexFrameDecoder.java @@ -20,6 +20,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.StringFinder; public class WondexFrameDecoder extends FrameDecoder { @@ -27,9 +28,7 @@ public class WondexFrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { if (buf.readableBytes() < KEEP_ALIVE_LENGTH) { return null; @@ -45,8 +44,8 @@ public class WondexFrameDecoder extends FrameDecoder { } else { - Integer index = ChannelBufferTools.find(buf, buf.readerIndex(), buf.writerIndex(), "\r\n"); - if (index != null) { + int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + if (index != -1) { ChannelBuffer frame = buf.readBytes(index - buf.readerIndex()); buf.skipBytes(2); return frame; |