Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
jerry - Common Java Functionality Copyright (c) 2012-2015, Sandeep Gupta http://sangupta.com/projects/jerry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
  
 package com.sangupta.jerry.store;
 
 import java.io.File;
 import java.util.List;
 import java.util.Set;
 
 
A java.util.Properties based UserLocalStore that makes use of properties to store all properties.

Author(s):
sangupta
 
 	
 	protected final File propertiesFile;
 	
 	protected final Properties properties;
 	
 	public PropertiesUserLocalStore(String folderNameString fileName) {
 		super(folderName);
 		
 		if(AssertUtils.isEmpty(fileName)) {
 			throw new IllegalArgumentException("Filename cannot be null/empty");
 		}
 		
 		this. = new File(this.fileName);
 		this. = new Properties();
 		
 		if(this..exists() && this..isFile()) {
 			try {
 			} catch (IOException e) {
 				throw new RuntimeException("Unable to read from the data store"e);
 			}
 		}
 	}
 
 	public String get(String property) {
 		return this..getProperty(property);
 	}
 	
 	public List<StringgetAllKeys() {
 		List<Stringlist = new ArrayList<String>();
 		
 		Set<Objectset = this..keySet();
 		for(Object o : set) {
 			list.add(o.toString());
 		}
 		
 		return list;
 	}
 
 	public void put(String keyString property) {
 		this..put(keyproperty);
 		save();
 	}
 
 	public void delete(String key) {
 		this..remove(key);
 		save();
 	}

Save the properties back to underlying storage
 
	private void save() {
		try {
			this..store(FileUtils.openOutputStream(this.false), " Updating from Properties data-store");
catch (IOException e) {
			throw new RuntimeException("Unable to write to the data store"e);
		}
	}
New to GrepCode? Check out our FAQ X