From: <bra...@us...> - 2007-07-25 00:20:51
|
Revision: 1858 http://archive-access.svn.sourceforge.net/archive-access/?rev=1858&view=rev Author: bradtofel Date: 2007-07-24 17:20:53 -0700 (Tue, 24 Jul 2007) Log Message: ----------- REFACTOR: moved directory ensure code to a util class REFACTOR: removed all references to PropertyConfigurable interface Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/ARCCacheDirectory.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/DirMaker.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/ARCCacheDirectory.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/ARCCacheDirectory.java 2007-07-25 00:19:26 UTC (rev 1857) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/liveweb/ARCCacheDirectory.java 2007-07-25 00:20:53 UTC (rev 1858) @@ -28,7 +28,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.Properties; import java.util.logging.Logger; import org.archive.io.ArchiveRecord; @@ -39,10 +38,8 @@ import org.archive.io.arc.ARCRecord; import org.archive.io.arc.ARCWriter; import org.archive.io.arc.ARCWriterPool; -import org.archive.wayback.PropertyConfigurable; -import org.archive.wayback.core.PropertyConfiguration; import org.archive.wayback.core.Resource; -import org.archive.wayback.exception.ConfigurationException; +import org.archive.wayback.util.DirMaker; /** * Class which manages a growing set of ARC files, managed by an ARCWriterPool. @@ -55,7 +52,7 @@ * @author brad * @version $Date$, $Revision$ */ -public class ARCCacheDirectory implements PropertyConfigurable { +public class ARCCacheDirectory { private static final Logger LOGGER = Logger.getLogger( ARCCacheDirectory.class.getName()); @@ -74,12 +71,16 @@ */ public static final String LIVE_WEB_ARC_PREFIX = "liveweb.arc.prefix"; private ARCWriterPool pool = null; + private String arcPath = null; + private String arcPrefix = "wayback-live"; private File arcDir = null; - public void init(Properties p) throws ConfigurationException { - PropertyConfiguration pc = new PropertyConfiguration(p); - arcDir = pc.getDir(LIVE_WEB_ARC_DIR,true); - String arcPrefix = pc.getString(LIVE_WEB_ARC_PREFIX); + /** + * @throws IOException + */ + public void init() throws IOException { + // TODO: check that all props have been set + arcDir = DirMaker.ensureDir(arcPath,"arcPath"); File[] files = { arcDir }; WriterPoolSettings settings = getSettings(true, arcPrefix, files); pool = new ARCWriterPool(settings, MAX_POOL_WRITERS, MAX_POOL_WAIT); @@ -166,6 +167,7 @@ return isCompressed; } + @SuppressWarnings("unchecked") public List getMetadata() { return null; } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/DirMaker.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/DirMaker.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/util/DirMaker.java 2007-07-25 00:20:53 UTC (rev 1858) @@ -0,0 +1,62 @@ +/* DirMaker + * + * $Id$ + * + * Created on 7:02:37 PM Jul 19, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-core. + * + * wayback-core is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback-core 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 Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback-core; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.util; + +import java.io.File; +import java.io.IOException; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class DirMaker { + /** + * Ensure that the path pointed to by 'path' is a directory, if possible + * @param path + * @param name + * @return File that is a created directory + * @throws IOException + */ + public static File ensureDir(String path, String name) throws IOException { + if((path == null) || (path.length() == 0)) { + throw new IOException("No configuration for (" + name + ")"); + } + File dir = new File(path); + if(dir.exists()) { + if(!dir.isDirectory()) { + throw new IOException("Dir(" + name + ") at (" + path + + ") exists but is not a directory!"); + } + } else { + if(!dir.mkdirs()) { + throw new IOException("Unable to create dir(" + name +") at (" + + path + ")"); + } + } + return dir; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |