Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonical loading of location4j.bin file from classpath #10

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Build
on:
push:
paths:
- 'src/**'
- 'library/src/**'
- 'pom.xml'
- '.github/**'
pull_request:
paths:
- 'src/**'
- 'library/src/**'
- 'pom.xml'
- '.github/**'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* The default loader for retrieving Countries from the DEFAULT_FILE located in the location4j.jar
*
*/
public class DefaultCountriesDataLoaderImpl implements CountriesDataLoader {

private static final String DEFAULT_FILE = "location4j.bin";
private static final String DEFAULT_FILE = "/location4j.bin";
private final List<Country> countries = new ArrayList<>();

/**
* Loads a list of {@link Country} from the location4j.bin file.
*/
public DefaultCountriesDataLoaderImpl() {
var logger = Logger.getLogger(this.getClass().getName());
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(DEFAULT_FILE)) {
try (InputStream inputStream = getClass().getResourceAsStream(DEFAULT_FILE)) {
logger.info("Attempting to load countries from " + DEFAULT_FILE);
if (inputStream == null) {
throw new IllegalArgumentException("File not found: " + DEFAULT_FILE);
Expand All @@ -34,7 +38,6 @@ public DefaultCountriesDataLoaderImpl() {
private void loadLocationsFromBinary(InputStream inputStream, Logger logger)
throws IOException, ClassNotFoundException {
try (var objectInputStream = new ObjectInputStream(inputStream)) {
// Read the list of countries from the binary file
List<Country> loadedCountries = (List<Country>) objectInputStream.readObject();
this.countries.addAll(loadedCountries);
logger.info("Successfully loaded countries binary file");
Expand Down
Loading