diff --git a/cdm/core/src/main/java/ucar/nc2/filter/Checksum32.java b/cdm/core/src/main/java/ucar/nc2/filter/Checksum32.java index f42a762adf..1a4f9d6d99 100644 --- a/cdm/core/src/main/java/ucar/nc2/filter/Checksum32.java +++ b/cdm/core/src/main/java/ucar/nc2/filter/Checksum32.java @@ -59,7 +59,8 @@ public byte[] encode(byte[] dataIn) { int dataStart = this.type == CType.FLETCHER ? 0 : nbytes; System.arraycopy(dataIn, 0, dataOut, dataStart, dataIn.length); int checksumStart = this.type == CType.FLETCHER ? dataOut.length - nbytes : 0; - System.arraycopy(Ints.toByteArray(checksum), 0, dataOut, checksumStart, nbytes);; + // encode as little endian by default + System.arraycopy(Ints.toByteArray(Integer.reverseBytes(checksum)), 0, dataOut, checksumStart, nbytes);; return dataOut; } @@ -76,7 +77,7 @@ public byte[] decode(byte[] dataIn) { byte[] bytes = new byte[nbytes]; int checksumStart = this.type == CType.FLETCHER ? dataIn.length - nbytes : 0; System.arraycopy(dataIn, checksumStart, bytes, 0, nbytes); - int i = Ints.fromByteArray(bytes); + int i = Integer.reverseBytes(Ints.fromByteArray(bytes)); // convert from little endian if (i != checksum) { throw new RuntimeException("Checksum invalid"); } @@ -145,7 +146,7 @@ public void update(byte[] b, int off, int len) { @Override public long getValue() { - return Integer.reverseBytes((int) ((sum2 << 16) | sum1)); + return (sum2 << 16) | sum1; } }