public BrooklynProperties addFrom(URL u) { try { return addFrom(u.openStream()); } catch (IOException e) { throw new RuntimeException("Error reading properties from "+u+": "+e, e); } } /**
public BrooklynProperties addFrom(File f) { if (!f.exists()) { LOG.warn("Unable to find file '"+f.getAbsolutePath()+"' when loading properties; ignoring"); return this; } else { try { return addFrom(new FileInputStream(f)); } catch (FileNotFoundException e) { throw Throwables.propagate(e); } } } public BrooklynProperties addFrom(URL u) {
public static BrooklynProperties loadFromFile(String file) { BrooklynProperties result = BrooklynProperties.Factory.newEmpty(); if (file!=null) result.addFrom(new File(file)); return result; }
private static void addPropertiesFromFile(BrooklynProperties p, String file) { String fileTidied = ResourceUtils.tidyFilePath(file); File f = new File(fileTidied); if (f.exists()) { p.addFrom(f); } } }
private static void addPropertiesFromUrl(BrooklynProperties p, String url, boolean warnIfNotFound) { try { p.addFrom(ResourceUtils.create(BrooklynProperties.class).getResourceFromUrl(url)); } catch (Exception e) { if (warnIfNotFound) LOG.warn("Could not load {}; continuing", url); if (LOG.isTraceEnabled()) LOG.trace("Could not load "+url+"; continuing", e); } }
/** * @see ResourceUtils#getResourceFromUrl(String) * * of the form form file:///home/... or http:// or classpath://xx ; * for convenience if not starting with xxx: it is treated as a classpath reference or a file; * throws if not found (but does nothing if argument is null) */ public BrooklynProperties addFromUrl(String url) { try { if (url==null) return this; return addFrom(ResourceUtils.create(this).getResourceFromUrl(url)); } catch (Exception e) { throw new RuntimeException("Error reading properties from "+url+": "+e, e); } }