com.mucommander.file.impl.nfs
Class NFSFile

java.lang.Object
  extended by com.mucommander.file.AbstractFile
      extended by com.mucommander.file.impl.nfs.NFSFile
All Implemented Interfaces:
PermissionAccesses, PermissionTypes

public class NFSFile
extends AbstractFile

NFSFile provides access to files located on an NFS/WebNFS server.

The associated FileURL scheme is FileProtocols.NFS. The host part of the URL designates the NFS server. The path separator is '/'.

Here are a few examples of valid NFS URLs: nfs://garfield/stuff/
nfs://192.168.1.1:2049/stuff/somefile

Access to NFS files is provided by the Yanfs library (formerly WebNFS) distributed under the BSD license. The getUnderlyingFileObject() method allows to retrieve a com.sun.xfile.XFile instance corresponding to this NFSFile.

Author:
Maxence Bernard

Nested Class Summary
static class NFSFile.NFSRandomAccessInputStream
          NFSRandomAccessInputStream extends RandomAccessInputStream to provide random read access to an NFSFile.
static class NFSFile.NFSRandomAccessOutputStream
          NFSRandomAccessOutputStream extends RandomAccessOutputStream to provide random write access to an NFSFile.
 
Field Summary
static java.lang.String DEFAULT_NFS_PROTOCOL
          Default transport protocol
static java.lang.String DEFAULT_NFS_VERSION
          Default NFS version
static java.lang.String NFS_PROTOCOL_AUTO
          'Auto' transport protocol: TCP is tried first and if the connection cannot be established, falls back to UDP
static java.lang.String NFS_PROTOCOL_PROPERTY_NAME
          Name of the NFS transport protocol property
static java.lang.String NFS_PROTOCOL_TCP
          TCP transport protocol
static java.lang.String NFS_PROTOCOL_UDP
          UDP transport protocol
static java.lang.String NFS_VERSION_2
          NFS version 2
static java.lang.String NFS_VERSION_3
          NFS version 3
static java.lang.String NFS_VERSION_PROPERTY_NAME
          Name of the NFS version property
static java.lang.String SEPARATOR
           
 
Fields inherited from class com.mucommander.file.AbstractFile
DEFAULT_SEPARATOR, fileURL, IO_BUFFER_SIZE, MUST_HINT, MUST_NOT_HINT, SHOULD_HINT, SHOULD_NOT_HINT, windowsDriveRootPattern
 
Fields inherited from interface com.mucommander.file.PermissionTypes
EXECUTE_PERMISSION, READ_PERMISSION, WRITE_PERMISSION
 
Fields inherited from interface com.mucommander.file.PermissionAccesses
GROUP_ACCESS, OTHER_ACCESS, USER_ACCESS
 
Constructor Summary
NFSFile(FileURL fileURL)
          Creates a new instance of NFSFile.
 
