aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/helper/BufferUtil.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-11-05 16:48:27 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-11-05 16:48:27 -0700
commit10a11e03fbb45506973c85ae49d0fd1443d0f9f1 (patch)
treecadcbe287fc14b0c9300b73163938539254fa89e /src/main/java/org/traccar/helper/BufferUtil.java
parentf8e6bc5ced2244f5f09664e7d778c0bf51cd4ab9 (diff)
downloadtrackermap-server-10a11e03fbb45506973c85ae49d0fd1443d0f9f1.tar.gz
trackermap-server-10a11e03fbb45506973c85ae49d0fd1443d0f9f1.tar.bz2
trackermap-server-10a11e03fbb45506973c85ae49d0fd1443d0f9f1.zip
Support new Xexun protocol (fix #4727)
Diffstat (limited to 'src/main/java/org/traccar/helper/BufferUtil.java')
-rw-r--r--src/main/java/org/traccar/helper/BufferUtil.java27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/helper/BufferUtil.java b/src/main/java/org/traccar/helper/BufferUtil.java
index b086f0f9e..bbf12d738 100644
--- a/src/main/java/org/traccar/helper/BufferUtil.java
+++ b/src/main/java/org/traccar/helper/BufferUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2021 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,19 +28,28 @@ public final class BufferUtil {
}
public static int indexOf(String needle, ByteBuf haystack) {
- ByteBuf needleBuffer = Unpooled.wrappedBuffer(needle.getBytes(StandardCharsets.US_ASCII));
+ return indexOf(needle, haystack, haystack.readerIndex(), haystack.writerIndex());
+ }
+
+ public static int indexOf(String needle, ByteBuf haystack, int startIndex, int endIndex) {
+ ByteBuf wrappedNeedle = Unpooled.wrappedBuffer(needle.getBytes(StandardCharsets.US_ASCII));
try {
- return ByteBufUtil.indexOf(needleBuffer, haystack);
+ return indexOf(wrappedNeedle, haystack, startIndex, endIndex);
} finally {
- needleBuffer.release();
+ wrappedNeedle.release();
}
}
- public static int indexOf(String needle, ByteBuf haystack, int startIndex, int endIndex) {
- ByteBuf wrappedHaystack = Unpooled.wrappedBuffer(haystack);
- wrappedHaystack.readerIndex(startIndex - haystack.readerIndex());
- wrappedHaystack.writerIndex(endIndex - haystack.readerIndex());
- int result = indexOf(needle, wrappedHaystack);
+ public static int indexOf(ByteBuf needle, ByteBuf haystack, int startIndex, int endIndex) {
+ ByteBuf wrappedHaystack;
+ if (startIndex == haystack.readerIndex() && endIndex == haystack.writerIndex()) {
+ wrappedHaystack = haystack;
+ } else {
+ wrappedHaystack = Unpooled.wrappedBuffer(haystack);
+ wrappedHaystack.readerIndex(startIndex - haystack.readerIndex());
+ wrappedHaystack.writerIndex(endIndex - haystack.readerIndex());
+ }
+ int result = ByteBufUtil.indexOf(needle, wrappedHaystack);
return result < 0 ? result : haystack.readerIndex() + startIndex + result;
}