aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper/Crc.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 16:25:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 16:25:42 +1300
commit1570f3cda955c895498edafaa87b12aa4fdd6c33 (patch)
treedbd7b2fae6a48507e9e92d304282ba89657e6e6f /src/org/traccar/helper/Crc.java
parentc261ba04b0e8c1a0cc9c9be8a9fb7dfc6bf0d826 (diff)
downloadtrackermap-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.tar.gz
trackermap-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.tar.bz2
trackermap-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.zip
Fix checksum calculation methods
Diffstat (limited to 'src/org/traccar/helper/Crc.java')
-rw-r--r--src/org/traccar/helper/Crc.java20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java
index 7aa7d094a..3df6ffd71 100644
--- a/src/org/traccar/helper/Crc.java
+++ b/src/org/traccar/helper/Crc.java
@@ -99,21 +99,17 @@ public class Crc {
private static int crc16Unreflected(ByteBuffer buf, int crc_in, int[] table) {
int crc16 = crc_in;
-
- for (int i = 0; i < buf.remaining(); i++) {
- crc16 = table[((crc16 >> 8) ^ buf.get(i)) & 0xff] ^ (crc16 << 8);
+ 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;
-
- for (int i = 0; i < buf.remaining(); i++) {
- crc16 = table[(crc16 ^ buf.get(i)) & 0xff] ^ (crc16 >> 8);
+ while (buf.hasRemaining()) {
+ crc16 = table[(crc16 ^ buf.get()) & 0xff] ^ (crc16 >> 8);
}
-
return crc16 & 0xFFFF;
}
@@ -131,16 +127,16 @@ public class Crc {
public static int crc32(ByteBuffer buf) {
CRC32 checksum = new CRC32();
- for (int i = 0; i < buf.remaining(); i++) {
- checksum.update(buf.get(i));
+ while (buf.hasRemaining()) {
+ checksum.update(buf.get());
}
return (int) checksum.getValue();
}
public static int xorChecksum(ByteBuffer buf) {
int checksum = 0;
- for (int i = 0; i < buf.remaining(); i++) {
- checksum ^= buf.get(i);
+ while (buf.hasRemaining()) {
+ checksum ^= buf.get();
}
return checksum;
}