Method Summary
 boolean canChangeDate()
          Always returns false (date cannot be changed).
 boolean canGetGroup()
          Always returns false, this information is not available unfortunately.
 boolean canGetOwner()
          Always returns false, this information is not available unfortunately.
 boolean canRunProcess()
          Always returns false.
 boolean changeDate(long lastModified)
          Always returns false (date cannot be changed).
 boolean changePermission(int access, int permission, boolean enabled)
          Changes the specified permission bit.
 void delete()
          Deletes this file and this file only (does not recurse on folders).
 boolean exists()
          Returns true if this file exists.
 PermissionBits getChangeablePermissions()
          Returns a bit mask describing the permission bits that can be changed on this file when calling AbstractFile.changePermission(int, int, boolean) and AbstractFile.changePermissions(int).
 long getDate()
          Returns this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).
 long getFreeSpace()
          Always returns -1 (not available)
 java.lang.String getGroup()
          Always returns null, this information is not available unfortunately.
 java.io.InputStream getInputStream()
          Returns an InputStream to read the contents of this file.
 java.io.OutputStream getOutputStream(boolean append)
          Returns an OuputStream to write the contents of this file, appending or overwriting the existing contents.
 java.lang.String getOwner()
          Always returns null, this information is not available unfortunately.
 AbstractFile getParent()
          Returns this file's parent, null if it doesn't have one.
 FilePermissions getPermissions()
          Returns this file's permissions, as a FilePermissions object.
 RandomAccessInputStream getRandomAccessInputStream()
          Returns a RandomAccessInputStream to read the contents of this file with random access.
 RandomAccessOutputStream getRandomAccessOutputStream()
          Warning: the returned NFSFile.NFSRandomAccessOutputStream instance is not fully functional, its NFSFile.NFSRandomAccessOutputStream.setLength(long) method has a limitation.
 long getSize()
          Returns this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined.
 long getTotalSpace()
          Always returns -1 (not available)
 java.lang.Object getUnderlyingFileObject()
          Returns a com.sun.xfile.XFile instance corresponding to this file.
 boolean hasRandomAccessInputStream()
          Returns true: getRandomAccessInputStream() is implemented.
 boolean hasRandomAccessOutputStream()
          Returns false: getRandomAccessOutputStream() is implemented but the returned RandomAccessOutputStream is not fully functional.
 boolean isDirectory()
          Returns true if this file is a directory, false in any of the following cases: this file does not exist this file is a regular file this file is browsable (as reported by AbstractFile.isBrowsable() but not a directory
 boolean isSymlink()
          Always returns false (symlinks are not detected).
 AbstractFile[] ls()
          Returns the children files that this file contains.
 AbstractFile[] ls(FilenameFilter filenameFilter)
          Returns the children files that this file contains, filtering out files that do not match the specified FilenameFilter.
 void mkdir()
          Creates this file as a directory.
 boolean moveTo(AbstractFile destFile)
          Overrides AbstractFile.moveTo(AbstractFile) to move/rename the file directly if the destination file is also an NFSFile.
 AbstractProcess runProcess(java.lang.String[] tokens)
          Always throws an IOException.
 void setParent(AbstractFile parent)
          Sets this file's parent.
 
Methods inherited from class com.mucommander.file.AbstractFile
addTrailingSeparator, calculateChecksum, calculateChecksum, calculateChecksum, changePermissions, changePermissions, checkCopyPrerequisites, copyRecursively, copyStream, copyTo, deleteRecursively, deleteRecursively, equals, getAbsolutePath, getAbsolutePath, getAncestor, getAncestor, getCanonicalFile, getCanonicalPath, getCanonicalPath, getChild, getChildSilently, getCopyToHint, getDirectChild, getExtension, getExtension, getIcon, getIcon, getInputStream, getJavaNetURL, getMoveToHint, getName, getNameWithoutExtension, getParentArchive, getParentSilently, getPermissionsString, getRoot, getSeparator, getTopAncestor, getURL, hasAncestor, hasAncestor, hashCode, importPermissions, importPermissions, isBrowsable, isHidden, isParentOf, isRoot, ls, mkdir, mkdirs, mkfile, mkfile, removeTrailingSeparator, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
See Also:
Constant Field Values

NFS_VERSION_PROPERTY_NAME

public static final java.lang.String NFS_VERSION_PROPERTY_NAME
Name of the NFS version property

See Also:
Constant Field Values

NFS_VERSION_2

public static final java.lang.String NFS_VERSION_2
NFS version 2

See Also:
Constant Field Values

NFS_VERSION_3

public static final java.lang.String NFS_VERSION_3
NFS version 3

See Also:
Constant Field Values

DEFAULT_NFS_VERSION

public static final java.lang.String DEFAULT_NFS_VERSION
Default NFS version

See Also:
Constant Field Values

NFS_PROTOCOL_PROPERTY_NAME

public static final java.lang.String NFS_PROTOCOL_PROPERTY_NAME
Name of the NFS transport protocol property

See Also:
Constant Field Values

NFS_PROTOCOL_AUTO

public static final java.lang.String NFS_PROTOCOL_AUTO
'Auto' transport protocol: TCP is tried first and if the connection cannot be established, falls back to UDP

See Also:
Constant Field Values

NFS_PROTOCOL_TCP

public static final java.lang.String NFS_PROTOCOL_TCP
TCP transport protocol

See Also:
Constant Field Values

NFS_PROTOCOL_UDP

public static final java.lang.String NFS_PROTOCOL_UDP
UDP transport protocol

See Also:
Constant Field Values

DEFAULT_NFS_PROTOCOL

public static final java.lang.String DEFAULT_NFS_PROTOCOL
Default transport protocol

See Also:
Constant Field Values
Constructor Detail

NFSFile

public NFSFile(FileURL fileURL)
Creates a new instance of NFSFile.

Method Detail

getDate

public long getDate()
Description copied from class: AbstractFile
Returns this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).

Specified by:
getDate in class AbstractFile
Returns:
this file's last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)

canChangeDate

public boolean canChangeDate()
Always returns false (date cannot be changed).

Specified by:
canChangeDate in class AbstractFile
Returns:
true if this file's date can be changed using AbstractFile.changeDate(long)

changeDate

public boolean changeDate(long lastModified)
Always returns false (date cannot be changed).

Specified by:
changeDate in class AbstractFile
Parameters:
lastModified - last modified date, in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)
Returns:
true if date was changed successfully.

getSize

