Skip to content

Commit

Permalink
Merge branch 'maint-5.x' into palette_support
Browse files Browse the repository at this point in the history
  • Loading branch information
WeatherGod authored May 7, 2024
2 parents b5a17bb + b05e193 commit 2008dd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
14 changes: 7 additions & 7 deletions cdm/misc/src/main/java/ucar/nc2/geotiff/GeoTiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private void writeIFDEntry(FileChannel channel, IFDEntry ifd, int start) throws
}
}

private int writeValues(ByteBuffer buffer, IFDEntry ifd) {
static int writeValues(ByteBuffer buffer, IFDEntry ifd) {
int done = 0;

if (ifd.type == FieldType.ASCII) {
Expand Down Expand Up @@ -379,7 +379,7 @@ private int writeValues(ByteBuffer buffer, IFDEntry ifd) {
return done;
}

private int writeIntValue(ByteBuffer buffer, IFDEntry ifd, int v) {
static int writeIntValue(ByteBuffer buffer, IFDEntry ifd, int v) {
switch (ifd.type.code) {
case 1:
case 2:
Expand All @@ -405,7 +405,7 @@ private int writeIntValue(ByteBuffer buffer, IFDEntry ifd, int v) {
return 0;
}

private int writeSValue(ByteBuffer buffer, IFDEntry ifd) {
static int writeSValue(ByteBuffer buffer, IFDEntry ifd) {
buffer.put(ifd.valueS.getBytes(StandardCharsets.UTF_8));
int size = ifd.valueS.length();
if ((size & 1) != 0)
Expand Down Expand Up @@ -552,7 +552,7 @@ private IFDEntry readIFDEntry(FileChannel channel, int start) throws IOException
return ifd;
}

private void readValues(ByteBuffer buffer, IFDEntry ifd) {
static void readValues(ByteBuffer buffer, IFDEntry ifd) {

if (ifd.type == FieldType.ASCII) {
ifd.valueS = readSValue(buffer, ifd);
Expand Down Expand Up @@ -580,7 +580,7 @@ private void readValues(ByteBuffer buffer, IFDEntry ifd) {

}

private int readIntValue(ByteBuffer buffer, IFDEntry ifd) {
static int readIntValue(ByteBuffer buffer, IFDEntry ifd) {
switch (ifd.type.code) {
case 1:
case 2:
Expand Down Expand Up @@ -610,11 +610,11 @@ private int readIntValue(ByteBuffer buffer, IFDEntry ifd) {
return 0;
}

private int readUShortValue(ByteBuffer buffer) {
static int readUShortValue(ByteBuffer buffer) {
return buffer.getShort() & 0xffff;
}

private String readSValue(ByteBuffer buffer, IFDEntry ifd) {
static String readSValue(ByteBuffer buffer, IFDEntry ifd) {
byte[] dst = new byte[ifd.count];
buffer.get(dst);
return new String(dst, StandardCharsets.UTF_8);
Expand Down
22 changes: 6 additions & 16 deletions cdm/misc/src/test/java/ucar/nc2/geotiff/TestIFDEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.lang.ReflectiveOperationException;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -30,9 +26,8 @@
@RunWith(Parameterized.class)
public class TestIFDEntry {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public IFDEntry ifd;
// Because we are dealing with reflection
public int testValue;
private final IFDEntry ifd;
private final int testValue;

@Parameterized.Parameters(name = "{0}_{1}")
public static List<Object[]> getTestParameters() {
Expand Down Expand Up @@ -82,22 +77,17 @@ public TestIFDEntry(IFDEntry ifd, int testValue) {
}

@Test
public void testRoundtrip() throws ReflectiveOperationException {
GeoTiff geotiff = new GeoTiff("foobar");
public void testRoundtrip() {
// 16 bytes should be more than enough
ByteBuffer buffer = ByteBuffer.allocate(16);
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
buffer.order(byteOrder);

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);
int writeSize = (int) writeMethod.invoke(geotiff, buffer, ifd, testValue);
int writeSize = GeoTiff.writeIntValue(buffer, ifd, testValue);
Assert.assertEquals(ifd.type.size, writeSize);
buffer.position(0);

int readValue = (int) readMethod.invoke(geotiff, buffer, ifd);
int readValue = GeoTiff.readIntValue(buffer, ifd);

Assert.assertEquals(testValue, readValue);
}
Expand Down

0 comments on commit 2008dd2

Please sign in to comment.