private static Properties loadPropertiesFile(final String fileName) { final Properties props = new Properties(); for (final URL url : LoaderUtil.findResources(fileName)) { try (final InputStream in = url.openStream()) { props.load(in); } catch (IOException e) { LowLevelLogUtil.logException("Unable to read " + url, e); } } return props; }
/** * Constructs a PropertiesUtil for a given properties file name on the classpath. The properties specified in this * file are used by default. If a property is not defined in this file, then the equivalent system property is used. * * @param propertiesFileName the location of properties file to load */ public PropertiesUtil(final String propertiesFileName) { final Properties properties = new Properties(); for (final URL url : LoaderUtil.findResources(propertiesFileName)) { try (final InputStream in = url.openStream()) { properties.load(in); } catch (final IOException ioe) { LowLevelLogUtil.logException("Unable to read " + url.toString(), ioe); } } this.props = properties; }
public ClassPathCatalogReader(Map<String, String> attributes) throws IOException { String catalogFile = attributes != null ? attributes.getOrDefault(CATALOG_ATTRIBUTE_NAME, DEFAULT_CATALOG_FILE) : DEFAULT_CATALOG_FILE; Collection<URL> catalogs = LoaderUtil.findResources(catalogFile); URL catalogURL; if (catalogs.size() == 0) { LOGGER.error("No catalog named {} could be found on the class path", catalogFile); throw new FileNotFoundException("No catalog named " + catalogFile + " could be found"); } else if (catalogs.size() > 1) { catalogURL = catalogs.stream().findFirst().get(); LOGGER.warn("Multiple catalogs named {} were found. Using {}", catalogFile, catalogURL.toString()); } else { catalogURL = catalogs.stream().findFirst().get(); } catalog = readCatalog(catalogURL); LocalDateTime localDateTime = null; try { URLConnection connection = catalogURL.openConnection(); localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(connection.getLastModified()), ZoneId.systemDefault()); } catch (IOException ioe) { LOGGER.warn("Unable to open connection to {}", catalogURL.toString()); } lastUpdated = localDateTime; JsonFactory factory = new JsonFactory(); factory.enable(JsonParser.Feature.ALLOW_COMMENTS); ObjectMapper objectMapper = new ObjectMapper(factory); catalogData = objectMapper.readValue(catalog, CatalogData.class); }