public long getSize()
Description copied from class: AbstractFile
Returns this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined.

Specified by:
getSize in class AbstractFile
Returns:
this file's size in bytes, 0 if this file doesn't exist, -1 if the size is undetermined

getParent

public AbstractFile getParent()
Description copied from class: AbstractFile
Returns this file's parent, null if it doesn't have one.

Specified by:
getParent in class AbstractFile
Returns:
this file's parent, null if it doesn't have one

setParent

public void setParent(AbstractFile parent)
Description copied from class: AbstractFile
Sets this file's parent. null can be specified if this file doesn't have a parent.

Specified by:
setParent in class AbstractFile
Parameters:
parent - the new parent of this file

exists

public boolean exists()
Description copied from class: AbstractFile
Returns true if this file exists.

Specified by:
exists in class AbstractFile
Returns:
true if this file exists

getPermissions

public FilePermissions getPermissions()
Description copied from class: AbstractFile
Returns this file's permissions, as a FilePermissions object. Note that this file may only support certain permission bits, use the permission mask to find out which bits are supported.

This method may return permissions for which none of the bits are supported, but may never return null.

Specified by:
getPermissions in class AbstractFile
Returns:
this file's permissions, as a FilePermissions object

getChangeablePermissions

public PermissionBits getChangeablePermissions()
Description copied from class: AbstractFile
Returns a bit mask describing the permission bits that can be changed on this file when calling AbstractFile.changePermission(int, int, boolean) and AbstractFile.changePermissions(int).

Specified by:
getChangeablePermissions in class AbstractFile
Returns:
a bit mask describing the permission bits that can be changed on this file

changePermission

public boolean changePermission(int access,
                                int permission,
                                boolean enabled)
Description copied from class: AbstractFile
Changes the specified permission bit. If the specified permission bit can't be changed (see AbstractFile.getChangeablePermissions()), this method has no effect and false is returned.

Specified by:
changePermission in class AbstractFile
Parameters:
access - see PermissionTypes for allowed values
permission - see PermissionAccesses for allowed values
enabled - true to enable the flag, false to disable it
Returns:
true if the permission flag was successfully set for the access type
See Also:
AbstractFile.getChangeablePermissions()

getOwner

public java.lang.String getOwner()
Always returns null, this information is not available unfortunately.

Specified by:
getOwner in class AbstractFile
Returns:
information about the owner of this file

canGetOwner

public boolean canGetOwner()
Always returns false, this information is not available unfortunately.

Specified by:
canGetOwner in class AbstractFile
Returns:
true if this file implementation is able to return information about file owners

getGroup

public java.lang.String getGroup()
Always returns null, this information is not available unfortunately.

Specified by:
getGroup in class AbstractFile
Returns:
information about the owner of this file

canGetGroup

public boolean canGetGroup()
Always returns false, this information is not available unfortunately.

Specified by:
canGetGroup in class AbstractFile
Returns:
true if this file implementation is able to return information about file groups

isDirectory

public boolean isDirectory()
Description copied from class: AbstractFile
Returns true if this file is a directory, false in any of the following cases:

Specified by:
isDirectory in class AbstractFile
Returns:
true if this file is a directory, false in any of the cases listed above

isSymlink

public boolean isSymlink()
Always returns false (symlinks are not detected).

Specified by:
isSymlink in class AbstractFile
Returns:
true if this file is a symbolic link

ls

public AbstractFile[] ls()
                  throws java.io.IOException
Description copied from class: AbstractFile
Returns the children files that this file contains. For this operation to be successful, this file must be 'browsable', i.e. AbstractFile.isBrowsable() must return true. This method may return a zero-length array if it has no children but may never return null.

Specified by:
ls in class AbstractFile
Returns:
the children files that this file contains
Throws:
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.

mkdir

public void mkdir()
           throws java.io.IOException
Description copied from class: AbstractFile
Creates this file as a directory. This method will fail (throw an IOException) if this file already exists.

Specified by:
mkdir in class AbstractFile
Throws:
java.io.IOException - if the directory could not be created, either because this file already exists or for any other reason.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from class: AbstractFile
Returns an InputStream to read the contents of this file. Throws an IOException in any of the following cases: This method may never return null.

Specified by:
getInputStream in class AbstractFile
Returns:
an InputStream to read the contents of this file
Throws:
java.io.IOException - in any of the cases listed above

getOutputStream

public java.io.OutputStream getOutputStream(boolean append)
                                     throws java.io.IOException
Description copied from class: AbstractFile
Returns an OuputStream to write the contents of this file, appending or overwriting the existing contents. This file will be created as a zero-byte file if it does not yet exist. Throws an IOException in any of the following cases: This method may never return null.

