diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-09 11:43:50 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-09 11:43:50 +1300 |
commit | 81a7fba08c37fd8032c747ada5d9a77340298647 (patch) | |
tree | b7b0534868dfc130d1b8779ff0b8c7bf8c149dc5 /src/org/traccar | |
parent | 8e555ab17b231d93ab51713d6cb25510c0f92476 (diff) | |
download | trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.tar.gz trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.tar.bz2 trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.zip |
Fix some FindBugs and style issues
Diffstat (limited to 'src/org/traccar')
39 files changed, 156 insertions, 101 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 404cab2ba..00bf0a5e9 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -40,7 +40,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { private DistanceHandler distanceHandler; private ReverseGeocoderHandler reverseGeocoderHandler; - protected class OpenChannelHandler extends SimpleChannelHandler { + private static class OpenChannelHandler extends SimpleChannelHandler { private final TrackerServer server; @@ -54,7 +54,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { } } - protected class StandardLoggingHandler extends LoggingHandler { + private static class StandardLoggingHandler extends LoggingHandler { @Override public void log(ChannelEvent e) { diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index ae537abbe..eb84b4ac5 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -117,9 +117,6 @@ public class Context { int cacheSize = config.getInteger("geocoder.cacheSize"); switch (type) { - case "google": - reverseGeocoder = new GoogleReverseGeocoder(cacheSize); - break; case "nominatim": reverseGeocoder = new NominatimReverseGeocoder(url, cacheSize); break; @@ -138,6 +135,9 @@ public class Context { case "factual": reverseGeocoder = new FactualReverseGeocoder(url, key, cacheSize); break; + default: + reverseGeocoder = new GoogleReverseGeocoder(cacheSize); + break; } } diff --git a/src/org/traccar/DetectorHandler.java b/src/org/traccar/DetectorHandler.java index 8b2ac64c1..52e5e9bce 100644 --- a/src/org/traccar/DetectorHandler.java +++ b/src/org/traccar/DetectorHandler.java @@ -16,7 +16,11 @@ package org.traccar; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.*; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.jboss.netty.handler.codec.string.StringDecoder; import org.traccar.helper.Log; diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index f337b99cd..bf5232420 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -41,21 +41,23 @@ public class ServerManager { if (packageUrl.getProtocol().equals("jar")) { String jarFileName = URLDecoder.decode(packageUrl.getFile(), "UTF-8"); - JarFile jf = new JarFile(jarFileName.substring(5, jarFileName.indexOf("!"))); - - Enumeration<JarEntry> jarEntries = jf.entries(); - while(jarEntries.hasMoreElements()){ - String entryName = jarEntries.nextElement().getName(); - if (entryName.startsWith(packagePath) && entryName.length() > packagePath.length() + 5) { - names.add(entryName.substring(packagePath.length() + 1, entryName.lastIndexOf('.'))); + try (JarFile jf = new JarFile(jarFileName.substring(5, jarFileName.indexOf("!")))) { + Enumeration<JarEntry> jarEntries = jf.entries(); + while(jarEntries.hasMoreElements()){ + String entryName = jarEntries.nextElement().getName(); + if (entryName.startsWith(packagePath) && entryName.length() > packagePath.length() + 5) { + names.add(entryName.substring(packagePath.length() + 1, entryName.lastIndexOf('.'))); + } } } } else { File folder = new File(new URI(packageUrl.toString())); File[] files = folder.listFiles(); - for (File actual: files) { - String entryName = actual.getName(); - names.add(entryName.substring(0, entryName.lastIndexOf('.'))); + if (files != null) { + for (File actual: files) { + String entryName = actual.getName(); + names.add(entryName.substring(0, entryName.lastIndexOf('.'))); + } } } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 7f30fc6f3..66134d51e 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -144,18 +144,20 @@ public class DataManager implements IdentityManager { if (config.getString("web.type", "new").equals("new") || config.getString("web.type", "new").equals("api")) { - Connection connection = dataSource.getConnection(); - ResultSet result = connection.getMetaData().getTables( - connection.getCatalog(), null, null, null); - boolean exist = false; - String checkTable = config.getString("database.checkTable"); - while (result.next()) { - if (result.getString("TABLE_NAME").equalsIgnoreCase(checkTable)) { - exist = true; - break; + + try (Connection connection = dataSource.getConnection(); + ResultSet result = connection.getMetaData().getTables(connection.getCatalog(), null, null, null)) { + + String checkTable = config.getString("database.checkTable"); + while (result.next()) { + if (result.getString("TABLE_NAME").equalsIgnoreCase(checkTable)) { + exist = true; + break; + } } } + if (exist) { String schemaVersionQuery = getQuery("database.selectSchemaVersion"); @@ -174,25 +176,26 @@ public class DataManager implements IdentityManager { } } - return; - } + } else { - QueryBuilder.create(dataSource, getQuery("database.createSchema")).executeUpdate(); + QueryBuilder.create(dataSource, getQuery("database.createSchema")).executeUpdate(); - User admin = new User(); - admin.setName("admin"); - admin.setEmail("admin"); - admin.setAdmin(true); - admin.setPassword("admin"); - addUser(admin); + User admin = new User(); + admin.setName("admin"); + admin.setEmail("admin"); + admin.setAdmin(true); + admin.setPassword("admin"); + addUser(admin); - Server server = new Server(); - server.setRegistration(true); - QueryBuilder.create(dataSource, getQuery("database.insertServer")) - .setObject(server) - .executeUpdate(); + Server server = new Server(); + server.setRegistration(true); + QueryBuilder.create(dataSource, getQuery("database.insertServer")) + .setObject(server) + .executeUpdate(); - mockData(admin.getId()); + mockData(admin.getId()); + + } } } diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 5846d4285..07a351c05 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -41,7 +41,7 @@ import org.traccar.helper.Log; import org.traccar.model.Factory; import org.traccar.model.MiscFormatter; -public class QueryBuilder { +public final class QueryBuilder { private final Map<String, List<Integer>> indexMap = new HashMap<>(); private Connection connection; diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index e9cd21724..e42956228 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -71,7 +71,7 @@ public class ChannelBufferTools { result += b & 0x0f; } - if (length % 2 == 1) { + if (length % 2 != 0) { int b = buf.getUnsignedByte(buf.readerIndex()); result *= 10; result += b >>> 4; @@ -92,7 +92,7 @@ public class ChannelBufferTools { formatter.format("%02x", buf.readByte()); } - if (length % 2 == 1) { + if (length % 2 != 0) { int b = buf.getUnsignedByte(buf.readerIndex()); formatter.format("%01x", b >>> 4); } diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java index d3cec3880..5ff87c7dd 100644 --- a/src/org/traccar/helper/Checksum.java +++ b/src/org/traccar/helper/Checksum.java @@ -100,16 +100,16 @@ public class Checksum { public static final String CRC16_GENIBUS = "GENIBUS"; public static final String CRC16_MCRF4XX = "MCRF4XX"; - private static int crc16Unreflected(ByteBuffer buf, int crc_in, int[] table) { - int crc16 = crc_in; + private static int crc16Unreflected(ByteBuffer buf, int crcIn, int[] table) { + int crc16 = crcIn; while (buf.hasRemaining()) { crc16 = table[((crc16 >> 8) ^ buf.get()) & 0xff] ^ (crc16 << 8); } return crc16 & 0xFFFF; } - private static int crc16Reflected(ByteBuffer buf, int crc_in, int[] table) { - int crc16 = crc_in; + private static int crc16Reflected(ByteBuffer buf, int crcIn, int[] table) { + int crc16 = crcIn; while (buf.hasRemaining()) { crc16 = table[(crc16 ^ buf.get()) & 0xff] ^ (crc16 >> 8); } diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java index 7f51d3768..beb674b00 100644 --- a/src/org/traccar/helper/Hashing.java +++ b/src/org/traccar/helper/Hashing.java @@ -28,13 +28,21 @@ public class Hashing { public static class HashingResult { - public final String hash; - public final String salt; + private final String hash; + private final String salt; public HashingResult(String hash, String salt) { this.hash = hash; this.salt = salt; } + + public String getHash() { + return hash; + } + + public String getSalt() { + return salt; + } } private static byte[] function(char[] password, byte[] salt) { diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java index c52d3bf63..e8f5c605a 100644 --- a/src/org/traccar/helper/PatternBuilder.java +++ b/src/org/traccar/helper/PatternBuilder.java @@ -21,8 +21,6 @@ public class PatternBuilder { private final StringBuilder pattern = new StringBuilder(); - private final boolean collapse = true; - public PatternBuilder xpr(String s) { pattern.append(s); return this; @@ -38,10 +36,9 @@ public class PatternBuilder { } public PatternBuilder num(String s) { - if (collapse) { - s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}"); - s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}"); - } + s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}"); + s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}"); + pattern.append(s.replace("d", "\\d").replace("x", "\\p{XDigit}").replaceAll("([\\.\\|])", "\\\\$1")); return this; } diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java index 7622f78cd..698505983 100644 --- a/src/org/traccar/model/Device.java +++ b/src/org/traccar/model/Device.java @@ -67,11 +67,19 @@ public class Device implements Factory { private Date lastUpdate; public Date getLastUpdate() { - return lastUpdate; + if (lastUpdate != null) { + return new Date(lastUpdate.getTime()); + } else { + return null; + } } public void setLastUpdate(Date lastUpdate) { - this.lastUpdate = lastUpdate; + if (lastUpdate != null) { + this.lastUpdate = new Date(lastUpdate.getTime()); + } else { + this.lastUpdate = null; + } } private long positionId; diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 9ad54adbf..2e4d82c0b 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -92,21 +92,37 @@ public abstract class Event extends Extensible { private Date serverTime; public Date getServerTime() { - return serverTime; + if (serverTime != null) { + return new Date(serverTime.getTime()); + } else { + return null; + } } public void setServerTime(Date serverTime) { - this.serverTime = serverTime; + if (serverTime != null) { + this.serverTime = new Date(serverTime.getTime()); + } else { + this.serverTime = null; + } } private Date deviceTime; public Date getDeviceTime() { - return deviceTime; + if (deviceTime != null) { + return new Date(deviceTime.getTime()); + } else { + return null; + } } public void setDeviceTime(Date deviceTime) { - this.deviceTime = deviceTime; + if (deviceTime != null) { + this.deviceTime = new Date(deviceTime.getTime()); + } else { + this.deviceTime = null; + } } } diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java index 725270122..f62e1f42c 100644 --- a/src/org/traccar/model/MiscFormatter.java +++ b/src/org/traccar/model/MiscFormatter.java @@ -15,6 +15,7 @@ */ package org.traccar.model; +import org.traccar.helper.Log; import org.traccar.web.JsonConverter; import java.text.DecimalFormat; @@ -108,6 +109,9 @@ public class MiscFormatter { case FALSE: attributes.put(entry.getKey(), false); break; + default: + Log.warning(new IllegalArgumentException()); + break; } } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index ab535ba2b..1ed559ecd 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -27,11 +27,19 @@ public class Position extends Event implements Factory { private Date fixTime; public Date getFixTime() { - return fixTime; + if (fixTime != null) { + return new Date(fixTime.getTime()); + } else { + return null; + } } public void setFixTime(Date fixTime) { - this.fixTime = fixTime; + if (fixTime != null) { + this.fixTime = new Date(fixTime.getTime()); + } else { + this.fixTime = null; + } } public void setTime(Date time) { diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index f9534b87d..8ac9e9d32 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -155,8 +155,8 @@ public class User implements Factory { this.password = password; if (password != null && !password.isEmpty()) { Hashing.HashingResult hashingResult = Hashing.createHash(password); - hashedPassword = hashingResult.hash; - salt = hashingResult.salt; + hashedPassword = hashingResult.getHash(); + salt = hashingResult.getSalt(); } } diff --git a/src/org/traccar/protocol/AutoFon45FrameDecoder.java b/src/org/traccar/protocol/AutoFon45FrameDecoder.java index 8a96ceb4e..f382f4784 100644 --- a/src/org/traccar/protocol/AutoFon45FrameDecoder.java +++ b/src/org/traccar/protocol/AutoFon45FrameDecoder.java @@ -36,7 +36,7 @@ public class AutoFon45FrameDecoder extends FrameDecoder { return null; } - int length = 0; + int length; switch (buf.getUnsignedByte(buf.readerIndex())) { case MSG_LOGIN: length = 19; @@ -44,6 +44,9 @@ public class AutoFon45FrameDecoder extends FrameDecoder { case MSG_LOCATION: length = 34; break; + default: + length = 0; + break; } // Check length and return buffer diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java index 67438613c..8df23f27f 100644 --- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java @@ -129,4 +129,5 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { } return GPRS_CRC; } + } diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java index 55a28c081..1ad9e6d3b 100644 --- a/src/org/traccar/protocol/AutoFonFrameDecoder.java +++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java @@ -37,7 +37,7 @@ public class AutoFonFrameDecoder extends FrameDecoder { return null; } - int length = 0; + int length; switch (buf.getUnsignedByte(buf.readerIndex())) { case MSG_LOGIN: length = 12; @@ -48,6 +48,9 @@ public class AutoFonFrameDecoder extends FrameDecoder { case MSG_HISTORY: length = 257; break; + default: + length = 0; + break; } // Check length and return buffer diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index 04b0025a4..322ebd06e 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -129,7 +129,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { // Send response if (channel != null) { - channel.write(ChannelBuffers.wrappedBuffer(new byte[] { buf.readByte() })); + channel.write(ChannelBuffers.wrappedBuffer(new byte[] {buf.readByte()})); } } else if (type == MSG_LOCATION) { diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 1eb2cc4ad..1f1fdd6f8 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -101,7 +101,6 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { // GPS length and Satellites count int gpsLength = buf.readUnsignedByte(); position.set(Event.KEY_SATELLITES, gpsLength & 0xf); - gpsLength >>= 4; //Skip Satellite numbers buf.skipBytes(1); diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java index 7fd542c0b..3be0f5dfe 100644 --- a/src/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java @@ -38,8 +38,7 @@ public class CellocatorFrameDecoder extends FrameDecoder { // Size depending on message type int length = 0; - switch (buf.getUnsignedByte(4)) - { + switch (buf.getUnsignedByte(4)) { case CellocatorProtocolDecoder.MSG_CLIENT_STATUS: length = 70; break; diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 912a981b9..5738b5eda 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -196,7 +196,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_MCC, buf.readUnsignedShort()); position.set(Event.KEY_MNC, buf.readUnsignedByte()); position.set(Event.KEY_LAC, buf.readUnsignedShort()); - position.set(Event.KEY_CELL, buf.readUnsignedShort() << 8 + buf.readUnsignedByte()); + position.set(Event.KEY_CELL, (buf.readUnsignedShort() << 8) + buf.readUnsignedByte()); if (lbsLength > 0) { buf.skipBytes(lbsLength - 9); } diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index f5b914b1c..f518d422d 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -21,6 +21,8 @@ import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; import org.traccar.model.Command; +import java.nio.charset.Charset; + public class Gt06ProtocolEncoder extends BaseProtocolEncoder { private ChannelBuffer encodeContent(String content) { @@ -36,7 +38,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { buf.writeByte(4 + content.length()); // command length buf.writeInt(0); - buf.writeBytes(content.getBytes()); // command + buf.writeBytes(content.getBytes(Charset.defaultCharset())); // command buf.writeShort(0); // message index diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java index a2e3499c4..43a102f09 100644 --- a/src/org/traccar/protocol/IntellitracFrameDecoder.java +++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java @@ -25,7 +25,7 @@ public class IntellitracFrameDecoder extends DelimiterBasedFrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 0; - private static final byte delimiter[] = { (byte) '\r', (byte) '\n' }; + private static final byte delimiter[] = {(byte) '\r', (byte) '\n'}; public IntellitracFrameDecoder(int maxFrameLength) { super(maxFrameLength, ChannelBuffers.wrappedBuffer(delimiter)); @@ -34,10 +34,7 @@ public class IntellitracFrameDecoder extends DelimiterBasedFrameDecoder { // example of sync header: 0xFA 0xF8 0x1B 0x01 0x81 0x60 0x33 0x3C @Override - protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { // Check minimum length if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 4584c1862..6acdef406 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -81,7 +81,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_RFID = 0x9966; private boolean identify(ChannelBuffer buf, Channel channel) { - String id = ""; + StringBuilder builder = new StringBuilder(); for (int i = 0; i < 7; i++) { int b = buf.readUnsignedByte(); @@ -89,14 +89,16 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { // First digit int d1 = (b & 0xf0) >> 4; if (d1 == 0xf) break; - id += d1; + builder.append(d1); // Second digit int d2 = b & 0x0f; if (d2 == 0xf) break; - id += d2; + builder.append(d2); } + String id = builder.toString(); + // Try to recreate full IMEI number // Sometimes first digit is cut, so this won't work if (id.length() == 14 && identify(id + Checksum.luhn(Long.parseLong(id)), channel, null, false)) { diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java index 584b558d0..63b018deb 100644 --- a/src/org/traccar/protocol/MeitrackFrameDecoder.java +++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java @@ -35,8 +35,7 @@ public class MeitrackFrameDecoder extends FrameDecoder { } Integer index = ChannelBufferTools.find(buf, buf.readerIndex(), buf.writerIndex(), ","); - if (index != null) - { + if (index != null) { int length = index - buf.readerIndex() + Integer.parseInt(buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, Charset.defaultCharset())); if (buf.readableBytes() >= length) { return buf.readBytes(length); diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 220a0c552..82cba08a5 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -161,6 +161,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 37: position.set(Event.KEY_RFID, data); break; + default: + position.set("event-data", data); + break; } } diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 055e4278c..5e9bb5174 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -72,8 +72,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { private int previousFloat; public float readFloat(ChannelBuffer buf) { - switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) - { + switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) { case 0: previousFloat = buf.readInt() << 2; break; diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java index d361d20a1..b8d5910f5 100644 --- a/src/org/traccar/protocol/NavigilProtocolDecoder.java +++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java @@ -90,7 +90,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(buf.readInt() * 0.0000001); position.setLongitude(buf.readInt() * 0.0000001); - position.setAltitude( buf.readUnsignedShort()); + position.setAltitude(buf.readUnsignedShort()); buf.readUnsignedShort(); // satellites in fix buf.readUnsignedShort(); // satellites in track diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 8d00ce9e0..a4b900f96 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -58,7 +58,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { return false; } - private class ParseResult { + private static class ParseResult { private final long id; private final Position position; diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index 62f0b4219..a5a7d75a4 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -35,8 +35,6 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); - public static final int MSG_UPLOAD_POSITION = 0x0008; public static final int MSG_UPLOAD_POSITION_NEW = 0x0032; public static final int MSG_CONTROL_RESPONSE = 0x8009; @@ -133,6 +131,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { // Time if (newFormat) { + DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); position.setTime(dateFormat.parse(buf.readBytes(17).toString(Charset.defaultCharset()))); buf.readByte(); } diff --git a/src/org/traccar/protocol/Stl060FrameDecoder.java b/src/org/traccar/protocol/Stl060FrameDecoder.java index 9eee11a02..0c271b243 100644 --- a/src/org/traccar/protocol/Stl060FrameDecoder.java +++ b/src/org/traccar/protocol/Stl060FrameDecoder.java @@ -20,14 +20,13 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; +import org.traccar.CharacterDelimiterFrameDecoder; import org.traccar.helper.ChannelBufferTools; -public class Stl060FrameDecoder extends DelimiterBasedFrameDecoder { - - private static final byte delimiter[] = { (byte) '#' }; +public class Stl060FrameDecoder extends CharacterDelimiterFrameDecoder { public Stl060FrameDecoder(int maxFrameLength) { - super(maxFrameLength, ChannelBuffers.wrappedBuffer(delimiter)); + super('#'); } @Override diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java index ec3919ebe..da379ef58 100644 --- a/src/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -115,7 +115,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { } // Identification - else if (Character.isDigit(sentence.charAt(0)) & sentence.length() == 15) { + else if (Character.isDigit(sentence.charAt(0)) && sentence.length() == 15) { identify(sentence, channel); } diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java index 29a31cef1..5ea431709 100644 --- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java +++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java @@ -32,7 +32,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - static private final Pattern pattern = Pattern.compile( + private static final Pattern pattern = Pattern.compile( "\\(" + "(\\d+)" + // IMEI ".*" + diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java index 5df26229a..09e766e56 100644 --- a/src/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/org/traccar/protocol/WialonProtocolDecoder.java @@ -152,7 +152,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { if (params != null) { String[] values = params.split(","); for (String param : values) { - Matcher paramParser = Pattern.compile( "(.*):[1-3]:(.*)").matcher(param); + Matcher paramParser = Pattern.compile("(.*):[1-3]:(.*)").matcher(param); if (paramParser.matches()) { position.set(paramParser.group(1).toLowerCase(), paramParser.group(2)); } diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index d4e402185..0801f45fe 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -136,7 +136,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_STATUS, parser.group(index++)); // Send response - if ((type.equals("KP") || type.equals("EP") || type.equals("EP")) && channel != null) { + if ((type.equals("KP") || type.equals("EP")) && channel != null) { channel.write("%AT+" + type + "=" + reportId + "\r\n"); } diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java index 9d68c959c..d541e29c5 100644 --- a/src/org/traccar/web/AsyncServlet.java +++ b/src/org/traccar/web/AsyncServlet.java @@ -48,7 +48,7 @@ public class AsyncServlet extends BaseServlet { return true; } - public class AsyncSession { + public static class AsyncSession { private static final boolean DEBUG_ASYNC = false; diff --git a/src/org/traccar/web/PositionServlet.java b/src/org/traccar/web/PositionServlet.java index afd7bab2a..796d6a81f 100644 --- a/src/org/traccar/web/PositionServlet.java +++ b/src/org/traccar/web/PositionServlet.java @@ -56,7 +56,7 @@ public class PositionServlet extends BaseServlet { long userId = getUserId(req); Map<String, Object> positions = new HashMap<>(); - for(String deviceIdString : req.getParameterValues("devicesId")) { + for (String deviceIdString : req.getParameterValues("devicesId")) { Long deviceId = Long.parseLong(deviceIdString); Context.getPermissionsManager().checkDevice(userId, deviceId); diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index fc9b60beb..36c43736d 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -76,9 +76,9 @@ public class WebServer { ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase(config.getString("web.path")); if (config.getBoolean("web.debug")) { - resourceHandler.setWelcomeFiles(new String[] { "debug.html" }); + resourceHandler.setWelcomeFiles(new String[] {"debug.html"}); } else { - resourceHandler.setWelcomeFiles(new String[] { "release.html", "index.html" }); + resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"}); } handlers.addHandler(resourceHandler); } |