0
|
1 package cachingfilter;
|
|
2
|
|
3 import java.io.File;
|
|
4 import java.io.IOException;
|
|
5
|
|
6 import java.io.File;
|
|
7 import java.io.IOException;
|
|
8 import org.slf4j.Logger;
|
|
9 import org.slf4j.LoggerFactory;
|
|
10
|
|
11
|
|
12 final class CachedFile implements CachedPage {
|
|
13 private static final Logger logger = LoggerFactory.getLogger(CachedFile.class);
|
|
14 private final File file;
|
|
15
|
|
16 CachedFile( File parent, String child ) {
|
|
17 this.file = new File(parent,child);
|
|
18 }
|
|
19
|
|
20 public String name() {
|
|
21 return file.getName();
|
|
22 }
|
|
23
|
|
24 public boolean exists() {
|
|
25 return file.exists();
|
|
26 }
|
|
27
|
|
28 public File lastFile() {
|
|
29 return file;
|
|
30 }
|
|
31
|
|
32 public File newFile() throws IOException {
|
|
33 delete();
|
|
34 if( !file.createNewFile() )
|
|
35 throw new RuntimeException("couldn't create "+file);
|
|
36 return file;
|
|
37 }
|
|
38
|
|
39 public void deleteNewFile() {
|
|
40 if( !delete() )
|
|
41 throw new RuntimeException("couldn't delete "+file);
|
|
42 }
|
|
43
|
|
44 public boolean delete() {
|
|
45 return file.delete();
|
|
46 }
|
|
47
|
|
48 public String toString() {
|
|
49 return file.toString();
|
|
50 }
|
|
51
|
|
52 }
|