1 package net.krecan.m2_proxy.repository; 2 3 import java.io.BufferedInputStream; 4 import java.io.File; 5 import java.io.FileInputStream; 6 import java.io.IOException; 7 import java.io.InputStream; 8 9 import net.krecan.m2_proxy.Repository; 10 import net.krecan.m2_proxy.Resource; 11 import net.krecan.m2_proxy.resource.DefaultResource; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 17 18 /*** 19 * File system repository 20 * @author Lukas Krecan 21 * 22 */ 23 public class FileRepository implements Repository { 24 25 26 27 private static final Log LOG = LogFactory.getLog(FileRepository.class); 28 private File baseDir; 29 30 protected File getResourceFile(String resourcePath) { 31 File file = new File(getBaseDir(), resourcePath); 32 return file; 33 } 34 35 public Resource loadResource(String resourcePath) throws IOException { 36 File resource = getResourceFile(resourcePath); 37 if (!resource.canRead()) 38 { 39 LOG.debug("Can not read \""+resource+"\""); 40 return null; 41 } 42 else 43 { 44 InputStream in = new BufferedInputStream(new FileInputStream(resource)); 45 LOG.debug("Reading "+resource); 46 return new DefaultResource(resource.getAbsolutePath(), resource.lastModified(), resource.length(), in); 47 } 48 } 49 public File getBaseDir() { 50 return baseDir; 51 } 52 public void setBaseDir(File baseDir) { 53 this.baseDir = baseDir; 54 } 55 56 }