Back to the RMI Plug-in for Eclipse

demo.rmi.filesystem.server
Class RemoteFileImpl

java.lang.Object
  extended by java.io.File
      extended by demo.rmi.filesystem.server.RemoteFileImpl
All Implemented Interfaces:
IRemoteFile, Serializable, Comparable<File>, Remote

public class RemoteFileImpl
extends File
implements IRemoteFile

This class implements the IRemoteFile interface for the local file system. The implementation extends the standard File class. Some methods already appear in the File class with the same signature as required by the interface and therefore you don't see their implementation here. As you can see this class does not extend UnicastRemoteObject, which means we have to manually export the remote implementations using the UnicastRemoteObject.exportObject(java.rmi.Remote) method. This implementation tries to be as efficient as it can be, but you should remember that the whole design is not very efficient itself. The interesting methods in terms of two-way communications are the methods that filter the file system. See their docs and the docs in the interface for more information.

Author:
Genady Beryozkin, rmi-info@genady.net
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
RemoteFileImpl(RemoteFileImpl parent, String child)
          Create a new remote file object that is a child of this directory.
RemoteFileImpl(String pathname)
          Create a new remote file object with a given path.
 
Method Summary
 String getCanonicalPath()
           
 IRemoteFile getChild(String name)
          Return a file that is a child of the current directory.
 IRemoteInputStream getInputStream()
          Return a remote input stream that can be used to read from the file.
 RemoteFileImpl getRemoteAbsoluteFile()
           
 RemoteFileImpl getRemoteParentFile()
           
 IRemoteFile[] listByFilter(IRemoteFilenameFilter filter)
          This method uses a remote filename filter which will result in callbacks to the client (the user of this interface) for every filename (if the implementing object is exported).
 IRemoteFile[] listByRegex(String regex, boolean dirsOnly)
          Return the files in this directory that their names (only the last segment) match the regular expression supplied as the regex argument.
 IRemoteFile[] listRemoteDirectories()
          This method returns the subdirectories of the current directory.
 IRemoteFile[] listRemoteFiles()
          Return the files in this directory as IRemoteFiles.
 
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface demo.rmi.filesystem.common.IRemoteFile
canRead, canWrite, exists, getAbsolutePath, getName, getParent, getPath, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

RemoteFileImpl

public RemoteFileImpl(RemoteFileImpl parent,
                      String child)
               throws RemoteException
Create a new remote file object that is a child of this directory.

Throws:
RemoteException

RemoteFileImpl

RemoteFileImpl(String pathname)
         throws RemoteException
Create a new remote file object with a given path. Used only by RemoteFileSystemImpl.getRoots().

Throws:
RemoteException
Method Detail

getCanonicalPath

public String getCanonicalPath()
                        throws RemoteException
Specified by:
getCanonicalPath in interface IRemoteFile
Overrides:
getCanonicalPath in class File
Throws:
RemoteException

getChild

public IRemoteFile getChild(String name)
                     throws RemoteException
Description copied from interface: IRemoteFile
Return a file that is a child of the current directory. Replaces the constructor (see File.File(File, String)), since interfaces can't declare constructors.

Specified by:
getChild in interface IRemoteFile
Parameters:
name - the child's name.
Throws:
RemoteException

getInputStream

public IRemoteInputStream getInputStream()
                                  throws RemoteException
Description copied from interface: IRemoteFile
Return a remote input stream that can be used to read from the file. The client code contains a class that can wrap IRemoteInputStream with a conventional InputStream.

Specified by:
getInputStream in interface IRemoteFile
Throws:
RemoteException
See Also:
IRemoteInputStream

getRemoteAbsoluteFile

public RemoteFileImpl getRemoteAbsoluteFile()
                                     throws RemoteException
Specified by:
getRemoteAbsoluteFile in interface IRemoteFile
Throws:
RemoteException

getRemoteParentFile

public RemoteFileImpl getRemoteParentFile()
                                   throws RemoteException
Specified by:
getRemoteParentFile in interface IRemoteFile
Throws:
RemoteException

listByFilter

public IRemoteFile[] listByFilter(IRemoteFilenameFilter filter)
                           throws RemoteException
Description copied from interface: IRemoteFile
This method uses a remote filename filter which will result in callbacks to the client (the user of this interface) for every filename (if the implementing object is exported). If the filter is exported this method is won't be very efficient. In such case it would probably be more efficient to get the whole file list and filter it locally. If the filter is not exported, it will be serialized and sent to the server. In such case the filter's code is executed locally inside the server VM and the method is more efficient. However, this means that client code is being executed on the server, which may not be acceptable in the real world (security-wise). See the client code for sample use.

Specified by:
listByFilter in interface IRemoteFile
Parameters:
filter - the filename filter.
Returns:
Throws:
RemoteException

listByRegex

public IRemoteFile[] listByRegex(String regex,
                                 boolean dirsOnly)
                          throws RemoteException
Description copied from interface: IRemoteFile
Return the files in this directory that their names (only the last segment) match the regular expression supplied as the regex argument.

Specified by:
listByRegex in interface IRemoteFile
Parameters:
regex - the regular expression filter for the childs filename.
dirsOnly - If true, only subdirectories will be considered.
Throws:
RemoteException
See Also:
String.matches(String);

listRemoteDirectories

public IRemoteFile[] listRemoteDirectories()
                                    throws RemoteException
Description copied from interface: IRemoteFile
This method returns the subdirectories of the current directory. Useful for traversal of the entire directory tree (see also IRemoteFile.listByFilter(IRemoteFilenameFilter).

Specified by:
listRemoteDirectories in interface IRemoteFile
Throws:
RemoteException

listRemoteFiles

public IRemoteFile[] listRemoteFiles()
                              throws RemoteException
Description copied from interface: IRemoteFile
Return the files in this directory as IRemoteFiles.

Specified by:
listRemoteFiles in interface IRemoteFile
Throws:
RemoteException

Back to the RMI Plug-in for Eclipse


© 2002-18 Genady Beryozkin, rmi-info@genady.net. Read our Privacy policy. Hosted on RimuHosting. Visit Javalobby.