From 4b4d68a4e6ee3bad66e00bd9905c572ad9c7b91b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 4 May 2016 13:26:16 +1200 Subject: Explicitly use ASCII charset --- src/org/traccar/protocol/NoranProtocolDecoder.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol/NoranProtocolDecoder.java') diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index ff1bc2549..693947e58 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -15,11 +15,6 @@ */ package org.traccar.protocol; -import java.net.SocketAddress; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; @@ -30,6 +25,12 @@ import org.traccar.helper.UnitsConverter; import org.traccar.model.Event; import org.traccar.model.Position; +import java.net.SocketAddress; +import java.nio.ByteOrder; +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + public class NoranProtocolDecoder extends BaseProtocolDecoder { public NoranProtocolDecoder(NoranProtocol protocol) { @@ -59,13 +60,13 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13); response.writeBytes( - ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", Charset.defaultCharset())); + ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII)); response.writeByte(0); response.writeShort(response.capacity()); response.writeShort(MSG_SHAKE_HAND_RESPONSE); response.writeByte(1); // status response.writeBytes( - ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset())); + ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII)); channel.write(response, remoteAddress); @@ -119,7 +120,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { } else { rawId = buf.readBytes(11); } - String id = rawId.toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", ""); + String id = rawId.toString(StandardCharsets.US_ASCII).replaceAll("[^\\p{Print}]", ""); if (!identify(id, channel, remoteAddress)) { return null; } @@ -127,7 +128,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(Charset.defaultCharset()))); + position.setTime(dateFormat.parse(buf.readBytes(17).toString(StandardCharsets.US_ASCII))); buf.readByte(); } -- cgit v1.2.3