public static InputSupplier<InputStream> newConfigEntrySupplier(final URI configBundle, String entryName) { InputSupplier<InputStream> configBundleInput = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { URL url = configBundle.toURL(); URLConnection connection = url.openConnection(); if (connection instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.addRequestProperty("User-Agent", "User-Agent: Apache-Maven/3.0.3 (Java 1.6.0_29; Mac OS X 10.7.2)"); } InputStream in = connection.getInputStream(); return in; } }; return newConfigEntrySupplier(configBundleInput, entryName); }
public static ConfigurationFactory createConfigurationFactory(URI configUri) throws IOException { Properties properties = new Properties(); InputSupplier<InputStream> configPropertiesStream = newConfigEntrySupplier(configUri, "etc/config.properties"); InputStream input = configPropertiesStream.getInput(); try { properties.load(input); } finally { input.close(); } return new ConfigurationFactory((Map<String,String>) (Object) properties); } }
public static Map<String, Integer> readResources(Repository repository, Assignment assignment) { ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); InputSupplier<? extends InputStream> resourcesFile = newConfigEntrySupplier(repository, assignment.getConfig(), "galaxy-resources.properties"); if (resourcesFile != null) { try { Properties resources = new Properties(); resources.load(resourcesFile.getInput()); for (Entry<Object, Object> entry : resources.entrySet()) { builder.put((String) entry.getKey(), Integer.valueOf((String) entry.getValue())); } } catch (IOException ignored) { } } return builder.build(); } }
public static InputSupplier<InputStream> newConfigEntrySupplier(Repository repository, String config, final String entryName) { URI uri = repository.configToHttpUri(config); if (uri == null) { return null; } URL configUrl; try { configUrl = uri.toURL(); } catch (MalformedURLException e) { throw new RuntimeException("Invalid config bundle location " + uri); } return ConfigUtils.newConfigEntrySupplier(Resources.newInputStreamSupplier(configUrl), entryName); }
InputSupplier<? extends InputStream> configFile = ConfigUtils.newConfigEntrySupplier(repository, config, "galaxy-service-inventory.json"); if (configFile == null) { return null;