001    package railo.runtime.cache.legacy;
002    
003    import java.io.ByteArrayInputStream;
004    import java.io.IOException;
005    
006    import railo.commons.io.IOUtil;
007    import railo.commons.io.res.Resource;
008    import railo.runtime.type.dt.TimeSpan;
009    
010    public class FileCacheEntry implements CacheEntry {
011    
012            private static final String ENC = "utf-8";
013            private Resource res,directory;
014            private String name,raw;
015            
016            
017            
018            private boolean isOK(TimeSpan timeSpan) {
019                    return res.exists() && (res.lastModified()+timeSpan.getMillis()>=System.currentTimeMillis());
020            }
021            public String readEntry(TimeSpan timeSpan,String defaultValue) throws IOException {
022                    if(isOK(timeSpan))
023                            return IOUtil.toString(res,ENC);
024                    return defaultValue;
025            }
026    
027            public void writeEntry(String entry,boolean append) throws IOException {
028                    IOUtil.copy(new ByteArrayInputStream(entry.getBytes(ENC)), res.getOutputStream(append),true,true);
029            }
030    
031    }