diff --git a/cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java b/cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java index bab1d8c72a..41c11ca5b8 100644 --- a/cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java +++ b/cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java @@ -360,20 +360,20 @@ private int writeIntValue(ByteBuffer buffer, IFDEntry ifd, int v) { case 2: case 6: case 7: - // unsigned byte and ascii - // signed byte and undefined (usually treated as raw binary) + // unsigned byte and ascii + // signed byte and undefined (usually treated as raw binary) buffer.put((byte) v); return 1; case 3: case 8: - // unsigned and signed short + // unsigned and signed short buffer.putShort((short) v); return 2; case 4: case 5: case 9: case 10: - // unsigned and signed rational and 32-bit integer + // unsigned and signed rational and 32-bit integer buffer.putInt(v); return 4; } @@ -558,32 +558,29 @@ private void readValues(ByteBuffer buffer, IFDEntry ifd) { private int readIntValue(ByteBuffer buffer, IFDEntry ifd) { switch (ifd.type.code) { case 1: - // unsigned byte - //return (int) buffer.get() & 0xff; case 2: - // unsigned ascii + // unsigned byte and unsigned ascii return (int) buffer.get() & 0xff; case 3: - // unsigned short + // unsigned short return readUShortValue(buffer); case 4: case 5: - // unsigned rational and 32-bit integer + // unsigned rational and unsigned 32-bit integer // Yes, this can lead to truncation. This is a bug // in the design of the IFDEntry API return (int) (buffer.getInt() & 0xffffffffL); - //return buffer.getInt(); case 6: case 7: - // signed byte & "undefined" (usually treated as binary data + // signed byte and "undefined" (usually treated as binary data) return (int) buffer.get(); case 8: - // signed short - return (int) buffer.getShort(); + // signed short + return (int) buffer.getShort(); case 9: case 10: - // signed rational and 32-bit integer - return buffer.getInt(); + // signed rational and signed 32-bit integer + return buffer.getInt(); } return 0; } diff --git a/cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java b/cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java index e293bdb3db..fdd3873944 100644 --- a/cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java +++ b/cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java @@ -55,7 +55,7 @@ public static List getTestParameters() { // for all possible values because Java's integer is signed. result.add(new Object[] {new IFDEntry(null, FieldType.LONG, 1), Integer.MAX_VALUE}); - //Signed + // Signed result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), 0}); result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), Byte.MIN_VALUE}); result.add(new Object[] {new IFDEntry(null, FieldType.SBYTE, 1), Byte.MAX_VALUE}); @@ -89,8 +89,8 @@ public void testRoundtrip() throws ReflectiveOperationException { ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; buffer.order(byteOrder); - logger.info("geotiff methods: {}", geotiff.getClass().getDeclaredMethods()); - Method writeMethod = geotiff.getClass().getDeclaredMethod("writeIntValue", ByteBuffer.class, ifd.getClass(), int.class); + Method writeMethod = + geotiff.getClass().getDeclaredMethod("writeIntValue", ByteBuffer.class, ifd.getClass(), int.class); Method readMethod = geotiff.getClass().getDeclaredMethod("readIntValue", ByteBuffer.class, ifd.getClass()); readMethod.setAccessible(true); writeMethod.setAccessible(true);