org.apache.commons.vfs.provider.ftp
Class FtpFileObject

java.lang.Object
  extended by org.apache.commons.vfs.provider.AbstractFileObject
      extended by org.apache.commons.vfs.provider.ftp.FtpFileObject
All Implemented Interfaces:
FileObject

public class FtpFileObject
extends AbstractFileObject

An FTP file.

Version:
$Revision: 484943 $ $Date: 2006-12-09 08:42:06 +0100 (Sa, 09 Dez 2006) $
Author:
Adam Murdoch

Nested Class Summary
(package private)  class FtpFileObject.FtpInputStream
          An InputStream that monitors for end-of-file.
private  class FtpFileObject.FtpOutputStream
          An OutputStream that monitors for end-of-file.
 
Field Summary
private  java.util.Map children
           
private static java.util.Map EMPTY_FTP_FILE_MAP
           
private  org.apache.commons.net.ftp.FTPFile fileInfo
           
private  FtpFileSystem ftpFs
           
private  boolean inRefresh
           
private  FileObject linkDestination
           
private  org.apache.commons.logging.Log log
           
private  java.lang.String relPath
           
 
Constructor Summary
protected FtpFileObject(FileName name, FtpFileSystem fileSystem, FileName rootName)
           
 
Method Summary
protected  void doAttach()
          Attaches this file object to its file resource.
protected  void doCreateFolder()
          Creates this file as a folder.
protected  void doDelete()
          Deletes the file.
protected  void doDetach()
          Detaches this file object from its file resource.
private  void doGetChildren()
          Fetches the children of this file, if not already cached.
protected  long doGetContentSize()
          Returns the size of the file content (in bytes).
protected  java.io.InputStream doGetInputStream()
          Creates an input stream to read the file content from.
protected  long doGetLastModifiedTime()
          get the last modified time on an ftp file
protected  java.io.OutputStream doGetOutputStream(boolean bAppend)
          Creates an output stream to write the file content to.
protected  RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode)
          Creates access to the file for random i/o.
protected  FileType doGetType()
          Determines the type of the file, returns null if the file does not exist.
protected  java.lang.String[] doListChildren()
          Lists the children of the file.
protected  FileObject[] doListChildrenResolved()
          Lists the children of this file.
protected  void doRename(FileObject newfile)
          Renames the file
private  org.apache.commons.net.ftp.FTPFile getChildFile(java.lang.String name, boolean flush)
          Called by child file objects, to locate their ftp file info.
private  void getInfo(boolean flush)
          Fetches the info for this file.
(package private)  FtpFileObject.FtpInputStream getInputStream(long filePointer)
           
private  FileObject getLinkDestination()
           
(package private)  java.lang.String getRelPath()
           
protected  void onChange()
          Called when the type or content of this file changes.
protected  void onChildrenChanged(FileName child, FileType newType)
          Called when the children of this file change.
 void refresh()
          This will prepare the fileObject to get resynchronized with the underlaying filesystem if required
 
Methods inherited from class org.apache.commons.vfs.provider.AbstractFileObject
canRenameTo, childrenChanged, childrenChanged, close, copyFrom, createFile, createFolder, delete, delete, doGetAttributes, doGetCertificates, doIsHidden, doIsReadable, doIsSameFile, doIsWriteable, doSetAttribute, doSetLastModifiedTime, endOutput, exists, finalize, findFiles, findFiles, getChild, getChildren, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getName, getOutputStream, getOutputStream, getParent, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isHidden, isReadable, isSameFile, isWriteable, moveTo, notifyAllStreamsClosed, resolveFile, resolveFile, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

EMPTY_FTP_FILE_MAP

private static final java.util.Map EMPTY_FTP_FILE_MAP

ftpFs

private final FtpFileSystem ftpFs

relPath

private final java.lang.String relPath

fileInfo

private org.apache.commons.net.ftp.FTPFile fileInfo

children

private java.util.Map children

linkDestination

private FileObject linkDestination

inRefresh

private boolean inRefresh
Constructor Detail

FtpFileObject

protected FtpFileObject(FileName name,
                        FtpFileSystem fileSystem,
                        FileName rootName)
                 throws FileSystemException
Throws:
FileSystemException
Method Detail

getChildFile

private org.apache.commons.net.ftp.FTPFile getChildFile(java.lang.String name,
                                                        boolean flush)
                                                 throws java.io.IOException
Called by child file objects, to locate their ftp file info.

Parameters:
name - the filename in its native form ie. without uri stuff (%nn)
flush - recreate children cache
Throws:
java.io.IOException

