Last change
on this file since 114 was
86,
checked in by sherbold, 9 years ago
|
- switched workspace encoding to UTF-8 and fixed broken characters
|
-
Property svn:mime-type set to
text/plain
|
File size:
1.5 KB
|
Line | |
---|
1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.cpdp.decentApp; |
---|
16 | |
---|
17 | import java.util.*; |
---|
18 | import java.io.*; |
---|
19 | |
---|
20 | /** |
---|
21 | * Helper class for watching if a file was changed |
---|
22 | * |
---|
23 | * @author Philip Makedonski |
---|
24 | * |
---|
25 | */ |
---|
26 | public abstract class FileWatcher extends TimerTask { |
---|
27 | // Last timestamp |
---|
28 | private long timeStamp; |
---|
29 | |
---|
30 | // File to watch |
---|
31 | private File file; |
---|
32 | |
---|
33 | /** |
---|
34 | * Constructor |
---|
35 | * |
---|
36 | * @param file |
---|
37 | */ |
---|
38 | public FileWatcher(File file) { |
---|
39 | this.file = file; |
---|
40 | this.timeStamp = file.lastModified(); |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Watches a file and executes the onChange Method if a file is changed |
---|
45 | */ |
---|
46 | public final void run() { |
---|
47 | long timeStamp = file.lastModified(); |
---|
48 | |
---|
49 | if (this.timeStamp != timeStamp) { |
---|
50 | this.timeStamp = timeStamp; |
---|
51 | onChange(file); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | protected abstract void onChange(File file); |
---|
56 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.