Specified by:
getOutputStream in class AbstractFile
Parameters:
append - if true, data written to the OutputStream will be appended to the end of this file. If false, any existing data this file contains will be discarded and overwritten.
Returns:
an OuputStream to write the contents of this file
Throws:
java.io.IOException - in any of the cases listed above

hasRandomAccessInputStream

public boolean hasRandomAccessInputStream()
Returns true: getRandomAccessInputStream() is implemented.

Specified by:
hasRandomAccessInputStream in class AbstractFile
Returns:
true

getRandomAccessInputStream

public RandomAccessInputStream getRandomAccessInputStream()
                                                   throws java.io.IOException
Description copied from class: AbstractFile
Returns a RandomAccessInputStream to read the contents of this file with random access. Throws an IOException in any of the following cases: This method may never return null.

Specified by:
getRandomAccessInputStream in class AbstractFile
Returns:
a RandomAccessInputStream to read the contents of this file with random access
Throws:
java.io.IOException - in any of the cases listed above

hasRandomAccessOutputStream

public boolean hasRandomAccessOutputStream()
Returns false: getRandomAccessOutputStream() is implemented but the returned RandomAccessOutputStream is not fully functional.

Specified by:
hasRandomAccessOutputStream in class AbstractFile
Returns:
false

getRandomAccessOutputStream

public RandomAccessOutputStream getRandomAccessOutputStream()
                                                     throws java.io.IOException
Warning: the returned NFSFile.NFSRandomAccessOutputStream instance is not fully functional, its NFSFile.NFSRandomAccessOutputStream.setLength(long) method has a limitation.

Specified by:
getRandomAccessOutputStream in class AbstractFile
Returns:
a RandomAccessOutputStream that is not fully functional
Throws:
java.io.IOException - if the file could not be opened for random write access

delete

public void delete()
            throws java.io.IOException
Description copied from class: AbstractFile
Deletes this file and this file only (does not recurse on folders). Throws an IOException in any of the following cases:

Specified by:
delete in class AbstractFile
Throws:
java.io.IOException - if this file does not exist or could not be deleted

getFreeSpace

public long getFreeSpace()
Always returns -1 (not available)

Specified by:
getFreeSpace in class AbstractFile
Returns:
the free space (in bytes) on the disk/volume where this file is, -1 if this information is not available.

getTotalSpace

public long getTotalSpace()
Always returns -1 (not available)

Specified by:
getTotalSpace in class AbstractFile
Returns:
the total space (in bytes) of the disk/volume where this file is, -1 if this information is not available

getUnderlyingFileObject

public java.lang.Object getUnderlyingFileObject()
Returns a com.sun.xfile.XFile instance corresponding to this file.

Specified by:
getUnderlyingFileObject in class AbstractFile
Returns:
the file Object of the underlying API providing access to the filesystem, null if there is none

canRunProcess

public boolean canRunProcess()
Always returns false.

Specified by:
canRunProcess in class AbstractFile
Returns:
true if it's possible to run processes on the underlying file system, false otherwise.

runProcess

public AbstractProcess runProcess(java.lang.String[] tokens)
                           throws java.io.IOException
Always throws an IOException.

Specified by:
runProcess in class AbstractFile
Parameters:
tokens - command and its arguments for the process to create.
Returns:
a process executing the specified command tokens using this file as a working directory.
Throws:
java.io.IOException - thrown if an error occured while creating the process, if the current file is not a directory or if the operation is not supported.

ls

public AbstractFile[] ls(FilenameFilter filenameFilter)
                  throws java.io.IOException
Description copied from class: AbstractFile
Returns the children files that this file contains, filtering out files that do not match the specified FilenameFilter. For this operation to be successful, this file must be 'browsable', i.e. AbstractFile.isBrowsable() must return true.

This default implementation filters out files *after* they have been created. This method should be overridden if a more efficient implementation can be provided by subclasses.

Overrides:
ls in class AbstractFile
Parameters:
filenameFilter - the FilenameFilter to be used to filter out files from the list, may be null
Returns:
the children files that this file contains
Throws:
java.io.IOException - if this operation is not possible (file is not browsable) or if an error occurred.

moveTo

public boolean moveTo(AbstractFile destFile)
               throws FileTransferException
Overrides AbstractFile.moveTo(AbstractFile) to move/rename the file directly if the destination file is also an NFSFile.

Overrides:
moveTo in class AbstractFile
Parameters:
destFile - the destination file to move this file to
Returns:
true if the operation could be successfully be completed, false if the operation could not be performed because of unsatisfied conditions (not an error)
Throws:
FileTransferException - in any of the cases listed above, use FileTransferException.getReason() to know the reason.


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard