📄 etagmanager.java
字号:
// ETagManager.java// $Id: ETagManager.java,v 1.8 2001/02/12 17:33:03 ylafon Exp $// (c) COPYRIGHT MIT, INRIA and Keio, 1999.// Please first read the full copyright statement in file COPYRIGHT.htmlpackage org.w3c.jwput;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.util.Hashtable;import java.util.Properties;import org.w3c.util.XMLProperties;/** * Very simple ETagsDatabase, based on XML properties */public class ETagManager implements ETagsDatabase, JWOptions { protected static XMLProperties etags = null; protected static File etagsfile = null; protected synchronized Properties loadETags(File file) { if (etags == null) { etags = new XMLProperties(); try { etags.load(getEtagFile(file)); } catch (Exception ex) { etags = new XMLProperties(); } } return etags; } protected synchronized void saveETags(File file, Properties props) { File etagsfile = getEtagFile(file); OutputStream out = null; try { out = new BufferedOutputStream( new FileOutputStream(getEtagFile(file))); props.store(out, "ETags"); } catch (Exception ex) { } finally { try { out.close(); } catch (Exception ex2) {} } } /** * Get the ETag relative to the given file which was puted at the given * url. * @param file the local file * @param url its url * @return a String instance */ public synchronized String getETag(File file, String url) { Properties props = loadETags(file); if (props != null) { try { return props.getProperty(file.getCanonicalPath()+"@"+url); } catch (IOException ex) { return null; } } return null; } /** * Remove the ETag from the database * @param file the local file * @param url its url */ public synchronized void removeETag(File file, String url) { Properties props = loadETags(file); if (props != null) { props.remove(url); saveETags(file, props); } } /** * Save the ETag into the database * @param file the local file * @param url its url * @param etag the ETag */ public synchronized void saveETag(File file, String url, String etag) { Properties props = loadETags(file); if (props != null) { try { props.put(file.getCanonicalPath()+"@"+url, etag); saveETags(file, props); } catch (IOException ex) { ex.printStackTrace(); } } } static File getEtagFile(File file) { if (etagsfile == null) { etagsfile = new File(JW.getPathConfig(), "etags"); } return etagsfile; //return new File(file.getParent(), file.getName()+".etag"); } public ETagManager() { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -