From b046228d8523747858b4a8d1b596c70ae6d13ed4 Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Fri, 12 Jan 2024 17:05:58 -0700 Subject: [PATCH 1/3] Add getLastModified override for the ZarrIosp --- cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrIosp.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrIosp.java b/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrIosp.java index 15bf286267..971d102473 100644 --- a/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrIosp.java +++ b/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrIosp.java @@ -139,4 +139,9 @@ private Object getFillValue(ZarrHeader.VInfo vinfo, DataType dataType) { } return fillValue; } + + @Override + public long getLastModified() { + return raf.getLastModified(); + } } From 497a06fc0cd25da6f452e2608eea5f76e8b34fb2 Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Fri, 12 Jan 2024 17:06:25 -0700 Subject: [PATCH 2/3] Avoid closing raf belonging to item which is still in use --- cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java b/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java index a1734bf658..24854661f6 100644 --- a/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java +++ b/cdm/zarr/src/main/java/ucar/nc2/iosp/zarr/ZarrHeader.java @@ -227,7 +227,8 @@ private void makeVariable(RandomAccessDirectoryItem item, long dataOffset, ZArra private List makeAttributes(RandomAccessDirectoryItem item) { // get RandomAccessFile for JSON parsing - try (RandomAccessFile raf = item.getOrOpenRaf()) { + try { + RandomAccessFile raf = item.getOrOpenRaf(); // read attributes from file raf.seek(0); Map attrMap = objectMapper.readValue(raf, HashMap.class); From 4992256f9e56466584b9147e83a7a56cce2808e0 Mon Sep 17 00:00:00 2001 From: Tara Drwenski Date: Fri, 12 Jan 2024 17:06:56 -0700 Subject: [PATCH 3/3] Add test for zarr last modified --- .../src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java b/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java index 7eb8f7e653..e2f93781fd 100644 --- a/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java +++ b/cdm/zarr/src/test/java/ucar/nc2/iosp/zarr/TestZarrIosp.java @@ -296,4 +296,12 @@ public void testFillValues() throws IOException { assertThat(double_ninf.getDouble(0)).isEqualTo(Double.NEGATIVE_INFINITY); } + @Test + public void testLastModified() throws IOException { + for (String uri : stores) { + try (NetcdfFile ncfile = NetcdfFiles.open(uri)) { + assertThat(ncfile.getLastModified()).isNotEqualTo(0); + } + } + } }