KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > util > AltFileResource


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.frontend.util;
17
18 import org.apache.avalon.excalibur.monitor.StreamResource;
19
20 import java.io.*;
21
22 /**
23  * A file resource for excalibur's monitor that also detects
24  * file removals.
25  */

26 public class AltFileResource extends StreamResource {
27     private File file;
28     private long previousLastModified = -1;
29
30     public AltFileResource(File file) throws Exception JavaDoc {
31         super(file.getCanonicalPath());
32         this.file = file;
33         this.previousLastModified = file.lastModified();
34     }
35
36     public long lastModified() {
37         long lastModified = file.lastModified();
38         if (lastModified == 0 && previousLastModified != 0) {
39             previousLastModified = 0;
40             return System.currentTimeMillis();
41         } else {
42             previousLastModified = lastModified;
43             return lastModified;
44         }
45     }
46
47     public InputStream getResourceAsStream() throws IOException {
48         // we don't use this so didn't bother to implement
49
return null;
50     }
51
52     public Reader getResourceAsReader() throws IOException {
53         // we don't use this so didn't bother to implement
54
return null;
55     }
56
57     public OutputStream setResourceAsStream() throws IOException {
58         // we don't use this so didn't bother to implement
59
return null;
60     }
61
62     public Writer setResourceAsWriter() throws IOException {
63         // we don't use this so didn't bother to implement
64
return null;
65     }
66 }
67
Popular Tags