Coverage Report - org.webslinger.commons.vfs.tests.AbstractFileObjectRoot
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFileObjectRoot
0%
0/13
N/A
0
AbstractFileObjectRoot$AbstractFileObjectRootListener
0%
0/11
N/A
0
 
 1  
 package org.webslinger.commons.vfs.tests;
 2  
 
 3  
 import java.io.InputStream;
 4  
 import java.io.OutputStream;
 5  
 
 6  
 import org.apache.commons.vfs.FileChangeEvent;
 7  
 import org.apache.commons.vfs.FileListener;
 8  
 import org.apache.commons.vfs.FileObject;
 9  
 import org.apache.commons.vfs.NameScope;
 10  
 
 11  
 import org.webslinger.io.Monitor;
 12  
 import org.webslinger.io.tests.Root;
 13  
 
 14  0
 public abstract class AbstractFileObjectRoot<R extends AbstractFileObjectRoot<R, F>, F extends FileObject> implements Root<R> {
 15  
     protected final F file;
 16  
 
 17  0
     protected AbstractFileObjectRoot(F file) {
 18  0
         this.file = file;
 19  0
     }
 20  
 
 21  
     public R create(String name) throws Exception {
 22  0
         return create((F) file.resolveFile(name, NameScope.CHILD));
 23  
     }
 24  
 
 25  
     protected abstract R create(F file) throws Exception;
 26  
 
 27  
     public void delete() throws Exception {
 28  0
         file.delete();
 29  0
     }
 30  
 
 31  
     public InputStream openIn() throws Exception {
 32  0
         return file.getContent().getInputStream();
 33  
     }
 34  
 
 35  
     public OutputStream openOut() throws Exception {
 36  0
         return file.getContent().getOutputStream();
 37  
     }
 38  
 
 39  
     public void touch(long time) throws Exception {
 40  0
         file.getContent().setLastModifiedTime(time);
 41  0
     }
 42  
 
 43  
     public void refresh() throws Exception {
 44  0
         file.refresh();
 45  0
     }
 46  
 
 47  0
     protected abstract class AbstractFileObjectRootListener extends Listener implements FileListener {
 48  
         public void start() throws Exception {
 49  0
             file.getFileSystem().addListener(file, this);
 50  0
         }
 51  
 
 52  
         public void stop() throws Exception {
 53  0
             file.getFileSystem().removeListener(file, this);
 54  0
         }
 55  
 
 56  
         public void fileCreated(FileChangeEvent event) throws Exception {
 57  0
             addEvent(Monitor.Listener.Event.CREATE);
 58  0
         }
 59  
 
 60  
         public void fileDeleted(FileChangeEvent event) throws Exception {
 61  0
             addEvent(Monitor.Listener.Event.CHANGE);
 62  0
         }
 63  
 
 64  
         public void fileChanged(FileChangeEvent event) throws Exception {
 65  0
             addEvent(Monitor.Listener.Event.DELETE);
 66  0
         }
 67  
     }
 68  
 }