diff --git a/src/loci/formats/services/JZarrServiceImpl.java b/src/loci/formats/services/JZarrServiceImpl.java index 731a6b8..26a8540 100644 --- a/src/loci/formats/services/JZarrServiceImpl.java +++ b/src/loci/formats/services/JZarrServiceImpl.java @@ -94,13 +94,7 @@ public JZarrServiceImpl(String root) { @Override public void open(String file) throws IOException, FormatException { currentId = file; - if (s3fs == null) { - zarrArray = ZarrArray.open(file); - } - else { - s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(file)); - zarrArray = ZarrArray.open(s3fs); - } + zarrArray = getArray(file); } public void open(String id, ZarrArray array) { @@ -109,15 +103,7 @@ public void open(String id, ZarrArray array) { } public Map getGroupAttr(String path) throws IOException, FormatException { - ZarrGroup group = null; - if (s3fs == null) { - group = ZarrGroup.open(path); - } - else { - s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); - group = ZarrGroup.open(s3fs); - } - return group.getAttributes(); + return getGroup(path).getAttributes(); } public Map getArrayAttr(String path) throws IOException, FormatException { @@ -129,31 +115,15 @@ public Map getArrayAttr(String path) throws IOException, FormatE s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); array = ZarrArray.open(s3fs); } - return array.getAttributes(); + return getArray(path).getAttributes(); } public Set getGroupKeys(String path) throws IOException, FormatException { - ZarrGroup group = null; - if (s3fs == null) { - group = ZarrGroup.open(path); - } - else { - s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); - group = ZarrGroup.open(s3fs); - } - return group.getGroupKeys(); + return getGroup(path).getGroupKeys(); } public Set getArrayKeys(String path) throws IOException, FormatException { - ZarrGroup group = null; - if (s3fs == null) { - group = ZarrGroup.open(path); - } - else { - s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); - group = ZarrGroup.open(s3fs); - } - return group.getArrayKeys(); + return getGroup(path).getArrayKeys(); } public DataType getZarrPixelType(int pixType) { @@ -379,4 +349,27 @@ private String getZarrRoot(String path) { return path.substring(0, path.indexOf(".zarr")+5); } + private ZarrGroup getGroup(String path) throws IOException { + ZarrGroup group = null; + if (s3fs == null) { + group = ZarrGroup.open(path); + } + else { + s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); + group = ZarrGroup.open(s3fs); + } + return group; + } + + private ZarrArray getArray(String path) throws IOException { + ZarrArray array = null; + if (s3fs == null) { + array = ZarrArray.open(path); + } + else { + s3fs.updateRoot(getZarrRoot(s3fs.getRoot()) + stripZarrRoot(path)); + array = ZarrArray.open(s3fs); + } + return array; + } }