/* Storer.java * * Copyright (c) 2003, Benja Fallenstein * * This file is part of Gzz. * * Gzz is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Gzz is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Gzz; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein */ package gzz.mediaserver.storage; import java.io.*; import java.util.*; public interface Storer { Set getKeys() throws IOException; OutputStream store(String key) throws IOException; InputStream retrieve(String key) throws IOException; void delete(String key) throws IOException; /** Get a file that contains this key. @return A file that contains the content of this file, or null if such a file is not available (for example, the datum is transferred from the network and is not available on a file system. */ File getFile(String key) throws IOException; String getProperty(String p); void setProperty(String name, String data) throws IOException; class DefaultPropertiesImpl { private Properties properties; private Storer store; public DefaultPropertiesImpl(Storer storer) throws IOException { this.store = storer; properties = new Properties(System.getProperties()); try { InputStream is = store.retrieve("properties"); if(is!=null) properties.load(is); } catch(Throwable t) { System.err.println("Warning: couldn't get properties in storer"); } } public String getProperty(String s) { return properties.getProperty(s); } public void setProperty(String name, String data) throws IOException { properties.setProperty(name, data); OutputStream os = store.store("properties"); if (os == null) throw new IOException(); properties.store(os, null); } } }