| 1 | |
package org.webslinger.io.tests; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.FileInputStream; |
| 5 | |
import java.io.FileOutputStream; |
| 6 | |
import java.io.InputStream; |
| 7 | |
import java.io.OutputStream; |
| 8 | |
|
| 9 | |
import org.webslinger.io.FileMonitor; |
| 10 | |
import org.webslinger.io.IOUtil; |
| 11 | |
import org.webslinger.io.JNotifyFileMonitor; |
| 12 | |
import org.webslinger.io.Monitor; |
| 13 | |
|
| 14 | 0 | public final class FileRoot implements Root<FileRoot> { |
| 15 | |
protected final File file; |
| 16 | |
|
| 17 | 0 | public FileRoot(File file) { |
| 18 | 0 | this.file = file; |
| 19 | 0 | } |
| 20 | |
|
| 21 | |
public FileRoot create(String name) throws Exception { |
| 22 | 0 | return new FileRoot(new File(file, name)); |
| 23 | |
} |
| 24 | |
|
| 25 | |
public void delete() throws Exception { |
| 26 | 0 | file.delete(); |
| 27 | 0 | } |
| 28 | |
|
| 29 | |
public InputStream openIn() throws Exception { |
| 30 | 0 | return new FileInputStream(file); |
| 31 | |
} |
| 32 | |
|
| 33 | |
public OutputStream openOut() throws Exception { |
| 34 | 0 | return new FileOutputStream(file); |
| 35 | |
} |
| 36 | |
|
| 37 | |
public void touch(long time) throws Exception { |
| 38 | 0 | IOUtil.touch(file, time); |
| 39 | 0 | } |
| 40 | |
|
| 41 | |
public Listener createListener() throws Exception { |
| 42 | 0 | return new FileRootListener(); |
| 43 | |
} |
| 44 | |
|
| 45 | |
public void refresh() throws Exception { |
| 46 | 0 | throw new UnsupportedOperationException(); |
| 47 | |
} |
| 48 | |
|
| 49 | 0 | protected final class FileRootListener extends Listener implements FileMonitor.FileListener { |
| 50 | |
public void start() throws Exception { |
| 51 | 0 | JNotifyFileMonitor.SINGLETON.add(file, this); |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
public void stop() throws Exception { |
| 55 | 0 | JNotifyFileMonitor.SINGLETON.remove(file, this); |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
public void acceptEvent(File item, Monitor.Listener.Event event) { |
| 59 | 0 | events.add(event); |
| 60 | 0 | } |
| 61 | |
} |
| 62 | |
} |