doGetChildren

private void doGetChildren()
                    throws java.io.IOException
Fetches the children of this file, if not already cached.

Throws:
java.io.IOException

doAttach

protected void doAttach()
                 throws java.io.IOException
Attaches this file object to its file resource.

Overrides:
doAttach in class AbstractFileObject
Throws:
java.io.IOException

getInfo

private void getInfo(boolean flush)
              throws java.io.IOException
Fetches the info for this file.

Throws:
java.io.IOException

refresh

public void refresh()
             throws FileSystemException
Description copied from class: AbstractFileObject
This will prepare the fileObject to get resynchronized with the underlaying filesystem if required

Specified by:
refresh in interface FileObject
Overrides:
refresh in class AbstractFileObject
Throws:
FileSystemException

doDetach

protected void doDetach()
Detaches this file object from its file resource.

Overrides:
doDetach in class AbstractFileObject

onChildrenChanged

protected void onChildrenChanged(FileName child,
                                 FileType newType)
Called when the children of this file change.

Overrides:
onChildrenChanged in class AbstractFileObject

onChange

protected void onChange()
                 throws java.io.IOException
Called when the type or content of this file changes.

Overrides:
onChange in class AbstractFileObject
Throws:
java.io.IOException

doGetType

protected FileType doGetType()
                      throws java.lang.Exception
Determines the type of the file, returns null if the file does not exist.

Specified by:
doGetType in class AbstractFileObject
Throws:
java.lang.Exception

getLinkDestination

private FileObject getLinkDestination()
                               throws FileSystemException
Throws:
FileSystemException

doListChildrenResolved

protected FileObject[] doListChildrenResolved()
                                       throws java.lang.Exception
Description copied from class: AbstractFileObject
Lists the children of this file. Is only called if AbstractFileObject.doGetType() returns FileType.FOLDER. The return value of this method is cached, so the implementation can be expensive.
Other than doListChildren you could return FileObject's to e.g. reinitialize the type of the file.
(Introduced for Webdav: "permission denied on resource" during getType())

Overrides:
doListChildrenResolved in class AbstractFileObject
Throws:
java.lang.Exception

doListChildren

protected java.lang.String[] doListChildren()
                                     throws java.lang.Exception
Lists the children of the file.

Specified by:
doListChildren in class AbstractFileObject
Throws:
java.lang.Exception

doDelete

protected void doDelete()
                 throws java.lang.Exception
Deletes the file.

Overrides:
doDelete in class AbstractFileObject
Throws:
java.lang.Exception

doRename

protected void doRename(FileObject newfile)
                 throws java.lang.Exception
Renames the file

Overrides:
doRename in class AbstractFileObject
Throws:
java.lang.Exception

doCreateFolder

protected void doCreateFolder()
                       throws java.lang.Exception
Creates this file as a folder.

Overrides:
doCreateFolder in class AbstractFileObject
Throws:
java.lang.Exception

doGetContentSize

protected long doGetContentSize()
                         throws java.lang.Exception
Returns the size of the file content (in bytes).

Specified by:
doGetContentSize in class AbstractFileObject
Throws:
java.lang.Exception

doGetLastModifiedTime

protected long doGetLastModifiedTime()
                              throws java.lang.Exception
get the last modified time on an ftp file

Overrides:
doGetLastModifiedTime in class AbstractFileObject
Throws:
java.lang.Exception
See Also:
AbstractFileObject.doGetLastModifiedTime()

doGetInputStream

protected java.io.InputStream doGetInputStream()
                                        throws java.lang.Exception
Creates an input stream to read the file content from.

Specified by:
doGetInputStream in class AbstractFileObject
Throws:
java.lang.Exception

doGetRandomAccessContent

protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode)
                                                throws java.lang.Exception
Description copied from class: AbstractFileObject
Creates access to the file for random i/o. Is only called if AbstractFileObject.doGetType() returns FileType.FILE.

It is guaranteed that there are no open output streams for this file when this method is called.

Overrides:
doGetRandomAccessContent in class AbstractFileObject
Throws:
java.lang.Exception

doGetOutputStream

protected java.io.OutputStream doGetOutputStream(boolean bAppend)
                                          throws java.lang.Exception
Creates an output stream to write the file content to.

Overrides:
doGetOutputStream in class AbstractFileObject
Throws:
java.lang.Exception

getRelPath

java.lang.String getRelPath()

getInputStream

FtpFileObject.FtpInputStream getInputStream(long filePointer)
                                      throws java.io.IOException
Throws:
java.io.IOException