Skip to content

Commit

Permalink
use a predefined dictionary for jar sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 8, 2025
1 parent 7fb4b51 commit ea99953
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/engines/
/models/

# maven specific files
# maven specific files
/target/

# eclipse specific files
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Long> 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<String, Long> 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);
}
}

0 comments on commit ea99953

Please sign in to comment.