Skip to content

Commit

Permalink
Merge pull request #10 from tomaytotomato/9-canonical-loading
Browse files Browse the repository at this point in the history
Canonical loading of location4j.bin file from classpath
  • Loading branch information
tomaytotomato authored Aug 9, 2024
2 parents bd0d083 + 659b7aa commit 51b3d14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 51b3d14

Please sign in to comment.