|
Last change
on this file since 40 was
32,
checked in by ftrautsch, 11 years ago
|
|
integrating decent into crosspare
|
-
Property svn:mime-type set to
text/plain
|
|
File size:
745 bytes
|
| Line | |
|---|
| 1 | package de.ugoe.cs.cpdp.decentApp; |
|---|
| 2 | |
|---|
| 3 | import java.util.*; |
|---|
| 4 | import java.io.*; |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * Helper class for watching if a file was changed |
|---|
| 8 | * |
|---|
| 9 | * @author Philip Makedonski |
|---|
| 10 | * |
|---|
| 11 | */ |
|---|
| 12 | public abstract class FileWatcher extends TimerTask { |
|---|
| 13 | // Last timestamp |
|---|
| 14 | private long timeStamp; |
|---|
| 15 | |
|---|
| 16 | // File to watch |
|---|
| 17 | private File file; |
|---|
| 18 | |
|---|
| 19 | /** |
|---|
| 20 | * Constructor |
|---|
| 21 | * @param file |
|---|
| 22 | */ |
|---|
| 23 | public FileWatcher(File file) { |
|---|
| 24 | this.file = file; |
|---|
| 25 | this.timeStamp = file.lastModified(); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * Watches a file and executes the onChange Method |
|---|
| 30 | * if a file is changed |
|---|
| 31 | */ |
|---|
| 32 | public final void run() { |
|---|
| 33 | long timeStamp = file.lastModified(); |
|---|
| 34 | |
|---|
| 35 | if (this.timeStamp != timeStamp) { |
|---|
| 36 | this.timeStamp = timeStamp; |
|---|
| 37 | onChange(file); |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | protected abstract void onChange(File file); |
|---|
| 42 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.