Class SftpFileObject
- java.lang.Object
-
- org.apache.commons.vfs2.provider.AbstractFileObject<SftpFileSystem>
-
- org.apache.commons.vfs2.provider.sftp.SftpFileObject
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Comparable<FileObject>
,java.lang.Iterable<FileObject>
,FileObject
public class SftpFileObject extends AbstractFileObject<SftpFileSystem>
An SFTP file.
-
-
Field Summary
-
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
SftpFileObject(AbstractFileName fileName, SftpFileSystem fileSystem)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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()
Returns the last modified time of this 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 this file, returns null if the file does not exist.protected boolean
doIsExecutable()
Determines if this file is executable.protected boolean
doIsReadable()
Determines if this file can be read.protected boolean
doIsWriteable()
Determines if this file can be written to.protected java.lang.String[]
doListChildren()
Lists the children of this file.protected FileObject[]
doListChildrenResolved()
Lists the children of this file.protected void
doRename(FileObject newFile)
Renames the file.protected boolean
doSetExecutable(boolean executable, boolean ownerOnly)
Make the file executable.protected boolean
doSetLastModifiedTime(long modtime)
Sets the last modified time of this file.protected boolean
doSetReadable(boolean readable, boolean ownerOnly)
Make the file or folder readable.protected boolean
doSetWritable(boolean writable, boolean ownerOnly)
Make the file or folder writable.protected PosixPermissions
getPermissions(boolean checkIds)
Returns the POSIX type permissions of the file.protected void
onChange()
Called when the type or content of this file changes.-
Methods inherited from class org.apache.commons.vfs2.provider.AbstractFileObject
canRenameTo, childrenChanged, close, compareTo, copyFrom, createFile, createFolder, delete, delete, deleteAll, doAttach, doCreateFileContent, doGetAttributes, doGetCertificates, doGetInputStream, doIsHidden, doIsSameFile, doIsSymbolicLink, doRemoveAttribute, doSetAttribute, endOutput, exists, finalize, findFiles, findFiles, getAbstractFileSystem, getChild, getChildren, 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, onChildrenChanged, refresh, 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
-
-
-
-
Constructor Detail
-
SftpFileObject
protected SftpFileObject(AbstractFileName fileName, SftpFileSystem fileSystem) throws FileSystemException
Constructs a new instance.- Parameters:
fileName
- the file name.fileSystem
- the file system.- Throws:
FileSystemException
- if a file system error occurs.
-
-
Method Detail
-
doCreateFolder
protected void doCreateFolder() throws java.lang.Exception
Creates this file as a folder.- Overrides:
doCreateFolder
in classAbstractFileObject<SftpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doDelete
protected void doDelete() throws java.lang.Exception
Deletes the file.- Overrides:
doDelete
in classAbstractFileObject<SftpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
doDetach
protected void doDetach() throws java.lang.Exception
Description copied from class:AbstractFileObject
Detaches this file object from its file resource.Called when this file is closed. Note that the file object may be reused later, so should be able to be reattached.
This implementation does nothing.
- Overrides:
doDetach
in classAbstractFileObject<SftpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.- Since:
- 2.0
-
doGetContentSize
protected long doGetContentSize() throws java.lang.Exception
Returns the size of the file content (in bytes).- Specified by:
doGetContentSize
in classAbstractFileObject<SftpFileSystem>
- 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<SftpFileSystem>
- 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
Description copied from class:AbstractFileObject
Returns the last modified time of this file. Is only called ifAbstractFileObject.doGetType()
does not returnThis implementation throws an exception.
- Overrides:
doGetLastModifiedTime
in classAbstractFileObject<SftpFileSystem>
- Returns:
- The last modification time.
- Throws:
java.lang.Exception
- if an error occurs.
-
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<SftpFileSystem>
- 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<SftpFileSystem>
- 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 this file, returns null if the file does not exist.- Specified by:
doGetType
in classAbstractFileObject<SftpFileSystem>
- Returns:
- the type of the file.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsExecutable
protected boolean doIsExecutable() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines if this file is executable. Is only called ifAbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation always returns false.
- Overrides:
doIsExecutable
in classAbstractFileObject<SftpFileSystem>
- Returns:
- true if the file is executable, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsReadable
protected boolean doIsReadable() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines if this file can be read. Is only called ifAbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation always returns true.
- Overrides:
doIsReadable
in classAbstractFileObject<SftpFileSystem>
- Returns:
- true if the file is readable, false otherwise.
- Throws:
java.lang.Exception
- if an error occurs.
-
doIsWriteable
protected boolean doIsWriteable() throws java.lang.Exception
Description copied from class:AbstractFileObject
Determines if this file can be written to. Is only called ifAbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation always returns true.
- Overrides:
doIsWriteable
in classAbstractFileObject<SftpFileSystem>
- Returns:
- true if the file is writable.
- Throws:
java.lang.Exception
- if an error occurs.
-
doListChildren
protected java.lang.String[] doListChildren() throws java.lang.Exception
Lists the children of this file.- Specified by:
doListChildren
in classAbstractFileObject<SftpFileSystem>
- 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
Lists the children of this file.- Overrides:
doListChildrenResolved
in classAbstractFileObject<SftpFileSystem>
- 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<SftpFileSystem>
- Parameters:
newFile
- A FileObject with the new file name.- Throws:
java.lang.Exception
- if an error occurs.
-
doSetExecutable
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file executable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Overrides:
doSetExecutable
in classAbstractFileObject<SftpFileSystem>
- Parameters:
executable
- True to allow access, false to disallow.ownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded.
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- See Also:
AbstractFileObject.setExecutable(boolean, boolean)
-
doSetLastModifiedTime
protected boolean doSetLastModifiedTime(long modtime) throws java.lang.Exception
Sets the last modified time of this file. Is only called ifdoGetType()
does not returnFileType.IMAGINARY
.- Overrides:
doSetLastModifiedTime
in classAbstractFileObject<SftpFileSystem>
- Parameters:
modtime
- is modification time in milliseconds. SFTP protocol can send times with nanosecond precision but at the moment jsch send them with second precision.- Returns:
- true if the time was set.
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.
-
doSetReadable
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file or folder readable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.This implementation returns false.
- Overrides:
doSetReadable
in classAbstractFileObject<SftpFileSystem>
- Parameters:
readable
- True to allow access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- See Also:
AbstractFileObject.setReadable(boolean, boolean)
-
doSetWritable
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws java.lang.Exception
Description copied from class:AbstractFileObject
Make the file or folder writable.Only called if
AbstractFileObject.doGetType()
does not returnFileType.IMAGINARY
.- Overrides:
doSetWritable
in classAbstractFileObject<SftpFileSystem>
- Parameters:
writable
- True to allow access, false to disallowownerOnly
- Iftrue
, the permission applies only to the owner; otherwise, it applies to everybody.- Returns:
- true if the operation succeeded
- Throws:
java.lang.Exception
- Any Exception thrown is wrapped in FileSystemException.- See Also:
AbstractFileObject.setWritable(boolean, boolean)
-
getPermissions
protected PosixPermissions getPermissions(boolean checkIds) throws java.lang.Exception
Returns the POSIX type permissions of the file.- Parameters:
checkIds
-true
if user and group ID should be checked (needed for some access rights checks)- Returns:
- A PosixPermission object
- Throws:
java.lang.Exception
- If an error occurs- Since:
- 2.1
-
onChange
protected void onChange() throws java.lang.Exception
Called when the type or content of this file changes.- Overrides:
onChange
in classAbstractFileObject<SftpFileSystem>
- Throws:
java.lang.Exception
- if an error occurs.
-
-