diff --git a/.gitignore b/.gitignore index 35a4b677..7aa8b531 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /engines/ /models/ -# maven specific files +# maven specific files /target/ # eclipse specific files diff --git a/src/main/java/io/bioimage/modelrunner/versionmanagement/JarInfo.java b/src/main/java/io/bioimage/modelrunner/versionmanagement/JarInfo.java new file mode 100644 index 00000000..e2184f88 --- /dev/null +++ b/src/main/java/io/bioimage/modelrunner/versionmanagement/JarInfo.java @@ -0,0 +1,63 @@ +package io.bioimage.modelrunner.versionmanagement; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.net.URL; +import java.util.Map; + +public class JarInfo { + + // Static instance for the Singleton + private static JarInfo instance; + + // Map to store the parsed JSON data + private Map urlData; + + private static URL FILE_PATH = JarInfo.class.getClassLoader().getResource("jar_sizes.json"); + + // Private constructor to restrict instantiation + private JarInfo() throws IOException { + loadJsonData(); + } + + /** + * Public method to initialize or get the singleton instance. + * + * @return The single instance of {@link JarInfo} + * @throws IOException If the file cannot be loaded + */ + public static JarInfo getInstance() throws IOException { + if (instance == null) { + instance = new JarInfo(); + } + return instance; + } + + /** + * Public method to access the URL data + * + * @return Map containing the URL and their respective sizes + */ + public Map getUrlData() { + return urlData; + } + + /** + * Method to retrieve the size for a specific URL + * + * @param url The URL to look up + * @return The size associated with the URL, or null if not found + */ + public Long getSizeForUrl(String url) { + return urlData.get(url); + } + + // Private method to load and parse the JSON data + @SuppressWarnings("unchecked") + private void loadJsonData() throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + urlData = objectMapper.readValue(FILE_PATH, Map.class); + } +} +