1 2 24 25 26 27 28 29 package com.lutris.classloader; 30 31 import java.io.File ; 34 import java.io.FileInputStream ; 35 import java.io.FileNotFoundException ; 36 import java.io.IOException ; 37 import java.io.InputStream ; 38 39 import com.lutris.logging.LogChannel; 40 import com.lutris.util.FatalExceptionError; 41 42 53 public class LocalDirResource extends Resource { 54 55 57 58 private File file = null; 59 60 62 75 protected LocalDirResource(String name, 76 ClassPathEntry location, 77 LogChannel loadLogChannel) 79 throws FileNotFoundException { 81 super(name, location, loadLogChannel); 83 String locName = location.getName(); 85 if (locName == null) { 86 throw new FileNotFoundException ("The name for location, " 87 + location + ", is null"); 88 } 89 file = new File (locName, name); 90 if (!file.exists() || !file.canRead()) { 91 File tmpFile = file; 92 file = null; 93 throw new FileNotFoundException ("File, " + 94 tmpFile.getAbsolutePath() + 95 ", does not exist or does not " + 96 "have read permission"); 97 } 98 99 String path = null; 100 String parentPath = null; 101 102 try { 103 parentPath = new File (locName).getCanonicalPath(); 104 } catch (IOException e) { 105 file = null; 106 throw new FileNotFoundException ("Classpath Directory " + locName + 107 " cannot be resolved: " + 108 e.toString()); 109 } 110 111 try { 112 path = file.getCanonicalPath(); 113 } catch (IOException e) { 114 File tmpFile = file; 115 file = null; 116 throw new FileNotFoundException ("File " + 117 tmpFile.getAbsolutePath() + 118 " cannot be resolved: " + 119 e.toString()); 120 } 121 122 if (path.startsWith(parentPath) == false) { 123 File tmpFile = file; 124 file = null; 125 throw new FileNotFoundException ("File, " + tmpFile + 126 " does not live under " + locName); 127 } 128 129 size = file.length(); 130 lastModifiedTime = file.lastModified(); 131 } 132 133 135 142 public InputStream getInputStream() throws IOException { 143 try { 144 return new FileInputStream (file); 145 } catch (FileNotFoundException e) { 146 throw new FatalExceptionError(e); 147 } 148 } 149 150 157 public long getCurrentLastModifiedTime() throws FileNotFoundException { 158 return file.lastModified(); 159 } 160 161 164 public File getFile() { 165 return file; 166 } 167 } 168 | Popular Tags |