public void update(final Map<String, String> props) throws IOException { if (props == null) return; lock.lock(); try { boolean save = false; for(Entry<String, String> e : props.entrySet()) { if (!e.getValue().equals(get().get(e.getKey()))) { get().put(e.getKey(), e.getValue()); save = true; } } if (save) { write(); } } finally { lock.unlock(); } }
public Properties get() throws IOException { lock.lock(); try { if (m_properties == null) { readWithDefault(new Properties()); } else { if (m_checkLastModify && m_file.canRead() && m_lastModify != m_file.lastModified()) { m_properties = read(); } } return m_properties; } finally { lock.unlock(); } }
private void readWithDefault(final Properties deflt) throws IOException { // this is if (deflt == null && !m_file.canRead()) { // nothing to load so m_properties remains null no writing necessary // just return to avoid getting the write lock return; } if (m_properties == null) { m_properties = read(); if (m_properties == null) { m_properties = deflt; } } }
/** * <p>getProperty</p> * * @param propFile a {@link java.io.File} object. * @param key a {@link java.lang.String} object. * @return a {@link java.lang.String} object. * @throws java.io.IOException if any. */ public String getProperty(final File propFile, final String key) throws IOException { return getHolder(propFile).getProperty(key); } }
/** * <p>saveProperties</p> * * @param propFile a {@link java.io.File} object. * @param properties a {@link java.util.Properties} object. * @throws java.io.IOException if any. */ public void saveProperties(final File propFile, final Properties properties) throws IOException { getHolder(propFile).put(properties); }
@Override public PropertiesHolder call() throws Exception { return new PropertiesHolder(propFile); } });
public Properties find() throws IOException { lock.lock(); try { if (m_properties == null) { readWithDefault(null); } return m_properties; } finally { lock.unlock(); } }
/** * <p>setProperty</p> * * @param propFile a {@link java.io.File} object. * @param key a {@link java.lang.String} object. * @param value a {@link java.lang.String} object. * @throws java.io.IOException if any. */ public void setProperty(final File propFile, final String key, final String value) throws IOException { getHolder(propFile).setProperty(key, value); }
/** * Get the current properties object from the cache loading it in memory * * @param propFile a {@link java.io.File} object. * @throws java.io.IOException if any. * @return a {@link java.util.Properties} object. */ public Properties getProperties(final File propFile) throws IOException { return getHolder(propFile).get(); }
public void put(final Properties properties) throws IOException { lock.lock(); try { m_properties = properties; write(); } finally { lock.unlock(); } }
/** * <p>updateProperties</p> * * @param propFile a {@link java.io.File} object. * @param props a {@link java.util.Map} object. * @throws java.io.IOException if any. */ public void updateProperties(final File propFile, final Map<String, String> props) throws IOException { getHolder(propFile).update(props); }
/** * <p>findProperties</p> * * @param propFile a {@link java.io.File} object. * @return a {@link java.util.Properties} object. * @throws java.io.IOException if any. */ public Properties findProperties(final File propFile) throws IOException { return getHolder(propFile).find(); } /**
public String getProperty(final String key) throws IOException { lock.lock(); try { return get().getProperty(key); } finally { lock.unlock(); } } }