1 52 53 package freemarker.cache; 54 55 import java.io.File ; 56 import java.io.IOException ; 57 import java.io.InputStream ; 58 import java.net.URL ; 59 import java.net.URLConnection ; 60 61 66 class URLTemplateSource { 67 private final URL url; 68 private URLConnection conn; 69 private InputStream inputStream; 70 71 URLTemplateSource(URL url) throws IOException { 72 this.url = url; 73 this.conn = url.openConnection(); 74 } 75 76 public boolean equals(Object o) { 77 if (o instanceof URLTemplateSource) { 78 return url.equals(((URLTemplateSource) o).url); 79 } else { 80 return false; 81 } 82 } 83 84 public int hashCode() { 85 return url.hashCode(); 86 } 87 88 public String toString() { 89 return url.toString(); 90 } 91 92 long lastModified() { 93 long lastModified = conn.getLastModified(); 94 if (lastModified == -1L && url.getProtocol().equals("file")) { 95 return new File (url.getFile()).lastModified(); 99 } else { 100 return lastModified; 101 } 102 } 103 104 InputStream getInputStream() throws IOException { 105 inputStream = conn.getInputStream(); 106 return inputStream; 107 } 108 109 void close() throws IOException { 110 try { 111 if (inputStream != null) { 112 inputStream.close(); 113 } 114 } finally { 115 inputStream = null; 116 conn = null; 117 } 118 } 119 } 120 | Popular Tags |