mirror of
https://github.com/traccar/traccar.git
synced 2026-07-31 10:29:19 -04:00
Extract string strip helpers
This commit is contained in:
@@ -36,4 +36,12 @@ public final class StringUtil {
|
||||
return value.substring(start);
|
||||
}
|
||||
|
||||
public static String stripTrailing(char c, String value) {
|
||||
int end = value.length();
|
||||
while (end > 1 && value.charAt(end - 1) == c) {
|
||||
end--;
|
||||
}
|
||||
return value.substring(0, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.traccar.session.DeviceSession;
|
||||
import org.traccar.NetworkMessage;
|
||||
import org.traccar.Protocol;
|
||||
import org.traccar.helper.BitUtil;
|
||||
import org.traccar.helper.StringUtil;
|
||||
import org.traccar.helper.UnitsConverter;
|
||||
import org.traccar.model.Position;
|
||||
|
||||
@@ -166,7 +167,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
|
||||
int content = buf.readUnsignedByte();
|
||||
|
||||
if (BitUtil.check(content, 0)) {
|
||||
String id = ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte())).replace("f", "");
|
||||
String id = StringUtil.stripTrailing(
|
||||
'f', ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte())));
|
||||
getDeviceSession(channel, remoteAddress, id);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.traccar.helper.Checksum;
|
||||
import org.traccar.helper.DateBuilder;
|
||||
import org.traccar.helper.Parser;
|
||||
import org.traccar.helper.PatternBuilder;
|
||||
import org.traccar.helper.StringUtil;
|
||||
import org.traccar.helper.UnitsConverter;
|
||||
import org.traccar.model.CellTower;
|
||||
import org.traccar.model.Network;
|
||||
@@ -1226,7 +1227,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
|
||||
|
||||
buf.skipBytes(8); // imei
|
||||
buf.skipBytes(8); // imsi
|
||||
position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(buf.readSlice(10)).replaceAll("f", ""));
|
||||
position.set(Position.KEY_ICCID, StringUtil.stripTrailing(
|
||||
'f', ByteBufUtil.hexDump(buf.readSlice(10))));
|
||||
return position;
|
||||
|
||||
} else if (subType == 0x0b) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.traccar.helper.BitUtil;
|
||||
import org.traccar.helper.DateBuilder;
|
||||
import org.traccar.helper.Parser;
|
||||
import org.traccar.helper.PatternBuilder;
|
||||
import org.traccar.helper.StringUtil;
|
||||
import org.traccar.helper.UnitsConverter;
|
||||
import org.traccar.model.CellTower;
|
||||
import org.traccar.model.Network;
|
||||
@@ -122,7 +123,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
|
||||
|
||||
buf.readByte(); // header
|
||||
|
||||
String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5))));
|
||||
String id = StringUtil.stripLeading('0', ByteBufUtil.hexDump(buf.readSlice(5)));
|
||||
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
|
||||
if (deviceSession == null) {
|
||||
return null;
|
||||
|
||||
@@ -1124,8 +1124,8 @@ public class Jt808ProtocolDecoder extends BaseProtocolDecoder {
|
||||
}
|
||||
break;
|
||||
case 0x00B2:
|
||||
position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(
|
||||
buf.readSlice(10)).replaceAll("f", ""));
|
||||
position.set(Position.KEY_ICCID, StringUtil.stripTrailing(
|
||||
'f', ByteBufUtil.hexDump(buf.readSlice(10))));
|
||||
break;
|
||||
case 0x00B9:
|
||||
buf.readUnsignedByte(); // count
|
||||
|
||||
Reference in New Issue
Block a user