From c40928cd674144fa5ed3dc7306c33b16823b2fad Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Jun 2018 11:53:11 +1200 Subject: Use slices instead of new buffers --- src/org/traccar/protocol/AdmProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/AlematicsFrameDecoder.java | 2 +- src/org/traccar/protocol/ApelProtocolDecoder.java | 2 +- src/org/traccar/protocol/AplicomFrameDecoder.java | 2 +- src/org/traccar/protocol/AplicomProtocolDecoder.java | 16 ++++++++-------- src/org/traccar/protocol/AstraProtocolDecoder.java | 2 +- src/org/traccar/protocol/At2000FrameDecoder.java | 2 +- src/org/traccar/protocol/At2000ProtocolDecoder.java | 2 +- src/org/traccar/protocol/AtrackFrameDecoder.java | 6 +++--- src/org/traccar/protocol/AtrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/AutoFonFrameDecoder.java | 2 +- src/org/traccar/protocol/AutoFonProtocolDecoder.java | 2 +- src/org/traccar/protocol/BceFrameDecoder.java | 2 +- src/org/traccar/protocol/BlackKiteProtocolDecoder.java | 2 +- src/org/traccar/protocol/CalAmpProtocolDecoder.java | 2 +- src/org/traccar/protocol/CastelProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/CellocatorFrameDecoder.java | 2 +- src/org/traccar/protocol/CityeasyProtocolDecoder.java | 2 +- src/org/traccar/protocol/DmtProtocolDecoder.java | 2 +- src/org/traccar/protocol/EelinkProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/EgtsFrameDecoder.java | 2 +- src/org/traccar/protocol/EgtsProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/EskyFrameDecoder.java | 4 ++-- src/org/traccar/protocol/GalileoFrameDecoder.java | 2 +- src/org/traccar/protocol/GalileoProtocolDecoder.java | 8 ++++---- src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/Gl200FrameDecoder.java | 4 ++-- src/org/traccar/protocol/Gps056FrameDecoder.java | 2 +- src/org/traccar/protocol/Gps056ProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/GranitFrameDecoder.java | 2 +- src/org/traccar/protocol/GranitProtocolDecoder.java | 2 +- src/org/traccar/protocol/Gt02ProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/Gt06FrameDecoder.java | 4 ++-- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 10 +++++----- src/org/traccar/protocol/H02FrameDecoder.java | 6 +++--- src/org/traccar/protocol/H02ProtocolDecoder.java | 2 +- src/org/traccar/protocol/HuaShengProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/HuabaoProtocolDecoder.java | 2 +- src/org/traccar/protocol/IntellitracFrameDecoder.java | 2 +- src/org/traccar/protocol/JpKorjarFrameDecoder.java | 2 +- src/org/traccar/protocol/Jt600FrameDecoder.java | 4 ++-- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 2 +- src/org/traccar/protocol/L100FrameDecoder.java | 2 +- src/org/traccar/protocol/MegastekFrameDecoder.java | 4 ++-- src/org/traccar/protocol/MeiligaoFrameDecoder.java | 2 +- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/MeitrackFrameDecoder.java | 2 +- src/org/traccar/protocol/MeitrackProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/NavigilFrameDecoder.java | 2 +- src/org/traccar/protocol/NoranProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/NvsFrameDecoder.java | 2 +- src/org/traccar/protocol/ObdDongleProtocolDecoder.java | 2 +- src/org/traccar/protocol/OigoProtocolDecoder.java | 6 +++--- src/org/traccar/protocol/OrionFrameDecoder.java | 4 ++-- src/org/traccar/protocol/PricolProtocolDecoder.java | 2 +- src/org/traccar/protocol/ProgressProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/Pt502FrameDecoder.java | 4 ++-- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 2 +- src/org/traccar/protocol/RecodaProtocolDecoder.java | 2 +- src/org/traccar/protocol/RoboTrackFrameDecoder.java | 2 +- src/org/traccar/protocol/RoboTrackProtocolDecoder.java | 2 +- src/org/traccar/protocol/RuptelaProtocolDecoder.java | 2 +- src/org/traccar/protocol/SabertekFrameDecoder.java | 2 +- src/org/traccar/protocol/SmokeyProtocolDecoder.java | 2 +- src/org/traccar/protocol/Stl060FrameDecoder.java | 2 +- src/org/traccar/protocol/T57FrameDecoder.java | 2 +- src/org/traccar/protocol/T800xProtocolDecoder.java | 2 +- src/org/traccar/protocol/TelicFrameDecoder.java | 4 ++-- src/org/traccar/protocol/TeltonikaFrameDecoder.java | 4 ++-- src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 8 ++++---- src/org/traccar/protocol/ThinkRaceProtocolDecoder.java | 2 +- src/org/traccar/protocol/Tk102ProtocolDecoder.java | 8 ++++---- src/org/traccar/protocol/Tk103FrameDecoder.java | 2 +- src/org/traccar/protocol/TlvProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/TmgFrameDecoder.java | 2 +- src/org/traccar/protocol/TotemFrameDecoder.java | 2 +- src/org/traccar/protocol/TramigoFrameDecoder.java | 2 +- src/org/traccar/protocol/TytanProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/TzoneProtocolDecoder.java | 4 ++-- src/org/traccar/protocol/UlbotechFrameDecoder.java | 2 +- src/org/traccar/protocol/UlbotechProtocolDecoder.java | 12 ++++++------ src/org/traccar/protocol/UproProtocolDecoder.java | 12 ++++++------ src/org/traccar/protocol/Vt200ProtocolDecoder.java | 2 +- src/org/traccar/protocol/VtfmsFrameDecoder.java | 2 +- src/org/traccar/protocol/WatchProtocolDecoder.java | 8 ++++---- src/org/traccar/protocol/WondexFrameDecoder.java | 4 ++-- src/org/traccar/protocol/XexunFrameDecoder.java | 2 +- src/org/traccar/protocol/Xt2400ProtocolDecoder.java | 4 ++-- 88 files changed, 158 insertions(+), 158 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/AdmProtocolDecoder.java b/src/org/traccar/protocol/AdmProtocolDecoder.java index 04a607749..4c41d29cd 100644 --- a/src/org/traccar/protocol/AdmProtocolDecoder.java +++ b/src/org/traccar/protocol/AdmProtocolDecoder.java @@ -132,7 +132,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { if (responseTextLength < 0) { responseTextLength = CMD_RESPONSE_SIZE - 3; } - position.set(Position.KEY_RESULT, buf.readBytes(responseTextLength).toString(StandardCharsets.UTF_8)); + position.set(Position.KEY_RESULT, buf.readSlice(responseTextLength).toString(StandardCharsets.UTF_8)); return position; } @@ -147,7 +147,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { if (size != CMD_RESPONSE_SIZE) { int type = buf.readUnsignedByte(); if (type == MSG_IMEI) { - getDeviceSession(channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.UTF_8)); + getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.UTF_8)); } else { return decodeData(channel, remoteAddress, buf, type); } diff --git a/src/org/traccar/protocol/AlematicsFrameDecoder.java b/src/org/traccar/protocol/AlematicsFrameDecoder.java index daac868c0..be7666657 100644 --- a/src/org/traccar/protocol/AlematicsFrameDecoder.java +++ b/src/org/traccar/protocol/AlematicsFrameDecoder.java @@ -38,7 +38,7 @@ public class AlematicsFrameDecoder extends LineBasedFrameDecoder { } if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) { - ByteBuf heartbeat = buf.readBytes(12); + ByteBuf heartbeat = buf.readRetainedSlice(12); if (ctx != null && ctx.channel() != null) { ctx.channel().writeAndFlush(new NetworkMessage(heartbeat, ctx.channel().remoteAddress())); } diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index bb99783f0..affbdedaf 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -111,7 +111,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { int length = buf.readUnsignedShortLE(); buf.skipBytes(length); length = buf.readUnsignedShortLE(); - getDeviceSession(channel, remoteAddress, buf.readBytes(length).toString(StandardCharsets.US_ASCII)); + getDeviceSession(channel, remoteAddress, buf.readSlice(length).toString(StandardCharsets.US_ASCII)); } else if (type == MSG_LAST_LOG_INDEX) { diff --git a/src/org/traccar/protocol/AplicomFrameDecoder.java b/src/org/traccar/protocol/AplicomFrameDecoder.java index 813bd49c6..6e81e8202 100644 --- a/src/org/traccar/protocol/AplicomFrameDecoder.java +++ b/src/org/traccar/protocol/AplicomFrameDecoder.java @@ -53,7 +53,7 @@ public class AplicomFrameDecoder extends BaseFrameDecoder { // Return buffer if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index b9da609ed..54b15700a 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -131,7 +131,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { ArrayList values = new ArrayList<>(count); for (int i = 0; i < count; i++) { - values.add(buf.readBytes(8)); + values.add(buf.readSlice(8)); } for (int i = 0; i < count; i++) { @@ -349,13 +349,13 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } if ((selector & 0x0800) != 0) { - position.set(Position.KEY_VIN, buf.readBytes(18).toString(StandardCharsets.US_ASCII).trim()); + position.set(Position.KEY_VIN, buf.readSlice(18).toString(StandardCharsets.US_ASCII).trim()); } if ((selector & 0x2000) != 0) { buf.readUnsignedByte(); // card 1 type buf.readUnsignedByte(); // card 1 country code - String card = buf.readBytes(20).toString(StandardCharsets.US_ASCII).trim(); + String card = buf.readSlice(20).toString(StandardCharsets.US_ASCII).trim(); if (!card.isEmpty()) { position.set("card1", card); } @@ -364,7 +364,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if ((selector & 0x4000) != 0) { buf.readUnsignedByte(); // card 2 type buf.readUnsignedByte(); // card 2 country code - String card = buf.readBytes(20).toString(StandardCharsets.US_ASCII).trim(); + String card = buf.readSlice(20).toString(StandardCharsets.US_ASCII).trim(); if (!card.isEmpty()) { position.set("card2", card); } @@ -373,7 +373,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { if ((selector & 0x10000) != 0) { int count = buf.readUnsignedByte(); for (int i = 1; i <= count; i++) { - position.set("driver" + i, buf.readBytes(22).toString(StandardCharsets.US_ASCII).trim()); + position.set("driver" + i, buf.readSlice(22).toString(StandardCharsets.US_ASCII).trim()); position.set("driverTime" + i, buf.readUnsignedInt()); } } @@ -477,7 +477,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { switch (type) { case 0x01: - position.set("brakeFlags", ByteBufUtil.hexDump(buf.readBytes(length))); + position.set("brakeFlags", ByteBufUtil.hexDump(buf.readSlice(length))); break; case 0x02: position.set("wheelSpeed", buf.readUnsignedShort() / 256.0); @@ -507,10 +507,10 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { position.set("vdcActiveCounter", buf.readUnsignedShort()); break; case 0x0B: - position.set("brakeMinMaxData", ByteBufUtil.hexDump(buf.readBytes(length))); + position.set("brakeMinMaxData", ByteBufUtil.hexDump(buf.readSlice(length))); break; case 0x0C: - position.set("missingPgn", ByteBufUtil.hexDump(buf.readBytes(length))); + position.set("missingPgn", ByteBufUtil.hexDump(buf.readSlice(length))); break; case 0x0D: buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java index 7a4e1ee85..c386c7757 100644 --- a/src/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/org/traccar/protocol/AstraProtocolDecoder.java @@ -105,7 +105,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // geofence events if (BitUtil.check(status, 8)) { - position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readSlice(7).toString(StandardCharsets.US_ASCII)); position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000); position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(buf.readUnsignedShort())); } diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java index c02e38b65..5fa82a5f7 100644 --- a/src/org/traccar/protocol/At2000FrameDecoder.java +++ b/src/org/traccar/protocol/At2000FrameDecoder.java @@ -72,7 +72,7 @@ public class At2000FrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index cba7c92c6..4c2967158 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -76,7 +76,7 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_DEVICE_ID) { - String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); if (getDeviceSession(channel, remoteAddress, imei) != null) { byte[] iv = new byte[BLOCK_LENGTH]; diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java index 4e1758f2d..3d33d9862 100644 --- a/src/org/traccar/protocol/AtrackFrameDecoder.java +++ b/src/org/traccar/protocol/AtrackFrameDecoder.java @@ -34,7 +34,7 @@ public class AtrackFrameDecoder extends BaseFrameDecoder { if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) { if (buf.readableBytes() >= KEEPALIVE_LENGTH) { - return buf.readBytes(KEEPALIVE_LENGTH); + return buf.readRetainedSlice(KEEPALIVE_LENGTH); } } else if (buf.getUnsignedShort(buf.readerIndex()) == 0x4050 && buf.getByte(buf.readerIndex() + 2) != ',') { @@ -42,7 +42,7 @@ public class AtrackFrameDecoder extends BaseFrameDecoder { if (buf.readableBytes() > 6) { int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2; if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } } @@ -50,7 +50,7 @@ public class AtrackFrameDecoder extends BaseFrameDecoder { int endIndex = BufferUtil.indexOf("\r\n", buf); if (endIndex > 0) { - return buf.readBytes(endIndex - buf.readerIndex() + 2); + return buf.readRetainedSlice(endIndex - buf.readerIndex() + 2); } } diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 19746f31e..ebccfec94 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -93,7 +93,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { 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); + result = buf.readSlice(index - buf.readerIndex()).toString(StandardCharsets.US_ASCII); } buf.readByte(); return result; diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java index 517f4b124..69f28133f 100644 --- a/src/org/traccar/protocol/AutoFonFrameDecoder.java +++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java @@ -56,7 +56,7 @@ public class AutoFonFrameDecoder extends BaseFrameDecoder { // Check length and return buffer if (length != 0 && buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index c0c57720e..c5a3692f2 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -131,7 +131,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // software version } - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null && channel != null) { diff --git a/src/org/traccar/protocol/BceFrameDecoder.java b/src/org/traccar/protocol/BceFrameDecoder.java index 15ae40148..381a97696 100644 --- a/src/org/traccar/protocol/BceFrameDecoder.java +++ b/src/org/traccar/protocol/BceFrameDecoder.java @@ -49,7 +49,7 @@ public class BceFrameDecoder extends BaseFrameDecoder { end += buf.getUnsignedShortLE(buf.readerIndex() + end) + 2; if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) { - return buf.readBytes(end + 1); + return buf.readRetainedSlice(end + 1); } } diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java index 9701a8059..54761b87c 100644 --- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java +++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java @@ -95,7 +95,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { switch (tag) { case TAG_IMEI: - getDeviceSession(channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII)); + getDeviceSession(channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); break; case TAG_DATE: diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index 9e9bd1336..d495e7400 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -152,7 +152,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { int content = buf.readUnsignedByte(); if (BitUtil.check(content, 0)) { - String id = ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte())); + String id = ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte())); getDeviceSession(channel, remoteAddress, id); } diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 3c3ad6117..af0bb9d41 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -383,7 +383,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { decodeStat(position, buf); buf.readUnsignedByte(); // flag - position.add(ObdDecoder.decodeCodes(ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte())))); + position.add(ObdDecoder.decodeCodes(ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte())))); return position; @@ -426,7 +426,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < successCount; i++) { buf.readUnsignedShortLE(); // tag position.set(Position.KEY_RESULT, - buf.readBytes(buf.readUnsignedShortLE()).toString(StandardCharsets.US_ASCII)); + buf.readSlice(buf.readUnsignedShortLE()).toString(StandardCharsets.US_ASCII)); } return position; @@ -548,7 +548,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { version = buf.readUnsignedByte(); } - ByteBuf id = buf.readBytes(20); + ByteBuf id = buf.readSlice(20); short type = buf.readShort(); DeviceSession deviceSession = getDeviceSession( diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java index 8cdba18e0..986dc75ec 100644 --- a/src/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java @@ -59,7 +59,7 @@ public class CellocatorFrameDecoder extends BaseFrameDecoder { } if (length > 0 && buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 5e5568402..a66b9adb3 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java @@ -74,7 +74,7 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(2); // header buf.readUnsignedShort(); // length - String imei = ByteBufUtil.hexDump(buf.readBytes(7)); + String imei = ByteBufUtil.hexDump(buf.readSlice(7)); DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei))); if (deviceSession == null) { diff --git a/src/org/traccar/protocol/DmtProtocolDecoder.java b/src/org/traccar/protocol/DmtProtocolDecoder.java index 9b414531a..25055d892 100644 --- a/src/org/traccar/protocol/DmtProtocolDecoder.java +++ b/src/org/traccar/protocol/DmtProtocolDecoder.java @@ -242,7 +242,7 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedIntLE(); // device serial number DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII)); + channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); ByteBuf response = Unpooled.buffer(0); if (length == 51) { diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 1ed21893d..67e7f5127 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -339,7 +339,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { if (buf.getByte(0) == 'E' && buf.getByte(1) == 'L') { buf.skipBytes(2 + 2 + 2); // udp header - uniqueId = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + uniqueId = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, uniqueId); } else { deviceSession = getDeviceSession(channel, remoteAddress); @@ -357,7 +357,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGIN) { if (deviceSession == null) { - getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(buf.readBytes(8)).substring(1)); + getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(buf.readSlice(8)).substring(1)); } } else { diff --git a/src/org/traccar/protocol/EgtsFrameDecoder.java b/src/org/traccar/protocol/EgtsFrameDecoder.java index c85eeff00..84f1f11a7 100644 --- a/src/org/traccar/protocol/EgtsFrameDecoder.java +++ b/src/org/traccar/protocol/EgtsFrameDecoder.java @@ -36,7 +36,7 @@ public class EgtsFrameDecoder extends BaseFrameDecoder { int length = headerLength + frameLength + (frameLength > 0 ? 2 : 0); if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/EgtsProtocolDecoder.java b/src/org/traccar/protocol/EgtsProtocolDecoder.java index bb78f89a2..df02b8f7f 100644 --- a/src/org/traccar/protocol/EgtsProtocolDecoder.java +++ b/src/org/traccar/protocol/EgtsProtocolDecoder.java @@ -169,11 +169,11 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(flags, 1)) { getDeviceSession( - channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII).trim()); + channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim()); } if (BitUtil.check(flags, 2)) { getDeviceSession( - channel, remoteAddress, buf.readBytes(16).toString(StandardCharsets.US_ASCII).trim()); + channel, remoteAddress, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim()); } if (BitUtil.check(flags, 3)) { buf.skipBytes(3); // language identifier @@ -186,7 +186,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(flags, 7)) { getDeviceSession( - channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII).trim()); + channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim()); } response = Unpooled.buffer(0); diff --git a/src/org/traccar/protocol/EskyFrameDecoder.java b/src/org/traccar/protocol/EskyFrameDecoder.java index a1470e12b..da24c1273 100644 --- a/src/org/traccar/protocol/EskyFrameDecoder.java +++ b/src/org/traccar/protocol/EskyFrameDecoder.java @@ -30,9 +30,9 @@ public class EskyFrameDecoder extends BaseFrameDecoder { int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E'); if (endIndex > 0) { - return buf.readBytes(endIndex - buf.readerIndex()); + return buf.readRetainedSlice(endIndex - buf.readerIndex()); } else { - return buf.readBytes(buf.readableBytes()); // assume full frame + return buf.readRetainedSlice(buf.readableBytes()); // assume full frame } } diff --git a/src/org/traccar/protocol/GalileoFrameDecoder.java b/src/org/traccar/protocol/GalileoFrameDecoder.java index 5a57c3a95..c23d26c83 100644 --- a/src/org/traccar/protocol/GalileoFrameDecoder.java +++ b/src/org/traccar/protocol/GalileoFrameDecoder.java @@ -34,7 +34,7 @@ public class GalileoFrameDecoder extends BaseFrameDecoder { int length = buf.getUnsignedShortLE(buf.readerIndex() + 1) & 0x7fff; if (buf.readableBytes() >= (length + MESSAGE_MINIMUM_LENGTH)) { - return buf.readBytes(length + MESSAGE_MINIMUM_LENGTH); + return buf.readRetainedSlice(length + MESSAGE_MINIMUM_LENGTH); } return null; diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index dae92fa8a..746e05f5d 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -215,7 +215,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { break; case 0xe1: position.set(Position.KEY_RESULT, - buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); + buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); break; case 0xe2: case 0xe3: @@ -228,8 +228,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.set("userData" + (tag - 0xe2), buf.readUnsignedIntLE()); break; case 0xea: - position.set("userDataArray", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()))); - position.set("userDataArray", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()))); + position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); + position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); break; default: buf.skipBytes(getTagLength(tag)); @@ -268,7 +268,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { if (tag == 0x03) { deviceSession = getDeviceSession( - channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII)); + channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); } else if (tag == 0x30) { hasLocation = true; position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00); diff --git a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java b/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java index e249cd936..62caaf13d 100644 --- a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java @@ -113,7 +113,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder { switch (BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 8 - 2)) { case 1: - bits = new BitBuffer(buf.readBytes(3)); + bits = new BitBuffer(buf.readSlice(3)); bits.readUnsigned(2); // point attribute bits.readUnsigned(1); // fix type speed = bits.readUnsigned(12); @@ -125,7 +125,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder { } break; case 2: - bits = new BitBuffer(buf.readBytes(5)); + bits = new BitBuffer(buf.readSlice(5)); bits.readUnsigned(2); // point attribute bits.readUnsigned(1); // fix type speed += bits.readSigned(7); @@ -387,7 +387,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; - switch (buf.readBytes(4).toString(StandardCharsets.US_ASCII)) { + switch (buf.readSlice(4).toString(StandardCharsets.US_ASCII)) { case "+RSP": return decodeLocation(channel, remoteAddress, buf); case "+INF": diff --git a/src/org/traccar/protocol/Gl200FrameDecoder.java b/src/org/traccar/protocol/Gl200FrameDecoder.java index bcddb1aff..c192cc28d 100644 --- a/src/org/traccar/protocol/Gl200FrameDecoder.java +++ b/src/org/traccar/protocol/Gl200FrameDecoder.java @@ -74,7 +74,7 @@ public class Gl200FrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } } else { @@ -84,7 +84,7 @@ public class Gl200FrameDecoder extends BaseFrameDecoder { endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0); } if (endIndex > 0) { - ByteBuf frame = buf.readBytes(endIndex - buf.readerIndex()); + ByteBuf frame = buf.readRetainedSlice(endIndex - buf.readerIndex()); buf.readByte(); // delimiter return frame; } diff --git a/src/org/traccar/protocol/Gps056FrameDecoder.java b/src/org/traccar/protocol/Gps056FrameDecoder.java index 7cfd54c4e..0d84bf231 100644 --- a/src/org/traccar/protocol/Gps056FrameDecoder.java +++ b/src/org/traccar/protocol/Gps056FrameDecoder.java @@ -33,7 +33,7 @@ public class Gps056FrameDecoder extends BaseFrameDecoder { if (buf.readableBytes() >= MESSAGE_HEADER) { int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5; if (buf.readableBytes() >= length) { - ByteBuf frame = buf.readBytes(length); + ByteBuf frame = buf.readRetainedSlice(length); while (buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) != '$') { buf.readByte(); } diff --git a/src/org/traccar/protocol/Gps056ProtocolDecoder.java b/src/org/traccar/protocol/Gps056ProtocolDecoder.java index c2a8372b0..bfe9fc68e 100644 --- a/src/org/traccar/protocol/Gps056ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps056ProtocolDecoder.java @@ -79,8 +79,8 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(2); // header buf.skipBytes(2); // length - String type = buf.readBytes(7).toString(StandardCharsets.US_ASCII); - String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + String type = buf.readSlice(7).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { @@ -110,7 +110,7 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder { decodeStatus(buf, position); - sendResponse(channel, "GPSA" + type.substring(4), imei, buf.readBytes(2)); + sendResponse(channel, "GPSA" + type.substring(4), imei, buf.readSlice(2)); return position; diff --git a/src/org/traccar/protocol/GranitFrameDecoder.java b/src/org/traccar/protocol/GranitFrameDecoder.java index 5e555fb15..bb7f4be44 100644 --- a/src/org/traccar/protocol/GranitFrameDecoder.java +++ b/src/org/traccar/protocol/GranitFrameDecoder.java @@ -37,7 +37,7 @@ public class GranitFrameDecoder extends BaseFrameDecoder { return null; } } - ByteBuf frame = buf.readBytes(indexEnd - buf.readerIndex()); + ByteBuf frame = buf.readRetainedSlice(indexEnd - buf.readerIndex()); buf.skipBytes(2); return frame; } diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index c3eff7d34..495faef30 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.java @@ -170,7 +170,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { if (buf.readableBytes() < HEADER_LENGTH) { return null; } - String header = buf.readBytes(HEADER_LENGTH).toString(StandardCharsets.US_ASCII); + String header = buf.readSlice(HEADER_LENGTH).toString(StandardCharsets.US_ASCII); if (header.equals("+RRCB~")) { diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 83be9d996..ab4c7022e 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -55,7 +55,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { int power = buf.readUnsignedByte(); int gsm = buf.readUnsignedByte(); - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; @@ -110,7 +110,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); position.set(Position.KEY_RESULT, - buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); + buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); } else { diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java index 41e56415a..cc934be42 100644 --- a/src/org/traccar/protocol/Gt06FrameDecoder.java +++ b/src/org/traccar/protocol/Gt06FrameDecoder.java @@ -39,14 +39,14 @@ public class Gt06FrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) { - return buf.readBytes(length); + return buf.readRetainedSlice(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()); + return buf.readRetainedSlice(endIndex + 2 - buf.readerIndex()); } } while (endIndex > 0); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 490c366ea..cc37d5602 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -388,7 +388,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGIN) { - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); buf.readUnsignedShort(); // type deviceSession = getDeviceSession(channel, remoteAddress, imei); @@ -573,7 +573,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (type != MSG_LBS_MULTIPLE && type != MSG_LBS_2) { int wifiCount = buf.readUnsignedByte(); for (int i = 0; i < wifiCount; i++) { - String mac = ByteBufUtil.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:"); + String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:"); network.addWifiAccessPoint(WifiAccessPoint.from( mac.substring(0, mac.length() - 1), buf.readUnsignedByte())); } @@ -590,7 +590,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (commandLength > 0) { buf.readUnsignedByte(); // server flag (reserved) position.set(Position.KEY_RESULT, - buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII)); + buf.readSlice(commandLength - 1).toString(StandardCharsets.US_ASCII)); } } else if (isSupported(type)) { @@ -666,9 +666,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // server flag String data; if (buf.readUnsignedByte() == 1) { - data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.US_ASCII); + data = buf.readSlice(buf.readableBytes() - 6).toString(StandardCharsets.US_ASCII); } else { - data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.UTF_16BE); + data = buf.readSlice(buf.readableBytes() - 6).toString(StandardCharsets.UTF_16BE); } if (decodeLocationString(position, data) == null) { diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index 4f7d78cea..583ad599f 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -50,7 +50,7 @@ public class H02FrameDecoder extends BaseFrameDecoder { // Return text message int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#'); if (index != -1) { - ByteBuf result = buf.readBytes(index + 1 - buf.readerIndex()); + ByteBuf result = buf.readRetainedSlice(index + 1 - buf.readerIndex()); while (buf.isReadable() && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) { buf.readByte(); // skip new line @@ -71,7 +71,7 @@ public class H02FrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= messageLength) { - return buf.readBytes(messageLength); + return buf.readRetainedSlice(messageLength); } break; @@ -79,7 +79,7 @@ public class H02FrameDecoder extends BaseFrameDecoder { case 'X': if (buf.readableBytes() >= MESSAGE_SHORT) { - return buf.readBytes(MESSAGE_SHORT); + return buf.readRetainedSlice(MESSAGE_SHORT); } break; diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index e6fd86897..2abde7d6f 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -106,7 +106,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { buf.readByte(); // marker DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, ByteBufUtil.hexDump(buf.readBytes(5))); + channel, remoteAddress, ByteBufUtil.hexDump(buf.readSlice(5))); if (deviceSession == null) { return null; } diff --git a/src/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/org/traccar/protocol/HuaShengProtocolDecoder.java index 6349a6792..79ba660ee 100644 --- a/src/org/traccar/protocol/HuaShengProtocolDecoder.java +++ b/src/org/traccar/protocol/HuaShengProtocolDecoder.java @@ -81,7 +81,7 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { int subtype = buf.readUnsignedShort(); int length = buf.readUnsignedShort() - 4; if (subtype == 0x0003) { - String imei = buf.readBytes(length).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(length).toString(StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null && channel != null) { ByteBuf content = Unpooled.buffer(); @@ -115,7 +115,7 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, BitUtil.check(status, 14)); position.set(Position.KEY_EVENT, buf.readUnsignedShort()); - String time = buf.readBytes(12).toString(StandardCharsets.US_ASCII); + String time = buf.readSlice(12).toString(StandardCharsets.US_ASCII); DateBuilder dateBuilder = new DateBuilder() .setYear(Integer.parseInt(time.substring(0, 2))) diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index 7735092fc..c9868b21e 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -107,7 +107,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // start marker int type = buf.readUnsignedShort(); buf.readUnsignedShort(); // body length - ByteBuf id = buf.readBytes(6); // phone number + ByteBuf id = buf.readSlice(6); // phone number int index = buf.readUnsignedShort(); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(id)); diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java index 2cf91bf59..8322e65ba 100644 --- a/src/org/traccar/protocol/IntellitracFrameDecoder.java +++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java @@ -40,7 +40,7 @@ public class IntellitracFrameDecoder extends LineBasedFrameDecoder { // Check for sync packet if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) { - ByteBuf syncMessage = buf.readBytes(8); + ByteBuf syncMessage = buf.readRetainedSlice(8); if (ctx != null && ctx.channel() != null) { ctx.channel().writeAndFlush(new NetworkMessage(syncMessage, ctx.channel().remoteAddress())); } diff --git a/src/org/traccar/protocol/JpKorjarFrameDecoder.java b/src/org/traccar/protocol/JpKorjarFrameDecoder.java index 9a0158230..0eb65c8ef 100644 --- a/src/org/traccar/protocol/JpKorjarFrameDecoder.java +++ b/src/org/traccar/protocol/JpKorjarFrameDecoder.java @@ -41,7 +41,7 @@ public class JpKorjarFrameDecoder extends BaseFrameDecoder { return null; } - return buf.readBytes(endIndex + 1); + return buf.readRetainedSlice(endIndex + 1); } } diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java index 5b712a7b4..b5d060ecc 100644 --- a/src/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/org/traccar/protocol/Jt600FrameDecoder.java @@ -38,12 +38,12 @@ public class Jt600FrameDecoder extends BaseFrameDecoder { 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); + return buf.readRetainedSlice(length); } } else if (type == '(') { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')'); if (endIndex != -1) { - return buf.readBytes(endIndex + 1); + return buf.readRetainedSlice(endIndex + 1); } } else { throw new ParseException(null, 0); // unknown message diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 58ec8c613..87996a0c3 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -93,7 +93,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75; - String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readBytes(5)))); + String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5)))); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java index 29839eb3a..d407ac0b5 100644 --- a/src/org/traccar/protocol/L100FrameDecoder.java +++ b/src/org/traccar/protocol/L100FrameDecoder.java @@ -42,7 +42,7 @@ public class L100FrameDecoder extends BaseFrameDecoder { if (buf.readableBytes() >= index - buf.readerIndex()) { buf.skipBytes(2); // header - ByteBuf frame = buf.readBytes(index - buf.readerIndex() - 2); + ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex() - 2); buf.skipBytes(2); // footer return frame; } diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java index 0bdd06a79..347fa24b1 100644 --- a/src/org/traccar/protocol/MegastekFrameDecoder.java +++ b/src/org/traccar/protocol/MegastekFrameDecoder.java @@ -36,7 +36,7 @@ public class MegastekFrameDecoder extends BaseFrameDecoder { 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); + return buf.readRetainedSlice(length); } } else { while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') { @@ -47,7 +47,7 @@ public class MegastekFrameDecoder extends BaseFrameDecoder { delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!'); } if (delimiter != -1) { - ByteBuf result = buf.readBytes(delimiter - buf.readerIndex()); + ByteBuf result = buf.readRetainedSlice(delimiter - buf.readerIndex()); buf.skipBytes(1); return result; } diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java index e14d8ed58..52f9ae26d 100644 --- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java +++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java @@ -37,7 +37,7 @@ public class MeiligaoFrameDecoder extends BaseFrameDecoder { if (buf.readableBytes() >= MESSAGE_HEADER) { int length = buf.getUnsignedShort(buf.readerIndex() + 2); if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } } diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 35512945a..6813ffcfe 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -371,7 +371,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { endIndex = buf.writerIndex() - 4; } - String sentence = buf.readBytes(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); + String sentence = buf.readSlice(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -398,7 +398,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header buf.readShort(); // length - ByteBuf id = buf.readBytes(7); + ByteBuf id = buf.readSlice(7); int command = buf.readUnsignedShort(); ByteBuf response; diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java index 5133dd2dc..d122bca0c 100644 --- a/src/org/traccar/protocol/MeitrackFrameDecoder.java +++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java @@ -37,7 +37,7 @@ public class MeitrackFrameDecoder extends BaseFrameDecoder { 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 buf.readRetainedSlice(length); } } diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index a38f52b77..3f027559a 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -348,7 +348,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { List positions = new LinkedList<>(); buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',') + 1); - String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); buf.skipBytes(1 + 3 + 1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); @@ -485,7 +485,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { int current = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII)); buf.readerIndex(endIndex + 1); - photo.writeBytes(buf.readBytes(buf.readableBytes() - 1 - 2 - 2)); + photo.writeBytes(buf.readSlice(buf.readableBytes() - 1 - 2 - 2)); if (current == total - 1) { Position position = new Position(getProtocolName()); diff --git a/src/org/traccar/protocol/NavigilFrameDecoder.java b/src/org/traccar/protocol/NavigilFrameDecoder.java index 90912fb45..e8b6bea52 100644 --- a/src/org/traccar/protocol/NavigilFrameDecoder.java +++ b/src/org/traccar/protocol/NavigilFrameDecoder.java @@ -47,7 +47,7 @@ public class NavigilFrameDecoder extends BaseFrameDecoder { buf.readUnsignedIntLE(); length -= 4; } - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 5e41cd6bc..2c5da4a78 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -129,9 +129,9 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { ByteBuf rawId; if (newFormat) { - rawId = buf.readBytes(12); + rawId = buf.readSlice(12); } else { - rawId = buf.readBytes(11); + rawId = buf.readSlice(11); } String id = rawId.toString(StandardCharsets.US_ASCII).replaceAll("[^\\p{Print}]", ""); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); @@ -142,7 +142,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { if (newFormat) { DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); - position.setTime(dateFormat.parse(buf.readBytes(17).toString(StandardCharsets.US_ASCII))); + position.setTime(dateFormat.parse(buf.readSlice(17).toString(StandardCharsets.US_ASCII))); buf.readByte(); } diff --git a/src/org/traccar/protocol/NvsFrameDecoder.java b/src/org/traccar/protocol/NvsFrameDecoder.java index 4fa1cab1c..e93a58cf6 100644 --- a/src/org/traccar/protocol/NvsFrameDecoder.java +++ b/src/org/traccar/protocol/NvsFrameDecoder.java @@ -38,7 +38,7 @@ public class NvsFrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java index bb925ca3e..dcfba242d 100644 --- a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java +++ b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java @@ -67,7 +67,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(2); // header int index = buf.readUnsignedShort(); - String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java index 9067bac21..fe356f7cf 100644 --- a/src/org/traccar/protocol/OigoProtocolDecoder.java +++ b/src/org/traccar/protocol/OigoProtocolDecoder.java @@ -53,12 +53,12 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession; switch (BitUtil.to(tag, 3)) { case 0: - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, imei); break; case 1: buf.skipBytes(1); - String meid = buf.readBytes(14).toString(StandardCharsets.US_ASCII); + String meid = buf.readSlice(14).toString(StandardCharsets.US_ASCII); deviceSession = getDeviceSession(channel, remoteAddress, meid); break; default: @@ -171,7 +171,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // flags deviceSession = getDeviceSession(channel, remoteAddress); } else { - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, imei); } diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java index ce5a06478..948806609 100644 --- a/src/org/traccar/protocol/OrionFrameDecoder.java +++ b/src/org/traccar/protocol/OrionFrameDecoder.java @@ -49,14 +49,14 @@ public class OrionFrameDecoder extends BaseFrameDecoder { } if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } } else if (type == OrionProtocolDecoder.MSG_SYSLOG && buf.readableBytes() >= length + 12) { length += buf.getUnsignedShortLE(buf.readerIndex() + 8); if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } } diff --git a/src/org/traccar/protocol/PricolProtocolDecoder.java b/src/org/traccar/protocol/PricolProtocolDecoder.java index e0ab300be..b76e5f27f 100644 --- a/src/org/traccar/protocol/PricolProtocolDecoder.java +++ b/src/org/traccar/protocol/PricolProtocolDecoder.java @@ -43,7 +43,7 @@ public class PricolProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // header DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, buf.readBytes(7).toString(StandardCharsets.US_ASCII)); + channel, remoteAddress, buf.readSlice(7).toString(StandardCharsets.US_ASCII)); if (deviceSession == null) { return null; } diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index c57d6e5ce..dca0e649e 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -79,7 +79,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { length = buf.readUnsignedShortLE(); buf.skipBytes(length); length = buf.readUnsignedShortLE(); - String imei = buf.readBytes(length).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(length).toString(StandardCharsets.US_ASCII); getDeviceSession(channel, remoteAddress, imei); } else if (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG) { @@ -146,7 +146,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(extraFlags, 2)) { - position.set("passenger", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedShortLE()))); + position.set("passenger", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedShortLE()))); } if (type == MSG_ALARM) { diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java index 9c7989446..316cd987f 100644 --- a/src/org/traccar/protocol/Pt502FrameDecoder.java +++ b/src/org/traccar/protocol/Pt502FrameDecoder.java @@ -40,7 +40,7 @@ public class Pt502FrameDecoder extends BaseFrameDecoder { int length = buf.getUnsignedShortLE(buf.readerIndex() + 3); if (buf.readableBytes() >= length) { buf.skipBytes(BINARY_HEADER); - ByteBuf result = buf.readBytes(length - BINARY_HEADER - 2); + ByteBuf result = buf.readRetainedSlice(length - BINARY_HEADER - 2); buf.skipBytes(2); // line break return result; } @@ -57,7 +57,7 @@ public class Pt502FrameDecoder extends BaseFrameDecoder { } if (index > 0) { - ByteBuf result = buf.readBytes(index - buf.readerIndex()); + ByteBuf result = buf.readRetainedSlice(index - buf.readerIndex()); while (buf.isReadable() && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) { buf.skipBytes(1); diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 05d498cb4..4d218653b 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -165,7 +165,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { if (photo != null) { - photo.writeBytes(buf.readBytes(buf.readableBytes())); + photo.writeBytes(buf.readSlice(buf.readableBytes())); if (photo.writableBytes() > 0) { diff --git a/src/org/traccar/protocol/RecodaProtocolDecoder.java b/src/org/traccar/protocol/RecodaProtocolDecoder.java index c948ff1b7..eef1cb5af 100644 --- a/src/org/traccar/protocol/RecodaProtocolDecoder.java +++ b/src/org/traccar/protocol/RecodaProtocolDecoder.java @@ -55,7 +55,7 @@ public class RecodaProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_SIGNAL_LINK_REGISTRATION) { - getDeviceSession(channel, remoteAddress, buf.readBytes(12).toString(StandardCharsets.US_ASCII)); + getDeviceSession(channel, remoteAddress, buf.readSlice(12).toString(StandardCharsets.US_ASCII)); } else if (type == MSG_GPS_DATA) { diff --git a/src/org/traccar/protocol/RoboTrackFrameDecoder.java b/src/org/traccar/protocol/RoboTrackFrameDecoder.java index 297e221d6..aecbaaa3b 100644 --- a/src/org/traccar/protocol/RoboTrackFrameDecoder.java +++ b/src/org/traccar/protocol/RoboTrackFrameDecoder.java @@ -48,7 +48,7 @@ public class RoboTrackFrameDecoder extends BaseFrameDecoder { int length = messageLength(buf); if (buf.readableBytes() >= length) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/RoboTrackProtocolDecoder.java b/src/org/traccar/protocol/RoboTrackProtocolDecoder.java index caf3d28d5..26d6bc4ff 100644 --- a/src/org/traccar/protocol/RoboTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/RoboTrackProtocolDecoder.java @@ -57,7 +57,7 @@ public class RoboTrackProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(16); // name - String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII); if (getDeviceSession(channel, remoteAddress, imei) != null && channel != null) { ByteBuf response = Unpooled.buffer(0); diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 2df0b6e25..e5d196fed 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -225,7 +225,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ARCHIVE, true); } - position.set(Position.KEY_DTCS, buf.readBytes(5).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_DTCS, buf.readSlice(5).toString(StandardCharsets.US_ASCII)); positions.add(position); } diff --git a/src/org/traccar/protocol/SabertekFrameDecoder.java b/src/org/traccar/protocol/SabertekFrameDecoder.java index 35dcd8928..771ef9cfb 100644 --- a/src/org/traccar/protocol/SabertekFrameDecoder.java +++ b/src/org/traccar/protocol/SabertekFrameDecoder.java @@ -31,7 +31,7 @@ public class SabertekFrameDecoder extends BaseFrameDecoder { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x03); if (beginIndex >= 0) { buf.readerIndex(beginIndex + 1); - ByteBuf frame = buf.readBytes(endIndex - beginIndex - 1); + ByteBuf frame = buf.readRetainedSlice(endIndex - beginIndex - 1); buf.readerIndex(endIndex + 1); buf.skipBytes(2); // end line return frame; diff --git a/src/org/traccar/protocol/SmokeyProtocolDecoder.java b/src/org/traccar/protocol/SmokeyProtocolDecoder.java index 2fd90a4ff..825108ed2 100644 --- a/src/org/traccar/protocol/SmokeyProtocolDecoder.java +++ b/src/org/traccar/protocol/SmokeyProtocolDecoder.java @@ -78,7 +78,7 @@ public class SmokeyProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); - ByteBuf id = buf.readBytes(8); + ByteBuf id = buf.readSlice(8); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ByteBufUtil.hexDump(id)); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/Stl060FrameDecoder.java b/src/org/traccar/protocol/Stl060FrameDecoder.java index 831360ec2..f72474e2b 100644 --- a/src/org/traccar/protocol/Stl060FrameDecoder.java +++ b/src/org/traccar/protocol/Stl060FrameDecoder.java @@ -37,7 +37,7 @@ public class Stl060FrameDecoder extends CharacterDelimiterFrameDecoder { return result; } else { result.skipBytes(index); - return result.readBytes(result.readableBytes()); + return result.readRetainedSlice(result.readableBytes()); } } diff --git a/src/org/traccar/protocol/T57FrameDecoder.java b/src/org/traccar/protocol/T57FrameDecoder.java index 844043088..14ba31453 100644 --- a/src/org/traccar/protocol/T57FrameDecoder.java +++ b/src/org/traccar/protocol/T57FrameDecoder.java @@ -43,7 +43,7 @@ public class T57FrameDecoder extends BaseFrameDecoder { } } - return index > 0 ? buf.readBytes(index + 1 - buf.readerIndex()) : null; + return index > 0 ? buf.readRetainedSlice(index + 1 - buf.readerIndex()) : null; } } diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java index d91fe9d42..d5504c190 100644 --- a/src/org/traccar/protocol/T800xProtocolDecoder.java +++ b/src/org/traccar/protocol/T800xProtocolDecoder.java @@ -85,7 +85,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); buf.readUnsignedShort(); // length int index = buf.readUnsignedShort(); - ByteBuf imei = buf.readBytes(8); + ByteBuf imei = buf.readSlice(8); DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, ByteBufUtil.hexDump(imei).substring(1)); diff --git a/src/org/traccar/protocol/TelicFrameDecoder.java b/src/org/traccar/protocol/TelicFrameDecoder.java index b99ef98bf..d1fef1b5b 100644 --- a/src/org/traccar/protocol/TelicFrameDecoder.java +++ b/src/org/traccar/protocol/TelicFrameDecoder.java @@ -36,12 +36,12 @@ public class TelicFrameDecoder extends BaseFrameDecoder { if (length < 1024) { if (buf.readableBytes() >= length + 4) { buf.readUnsignedIntLE(); - return buf.readBytes((int) length); + return buf.readRetainedSlice((int) length); } } else { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0); if (endIndex >= 0) { - ByteBuf frame = buf.readBytes(endIndex - buf.readerIndex()); + ByteBuf frame = buf.readRetainedSlice(endIndex - buf.readerIndex()); buf.readByte(); if (frame.readableBytes() > 0) { return frame; diff --git a/src/org/traccar/protocol/TeltonikaFrameDecoder.java b/src/org/traccar/protocol/TeltonikaFrameDecoder.java index 17c6264e0..4d4d79d8d 100644 --- a/src/org/traccar/protocol/TeltonikaFrameDecoder.java +++ b/src/org/traccar/protocol/TeltonikaFrameDecoder.java @@ -38,12 +38,12 @@ public class TeltonikaFrameDecoder extends BaseFrameDecoder { int length = buf.getUnsignedShort(buf.readerIndex()); if (length > 0) { if (buf.readableBytes() >= (length + 2)) { - return buf.readBytes(length + 2); + return buf.readRetainedSlice(length + 2); } } else { int dataLength = buf.getInt(buf.readerIndex() + 4); if (buf.readableBytes() >= (dataLength + 12)) { - return buf.readBytes(dataLength + 12); + return buf.readRetainedSlice(dataLength + 12); } } diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 34afe28ad..5e9b6640e 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -79,7 +79,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_TYPE, buf.readUnsignedByte()); - position.set(Position.KEY_RESULT, buf.readBytes(buf.readInt()).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_RESULT, buf.readSlice(buf.readInt()).toString(StandardCharsets.US_ASCII)); } @@ -151,7 +151,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { case 134: String driver = id == 129 || id == 132 ? "" : position.getString("driver1"); position.set("driver" + (id >= 132 ? 2 : 1), - driver + buf.readBytes(length).toString(StandardCharsets.US_ASCII).trim()); + driver + buf.readSlice(length).toString(StandardCharsets.US_ASCII).trim()); break; case 179: position.set(Position.PREFIX_OUT + 1, readValue(buf, length, false) == 1); @@ -394,7 +394,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (extended) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ByteBufUtil.hexDump(buf.readBytes(16))); + position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ByteBufUtil.hexDump(buf.readSlice(16))); } } @@ -482,7 +482,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // packet id buf.readUnsignedByte(); // packet type int locationPacketId = buf.readUnsignedByte(); - String imei = buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII); + String imei = buf.readSlice(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII); return parseData(channel, remoteAddress, buf, locationPacketId, imei); diff --git a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java index dd1f34254..451f1c448 100644 --- a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java +++ b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java @@ -56,7 +56,7 @@ public class ThinkRaceProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header - ByteBuf id = buf.readBytes(12); + ByteBuf id = buf.readSlice(12); buf.readUnsignedByte(); // separator int type = buf.readUnsignedByte(); buf.readUnsignedShort(); // length diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java index 1419000be..5bbbddbef 100644 --- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java @@ -81,12 +81,12 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(1); // header int type = buf.readUnsignedByte(); - ByteBuf dataSequence = buf.readBytes(10); + ByteBuf dataSequence = buf.readSlice(10); int length = buf.readUnsignedByte(); if (type == MSG_LOGIN_REQUEST || type == MSG_LOGIN_REQUEST_2) { - ByteBuf data = buf.readBytes(length); + ByteBuf data = buf.readSlice(length); String id; if (type == MSG_LOGIN_REQUEST) { @@ -104,7 +104,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_HEARTBEAT_REQUEST) { - sendResponse(channel, MSG_HEARTBEAT_RESPONSE, dataSequence, buf.readBytes(length)); + sendResponse(channel, MSG_HEARTBEAT_RESPONSE, dataSequence, buf.readSlice(length)); } else { @@ -113,7 +113,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder { return null; } - Parser parser = new Parser(PATTERN, buf.readBytes(length).toString(StandardCharsets.US_ASCII)); + Parser parser = new Parser(PATTERN, buf.readSlice(length).toString(StandardCharsets.US_ASCII)); if (!parser.matches()) { return null; } diff --git a/src/org/traccar/protocol/Tk103FrameDecoder.java b/src/org/traccar/protocol/Tk103FrameDecoder.java index 3ad1cd2c9..b61a42563 100644 --- a/src/org/traccar/protocol/Tk103FrameDecoder.java +++ b/src/org/traccar/protocol/Tk103FrameDecoder.java @@ -69,7 +69,7 @@ public class Tk103FrameDecoder extends BaseFrameDecoder { buf.readerIndex(frameStartIndex); - return buf.readBytes(frameEndIndex + 1 - frameStartIndex); + return buf.readRetainedSlice(frameEndIndex + 1 - frameStartIndex); } } diff --git a/src/org/traccar/protocol/TlvProtocolDecoder.java b/src/org/traccar/protocol/TlvProtocolDecoder.java index ae1a3346a..b682345db 100644 --- a/src/org/traccar/protocol/TlvProtocolDecoder.java +++ b/src/org/traccar/protocol/TlvProtocolDecoder.java @@ -48,7 +48,7 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder { } private String readArgument(ByteBuf buf) { - return buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII); + return buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII); } @Override @@ -57,7 +57,7 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; - String type = buf.readBytes(2).toString(StandardCharsets.US_ASCII); + String type = buf.readSlice(2).toString(StandardCharsets.US_ASCII); if (channel != null) { switch (type) { diff --git a/src/org/traccar/protocol/TmgFrameDecoder.java b/src/org/traccar/protocol/TmgFrameDecoder.java index a2039ff52..205adaa51 100644 --- a/src/org/traccar/protocol/TmgFrameDecoder.java +++ b/src/org/traccar/protocol/TmgFrameDecoder.java @@ -54,7 +54,7 @@ public class TmgFrameDecoder extends BaseFrameDecoder { int endIndex = buf.indexOf(beginIndex, buf.writerIndex(), (byte) '\n'); if (endIndex >= 0) { - ByteBuf frame = buf.readBytes(endIndex - beginIndex); + ByteBuf frame = buf.readRetainedSlice(endIndex - beginIndex); buf.readByte(); // delimiter return frame; } diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java index a7e134c09..3fa5abc7a 100644 --- a/src/org/traccar/protocol/TotemFrameDecoder.java +++ b/src/org/traccar/protocol/TotemFrameDecoder.java @@ -50,7 +50,7 @@ public class TotemFrameDecoder extends BaseFrameDecoder { } if (length <= buf.readableBytes()) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/TramigoFrameDecoder.java b/src/org/traccar/protocol/TramigoFrameDecoder.java index 6c7e639ac..fae9efecf 100644 --- a/src/org/traccar/protocol/TramigoFrameDecoder.java +++ b/src/org/traccar/protocol/TramigoFrameDecoder.java @@ -37,7 +37,7 @@ public class TramigoFrameDecoder extends BaseFrameDecoder { } if (length >= buf.readableBytes()) { - return buf.readBytes(length); + return buf.readRetainedSlice(length); } return null; diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java index 221df6081..ac94e5ca7 100644 --- a/src/org/traccar/protocol/TytanProtocolDecoder.java +++ b/src/org/traccar/protocol/TytanProtocolDecoder.java @@ -75,10 +75,10 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder { position.set("antihijack", buf.readUnsignedByte()); break; case 9: - position.set("unauthorized", ByteBufUtil.hexDump(buf.readBytes(8))); + position.set("unauthorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 10: - position.set("authorized", ByteBufUtil.hexDump(buf.readBytes(8))); + position.set("authorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 24: for (int i = 0; i < length / 2; i++) { diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index 4983410a5..6f6ff3878 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -77,7 +77,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { length += 1; } - String num = ByteBufUtil.hexDump(buf.readBytes(length / 2)); + String num = ByteBufUtil.hexDump(buf.readSlice(length / 2)); if (odd) { num = num.substring(1); @@ -122,7 +122,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { int hardware = buf.readUnsignedShort(); long firmware = buf.readUnsignedInt(); - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java index 963b0e2ab..f141dc9b7 100644 --- a/src/org/traccar/protocol/UlbotechFrameDecoder.java +++ b/src/org/traccar/protocol/UlbotechFrameDecoder.java @@ -59,7 +59,7 @@ public class UlbotechFrameDecoder extends BaseFrameDecoder { int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#'); if (index != -1) { - return buf.readBytes(index + 1 - buf.readerIndex()); + return buf.readRetainedSlice(index + 1 - buf.readerIndex()); } } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 0c3ea6391..ed4695a44 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -67,7 +67,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { while (buf.readerIndex() < end) { int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4; int mode = buf.readUnsignedByte() & 0x0F; - position.add(ObdDecoder.decode(mode, ByteBufUtil.hexDump(buf.readBytes(parameterLength - 1)))); + position.add(ObdDecoder.decode(mode, ByteBufUtil.hexDump(buf.readSlice(parameterLength - 1)))); } } @@ -83,7 +83,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (type == 3) { id += 256; } - String value = ByteBufUtil.hexDump(buf.readBytes(len - 1)); + String value = ByteBufUtil.hexDump(buf.readSlice(len - 1)); if (type == 2 || type == 3) { position.set("pid" + id, value); } @@ -206,7 +206,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // version buf.readUnsignedByte(); // type - String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { @@ -296,7 +296,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_CANBUS: - position.set("can", ByteBufUtil.hexDump(buf.readBytes(length))); + position.set("can", ByteBufUtil.hexDump(buf.readSlice(length))); break; case DATA_J1708: @@ -304,12 +304,12 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_VIN: - position.set(Position.KEY_VIN, buf.readBytes(length).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII)); break; case DATA_RFID: position.set(Position.KEY_DRIVER_UNIQUE_ID, - buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII)); + buf.readSlice(length - 1).toString(StandardCharsets.US_ASCII)); position.set("authorized", buf.readUnsignedByte() != 0); break; diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java index 4e09d544a..1c2944a6c 100644 --- a/src/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/org/traccar/protocol/UproProtocolDecoder.java @@ -103,7 +103,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { if (headerIndex < 0) { headerIndex = buf.writerIndex(); } - String header = buf.readBytes(headerIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); + String header = buf.readSlice(headerIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); Parser parser = new Parser(PATTERN_HEADER, header); if (!parser.matches()) { @@ -138,7 +138,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { delimiterIndex = buf.writerIndex(); } - ByteBuf data = buf.readBytes(delimiterIndex - buf.readerIndex()); + ByteBuf data = buf.readSlice(delimiterIndex - buf.readerIndex()); switch (dataType) { case 'A': @@ -157,10 +157,10 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { break; case 'P': position.setNetwork(new Network(CellTower.from( - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)), - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)), - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16), - Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16)))); + Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)), + Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)), + Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII), 16), + Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII), 16)))); break; case 'Q': position.set("obd-pid", ByteBufUtil.hexDump(data)); diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index d0ee32c5d..d5035bd5c 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -57,7 +57,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(1); // header - String id = ByteBufUtil.hexDump(buf.readBytes(6)); + String id = ByteBufUtil.hexDump(buf.readSlice(6)); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/VtfmsFrameDecoder.java b/src/org/traccar/protocol/VtfmsFrameDecoder.java index 98072711f..62a189960 100644 --- a/src/org/traccar/protocol/VtfmsFrameDecoder.java +++ b/src/org/traccar/protocol/VtfmsFrameDecoder.java @@ -31,7 +31,7 @@ public class VtfmsFrameDecoder extends BaseFrameDecoder { if (endIndex > 0) { endIndex += 1 + 3; if (buf.writerIndex() >= endIndex) { - return buf.readBytes(endIndex - buf.readerIndex()); + return buf.readRetainedSlice(endIndex - buf.readerIndex()); } } diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 04da066c5..4e5d8c377 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -180,11 +180,11 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; buf.skipBytes(1); // header - manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII); + manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII); buf.skipBytes(1); // delimiter int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*'); - String id = buf.readBytes(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); + String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; @@ -198,7 +198,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { && buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) { int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex(); hasIndex = true; - index = buf.readBytes(indexLength).toString(StandardCharsets.US_ASCII); + index = buf.readSlice(indexLength).toString(StandardCharsets.US_ASCII); buf.skipBytes(1); // delimiter } @@ -212,7 +212,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { contentIndex = buf.writerIndex(); } - String type = buf.readBytes(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); + String type = buf.readSlice(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); if (contentIndex < buf.writerIndex()) { buf.readerIndex(contentIndex + 1); diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java index b09306b57..c223c87ff 100644 --- a/src/org/traccar/protocol/WondexFrameDecoder.java +++ b/src/org/traccar/protocol/WondexFrameDecoder.java @@ -38,7 +38,7 @@ public class WondexFrameDecoder extends BaseFrameDecoder { if (buf.getUnsignedByte(buf.readerIndex()) == 0xD0) { // Send response - ByteBuf frame = buf.readBytes(KEEP_ALIVE_LENGTH); + ByteBuf frame = buf.readRetainedSlice(KEEP_ALIVE_LENGTH); if (channel != null) { channel.writeAndFlush(new NetworkMessage(frame, channel.remoteAddress())); } @@ -48,7 +48,7 @@ public class WondexFrameDecoder extends BaseFrameDecoder { int index = BufferUtil.indexOf("\r\n", buf); if (index != -1) { - ByteBuf frame = buf.readBytes(index - buf.readerIndex()); + ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex()); buf.skipBytes(2); return frame; } diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java index 15011ac7a..114e94061 100644 --- a/src/org/traccar/protocol/XexunFrameDecoder.java +++ b/src/org/traccar/protocol/XexunFrameDecoder.java @@ -52,7 +52,7 @@ public class XexunFrameDecoder extends BaseFrameDecoder { buf.skipBytes(beginIndex - buf.readerIndex()); - return buf.readBytes(endIndex - beginIndex + 1); + return buf.readRetainedSlice(endIndex - beginIndex + 1); } } diff --git a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java index 25395238c..a01a64b5b 100644 --- a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java @@ -174,10 +174,10 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(buf.readUnsignedShort())); break; case 0x65: - position.set(Position.KEY_VIN, buf.readBytes(17).toString(StandardCharsets.US_ASCII)); + position.set(Position.KEY_VIN, buf.readSlice(17).toString(StandardCharsets.US_ASCII)); break; case 0x73: - position.set(Position.KEY_VERSION_FW, buf.readBytes(16).toString(StandardCharsets.US_ASCII).trim()); + position.set(Position.KEY_VERSION_FW, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim()); break; default: buf.skipBytes(getTagLength(tag)); -- cgit v1.2.3