-
- /**
- * Load a file, first checking cache
- *
- *
- * @param logTarget - logTarget can be null (won't log)
- * @param dataRoot - data root storage directory
- * @param key - relative File Path
- * @param mediaType - what kind of file is it. If null, will check via file extension
- * @param timeCheck - "-1" will take system default - Otherwise, will compare "now" + timeCheck(Millis) before looking at File mod
- * @return
- * @throws IOException
- */
- public Content load(LogTarget logTarget, String dataRoot, String key, String mediaType, long _timeCheck) throws IOException {
- long timeCheck = _timeCheck;
- if(timeCheck<0) {
- timeCheck=checkInterval; // if time < 0, then use default
- }
- boolean isRoot;
- String fileName;
- if("-".equals(key)) {
- fileName = dataRoot;
- isRoot = true;
- } else {
- fileName=dataRoot + '/' + key;
- isRoot = false;
- }
- Content c = content.get(key);
- long systime = System.currentTimeMillis();
- File f=null;
- if(c!=null) {
- // Don't check every hit... only after certain time value
- if(c.date < systime + timeCheck) {
- f = new File(fileName);
- if(f.lastModified()>c.date) {
- c=null;
- }
- }
- }
- if(c==null) {
- if(logTarget!=null) {
- logTarget.log("File Read: ",key);
- }
-
- if(f==null){
- f = new File(fileName);
- }
- boolean cacheMe;
- if(f.exists()) {
- if(f.isDirectory()) {
- cacheMe = false;
- c = new DirectoryContent(f,isRoot);
- } else {
- if(f.length() > maxItemSize) {
- c = new DirectFileContent(f);
- cacheMe = false;
- } else {
- c = new CachedContent(f);
- cacheMe = checkInterval>0;
- }
-
- if(mediaType==null) { // determine from file Ending
- int idx = key.lastIndexOf('.');
- String subkey = key.substring(++idx);
- if((c.contentType = idx<0?null:typeMap.get(subkey))==null) {
- // if nothing else, just set to default type...
- c.contentType = "application/octet-stream";
- }
- c.attachmentOnly = attachOnly.contains(subkey);
- } else {
- c.contentType=mediaType;
- c.attachmentOnly = false;
- }
-
- c.date = f.lastModified();
-
- if(cacheMe) {
- content.put(key, c);
- }
- }
- } else {
- c=NULL;
- }
- } else {
- if(logTarget!=null)logTarget.log("Cache Read: ",key);
- }
+
+ /**
+ * Load a file, first checking cache
+ *
+ *
+ * @param logTarget - logTarget can be null (won't log)
+ * @param dataRoot - data root storage directory
+ * @param key - relative File Path
+ * @param mediaType - what kind of file is it. If null, will check via file extension
+ * @param timeCheck - "-1" will take system default - Otherwise, will compare "now" + timeCheck(Millis) before looking at File mod
+ * @return
+ * @throws IOException
+ */
+ public Content load(LogTarget logTarget, String dataRoot, String key, String mediaType, long _timeCheck) throws IOException {
+ long timeCheck = _timeCheck;
+ if (timeCheck<0) {
+ timeCheck=checkInterval; // if time < 0, then use default
+ }
+ boolean isRoot;
+ String fileName;
+ if ("-".equals(key)) {
+ fileName = dataRoot;
+ isRoot = true;
+ } else {
+ fileName=dataRoot + '/' + key;
+ isRoot = false;
+ }
+ Content c = content.get(key);
+ long systime = System.currentTimeMillis();
+ File f=null;
+ if (c!=null) {
+ // Don't check every hit... only after certain time value
+ if (c.date < systime + timeCheck) {
+ f = new File(fileName);
+ if (f.lastModified()>c.date) {
+ c=null;
+ }
+ }
+ }
+ if (c==null) {
+ if (logTarget!=null) {
+ logTarget.log("File Read: ",key);
+ }
+
+ if (f==null){
+ f = new File(fileName);
+ }
+ boolean cacheMe;
+ if (f.exists()) {
+ if (f.isDirectory()) {
+ cacheMe = false;
+ c = new DirectoryContent(f,isRoot);
+ } else {
+ if (f.length() > maxItemSize) {
+ c = new DirectFileContent(f);
+ cacheMe = false;
+ } else {
+ c = new CachedContent(f);
+ cacheMe = checkInterval>0;
+ }
+
+ if (mediaType==null) { // determine from file Ending
+ int idx = key.lastIndexOf('.');
+ String subkey = key.substring(++idx);
+ if ((c.contentType = idx<0?null:typeMap.get(subkey))==null) {
+ // if nothing else, just set to default type...
+ c.contentType = "application/octet-stream";
+ }
+ c.attachmentOnly = attachOnly.contains(subkey);
+ } else {
+ c.contentType=mediaType;
+ c.attachmentOnly = false;
+ }
+
+ c.date = f.lastModified();
+
+ if (cacheMe) {
+ content.put(key, c);
+ }
+ }
+ } else {
+ c=NULL;
+ }
+ } else {
+ if (logTarget!=null)logTarget.log("Cache Read: ",key);
+ }