diff --git a/components/formats-bsd/src/loci/formats/out/DicomWriter.java b/components/formats-bsd/src/loci/formats/out/DicomWriter.java index 027d7b27bb3..ff8703b7103 100644 --- a/components/formats-bsd/src/loci/formats/out/DicomWriter.java +++ b/components/formats-bsd/src/loci/formats/out/DicomWriter.java @@ -146,8 +146,14 @@ public DicomWriter() { // -- IExtraMetadataWriter API methods -- + /** + * Add a tag provider. + * + * tagSource is expected to be either an ITagProvider, + * or a String file name that can be read by DicomJSONProvider. + */ @Override - public void setExtraMetadata(String tagSource) { + public void setExtraMetadata(Object tagSource) { FormatTools.assertId(currentId, false, 1); StopWatch metadataWatch = stopWatch(); @@ -157,20 +163,23 @@ public void setExtraMetadata(String tagSource) { if (tagSource != null) { ITagProvider provider = null; - if (checkSuffix(tagSource, "json")) { + if (tagSource instanceof ITagProvider) { + provider = (ITagProvider) tagSource; + } + else if (tagSource instanceof String && checkSuffix((String) tagSource, "json")) { provider = new DicomJSONProvider(); + try { + provider.readTagSource((String) tagSource); + } + catch (IOException e) { + LOGGER.error("Could not parse extra metadata: " + tagSource, e); + } } else { throw new IllegalArgumentException("Unknown tag format: " + tagSource); } - try { - provider.readTagSource(tagSource); - tagProviders.add(provider); - } - catch (IOException e) { - LOGGER.error("Could not parse extra metadata: " + tagSource, e); - } + tagProviders.add(provider); } metadataWatch.stop("parsed extra metadata from " + tagSource); } diff --git a/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java b/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java index 7cc1da2170d..5bf392bde46 100644 --- a/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java +++ b/components/formats-bsd/src/loci/formats/out/IExtraMetadataWriter.java @@ -48,6 +48,6 @@ public interface IExtraMetadataWriter { * * All calls to this method must occur before setId is called. */ - void setExtraMetadata(String metadataSource); + void setExtraMetadata(Object metadataSource); }