aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-10-02 11:15:46 -0700
committerAnton Tananaev <anton@traccar.org>2022-10-02 11:15:46 -0700
commitb06dd882bf7b8e2067240d5957315499836138c8 (patch)
tree092032f6c347f2659c31cce6931d4b507f2eb663 /src/main
parentf7c662f04af49e29f992ab8b4c9ea24d768a32d8 (diff)
downloadtrackermap-server-b06dd882bf7b8e2067240d5957315499836138c8.tar.gz
trackermap-server-b06dd882bf7b8e2067240d5957315499836138c8.tar.bz2
trackermap-server-b06dd882bf7b8e2067240d5957315499836138c8.zip
Update Java dependencies
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/helper/BufferUtil.java18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/helper/BufferUtil.java b/src/main/java/org/traccar/helper/BufferUtil.java
index 0dbe0a4ad..d1025f548 100644
--- a/src/main/java/org/traccar/helper/BufferUtil.java
+++ b/src/main/java/org/traccar/helper/BufferUtil.java
@@ -59,16 +59,16 @@ public final class BufferUtil {
}
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 originalReaderIndex = haystack.readerIndex();
+ int originalWriterIndex = haystack.writerIndex();
+ try {
+ haystack.readerIndex(startIndex);
+ haystack.writerIndex(endIndex);
+ return ByteBufUtil.indexOf(needle, haystack);
+ } finally {
+ haystack.readerIndex(originalReaderIndex);
+ haystack.writerIndex(originalWriterIndex);
}
- int result = ByteBufUtil.indexOf(needle, wrappedHaystack);
- return result < 0 ? result : startIndex + result;
}
}