Class FtpFileObject
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<FtpFileSystem>
-
- org.apache.commons.vfs2.provider.ftp.FtpFileObject
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
public class FtpFileObject extends AbstractFileObject<FtpFileSystem>
An FTP file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (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
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,org.apache.commons.net.ftp.FTPFile>
childMap
private static long
DEFAULT_TIMESTAMP
private static java.util.Map<java.lang.String,org.apache.commons.net.ftp.FTPFile>
EMPTY_FTP_FILE_MAP
private org.apache.commons.net.ftp.FTPFile
ftpFile
private java.util.concurrent.atomic.AtomicBoolean
inRefresh
private FileObject
linkDestination
private static org.apache.commons.logging.Log
log
private boolean
mdtmSet
private java.lang.String
relPath
private static org.apache.commons.net.ftp.FTPFile
UNKNOWN
-
Fields inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
DEFAULT_BUFFER_SIZE
-
Fields inherited from interface org.apache.commons.vfs2.FileObject
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FtpFileObject(AbstractFileName name, FtpFileSystem fileSystem, FileName rootName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(int bufferSize)
Creates an input stream to read the file content from.protected long
doGetLastModifiedTime()
Get the last modified time on an FTP fileprotected 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 fileprivate org.apache.commons.net.ftp.FTPFile
getChildFile(java.lang.String name, boolean flush)
Called by child file objects, to locate their FTP file info.FileObject[]
getChildren()
Returns the file's list of children.(package private) FtpFileObject.FtpInputStream
getInputStream(long filePointer)
private FileObject
getLinkDestination()
(package private) java.lang.String
getRelPath()
private long
getTimestampMillis()
ftpFile is not null.private boolean
isCircular(FileObject linkDest)
This is an over simplistic implementation for VFS-437.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 underlying file system if required.private void
setFTPFile(boolean flush)
Sets the internal FTPFile for this instance.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, close, compareTo, copyFrom, createFile, createFolder, delete, delete, deleteAll, doCreateFileContent, doGetAttributes, doGetCertificates, doGetInputStream, doIsExecutable, doIsHidden, doIsReadable, doIsSameFile, doIsSymbolicLink, doIsWriteable, doRemoveAttribute, doSetAttribute, doSetExecutable, doSetLastModifiedTime, doSetReadable, doSetWritable, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getContent, getFileContentInfoFactory, getFileOperations, getFileSystem, getInputStream, getInputStream, getName, getOutputStream, getOutputStream, getParent, getPublicURIString, getRandomAccessContent, getType, getURL, handleChanged, handleCreate, handleDelete, holdObject, injectType, isAttached, isContentOpen, isExecutable, isFile, isFolder, isHidden, isReadable, isSameFile, isSymbolicLink, isWriteable, iterator, listFiles, moveTo, notifyAllStreamsClosed, resolveFile, resolveFile, setExecutable, setReadable, setWritable, toString
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.vfs2.FileObject
getPath, getURI
-
-
-
-
Field Detail
-
DEFAULT_TIMESTAMP
private static final long DEFAULT_TIMESTAMP
- See Also:
- Constant Field Values
-
EMPTY_FTP_FILE_MAP
private static final java.util.Map<java.lang.String,org.apache.commons.net.ftp.FTPFile> EMPTY_FTP_FILE_MAP
-
UNKNOWN
private static final org.apache.commons.net.ftp.FTPFile UNKNOWN
-
log
private static final org.apache.commons.logging.Log log
-
mdtmSet
private volatile boolean mdtmSet
-
relPath
private final java.lang.String relPath
-
ftpFile
private volatile org.apache.commons.net.ftp.FTPFile ftpFile
-
childMap
private volatile java.util.Map<java.lang.String,org.apache.commons.net.ftp.FTPFile> childMap
-
linkDestination
private volatile FileObject linkDestination
-
inRefresh
private final java.util.concurrent.atomic.AtomicBoolean inRefresh
-
-
Constructor Detail
-
FtpFileObject
protected FtpFileObject(AbstractFileName name, FtpFileSystem fileSystem, FileName rootName) throws FileSystemException
- Throws:
FileSystemException
-
-
Method Detail
-
doAttach
protected void doAttach() throws java.io.IOException
Attaches this file object to its file resource.- Overrides:
doAttach
in classAbstractFileObject<FtpFileSystem>
- Throws:
java.io.IOException
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this file as a folder.- Overrides:
doCreateFolder
in classAbstractFileObject<FtpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes the file.- Overrides:
doDelete
in classAbstractFileObject<FtpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doDetach
protected void doDetach()
Detaches this file object from its file resource.- Overrides:
doDetach
in classAbstractFileObject<FtpFileSystem>
-
doGetChildren
private void doGetChildren() throws java.io.IOException
Fetches the children of this file, if not already cached.- Throws:
java.io.IOException
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes).- Specified by:
doGetContentSize
in classAbstractFileObject<FtpFileSystem>
- Returns:
- The size of the file in bytes.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetInputStream
protected java.io.InputStream doGetInputStream(int bufferSize) throws java.lang.Exception
Creates an input stream to read the file content from.- Overrides:
doGetInputStream
in classAbstractFileObject<FtpFileSystem>
- Parameters:
bufferSize
- Buffer size hint.- Returns:
- An InputStream to read the file content.
- Throws:
java.lang.Exception
- if an error occurs.
-
doGetLastModifiedTime
protected long doGetLastModifiedTime() throws java.lang.Exception
Get the last modified time on an FTP file- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<FtpFileSystem>
- Returns:
- The last modification time.
- Throws:
java.lang.Exception
- if an error occurs.- See Also:
AbstractFileObject.doGetLastModifiedTime()
-
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 classAbstractFileObject<FtpFileSystem>
- Parameters:
bAppend
- true if the file should be appended to, false if it should be overwritten.- Returns:
- An OutputStream to write to the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
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 ifAbstractFileObject.doGetType()
returnsFileType.FILE
.It is guaranteed that there are no open output streams for this file when this method is called.
- Overrides:
doGetRandomAccessContent
in classAbstractFileObject<FtpFileSystem>
- Parameters:
mode
- The mode to access the file.- Returns:
- The RandomAccessContext.
- Throws:
java.lang.Exception
- if an error occurs.
-
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 classAbstractFileObject<FtpFileSystem>
- Returns:
- the type of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Lists the children of the file.- Specified by:
doListChildren
in classAbstractFileObject<FtpFileSystem>
- Returns:
- a possible empty String array if the file is a directory or null or an exception if the file is not a directory or can't be read.
- Throws:
java.lang.Exception
- if an error occurs.
-
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()
returnsFileType.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 classAbstractFileObject<FtpFileSystem>
- Returns:
- The children of this FileObject.
- Throws:
java.lang.Exception
- if an error occurs.
-
doRename
protected void doRename(FileObject newFile) throws java.lang.Exception
Renames the file- Overrides:
doRename
in classAbstractFileObject<FtpFileSystem>
- Parameters:
newFile
- A FileObject with the new file name.- Throws:
java.lang.Exception
- if an error occurs.
-
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 file name in its native form ie. without URI stuff (%nn)flush
- recreate children cache- Throws:
java.io.IOException
-
getChildren
public FileObject[] getChildren() throws FileSystemException
Returns the file's list of children.- Specified by:
getChildren
in interfaceFileObject
- Overrides:
getChildren
in classAbstractFileObject<FtpFileSystem>
- Returns:
- The list of children
- Throws:
FileSystemException
- If there was a problem listing children- Since:
- 2.0
- See Also:
AbstractFileObject.getChildren()
-
getInputStream
FtpFileObject.FtpInputStream getInputStream(long filePointer) throws java.io.IOException
- Throws:
java.io.IOException
-
getLinkDestination
private FileObject getLinkDestination() throws FileSystemException
- Throws:
FileSystemException
-
getRelPath
java.lang.String getRelPath()
-
getTimestampMillis
private long getTimestampMillis() throws java.io.IOException
ftpFile is not null.- Throws:
java.io.IOException
-
isCircular
private boolean isCircular(FileObject linkDest) throws FileSystemException
This is an over simplistic implementation for VFS-437.- Throws:
FileSystemException
-
onChange
protected void onChange() throws java.io.IOException
Called when the type or content of this file changes.- Overrides:
onChange
in classAbstractFileObject<FtpFileSystem>
- Throws:
java.io.IOException
-
onChildrenChanged
protected void onChildrenChanged(FileName child, FileType newType)
Called when the children of this file change.- Overrides:
onChildrenChanged
in classAbstractFileObject<FtpFileSystem>
- Parameters:
child
- The name of the child that changed.newType
- The type of the file.
-
refresh
public void refresh() throws FileSystemException
Description copied from class:AbstractFileObject
This will prepare the fileObject to get resynchronized with the underlying file system if required.- Specified by:
refresh
in interfaceFileObject
- Overrides:
refresh
in classAbstractFileObject<FtpFileSystem>
- Throws:
FileSystemException
- if an error occurs.
-
setFTPFile
private void setFTPFile(boolean flush) throws java.io.IOException
Sets the internal FTPFile for this instance.- Throws:
java.io.IOException
-
-