1 package twcsckernel.projectbase.io; 2 3 import java.io.FileNotFoundException; 4 import java.io.IOException; 5 import java.rmi.RemoteException; 6 import java.util.HashSet; 7 import java.util.Set; 8 9 import twcsckernel.projectbase.common.RemoteFileSystem; 10 11 public class RemoteFileSystemImpl implements RemoteFileSystem { 12 13 private Set<LocalFsChangeListener> fsListeners = new HashSet<LocalFsChangeListener>(); 14 15 public final ReaderFactoryImpl readerFactory; 16 public final WriterFactoryImpl writerFactory; 17 public final FileFactoryImpl fileFactory; 18 public final FileSecurityManager defaultSecurityManager; 19 20 21 public RemoteFileSystemImpl(FileSecurityManager manager) { 22 defaultSecurityManager = manager; 23 fileFactory = new FileFactoryImpl(defaultSecurityManager,fsListeners); 24 writerFactory = new WriterFactoryImpl(defaultSecurityManager,fsListeners); 25 readerFactory = new ReaderFactoryImpl(defaultSecurityManager); 26 } 27 28 public RemoteFile newRemoteFile(String filePath) throws RemoteException, 29 SecurityException, IOException { 30 return fileFactory.newRemoteFile(filePath); 31 } 32 33 public RemoteFileOutputStream newFileOutputStream(String filePath) 34 throws RemoteException, FileNotFoundException, SecurityException { 35 return writerFactory.newFileOutputStream(filePath); 36 } 37 38 public RemoteFileInputStream newFileInputStream(String filePath) 39 throws RemoteException, FileNotFoundException, SecurityException { 40 return readerFactory.newFileInputStream(filePath); 41 } 42 43 public boolean addFilesystemChangeListener(LocalFsChangeListener fsChL) { 44 if (fsChL != null) 45 return fsListeners.add(fsChL); 46 else 47 return false; 48 } 49 50 public boolean removeFilesystemChangeListener(LocalFsChangeListener fsChL) { 51 return fsListeners.remove(fsChL); 52 } 53 54 public void releaseAllResources() { 55 readerFactory.releaseAllResources(); 56 writerFactory.releaseAllResources(); 57 fileFactory.releaseAllResources(); 58 } 59 60 }