org.apache.commons.vfs.provider.sftp
Class SftpFileObject

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

public class SftpFileObject
extends AbstractFileObject
implements FileObject

An SFTP file.

Version:
$Revision: 480428 $ $Date: 2005-10-14 19:59:47 +0200 (Fr, 14 Okt 2005) $
Author:
Adam Murdoch

Nested Class Summary
private  class SftpFileObject.SftpOutputStream
          An OutputStream that wraps an sftp OutputStream, and closes the channel when the stream is closed.
 
Field Summary
private  com.jcraft.jsch.SftpATTRS attrs
           
private  SftpFileSystem fileSystem
           
private  java.lang.String relPath
           
 
Constructor Summary
protected SftpFileObject(FileName name, SftpFileSystem fileSystem)
           
 
Method Summary
protected  void doCreateFolder()
          Creates this file as a folder.
protected  void doDelete()
          Deletes the file.
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()
          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  java.lang.String[] doListChildren()
          Lists the children of this file.
protected  FileObject[] doListChildrenResolved()
          Lists the children of this file.
protected  void doRename(FileObject newfile)
          Rename the file.
protected  void doSetLastModifiedTime(long modtime)
          Sets the last modified time of this file.
(package private)  java.io.InputStream getInputStream(long filePointer)
          Creates an input stream to read the file content from.
protected  void onChange()
          Called when the type or content of this file changes.
private  void setStat(com.jcraft.jsch.SftpATTRS attrs)
          Set attrs from listChildrenResolved
private  void statSelf()
          Fetches file attrs from server.
 
Methods inherited from class org.apache.commons.vfs.provider.AbstractFileObject
canRenameTo, childrenChanged, childrenChanged, close, copyFrom, createFile, createFolder, delete, delete, doAttach, doDetach, doGetAttributes, doGetCertificates, doIsHidden, doIsReadable, doIsSameFile, doIsWriteable, doSetAttribute, 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, onChildrenChanged, refresh, resolveFile, resolveFile, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.vfs.FileObject
canRenameTo, close, copyFrom, createFile, createFolder, delete, delete, exists, findFiles, findFiles, getChild, getChildren, getContent, getFileOperations, getFileSystem, getName, getParent, getType, getURL, isAttached, isContentOpen, isHidden, isReadable, isWriteable, moveTo, refresh, resolveFile, resolveFile
 

Field Detail

fileSystem

private final SftpFileSystem fileSystem

attrs

private com.jcraft.jsch.SftpATTRS attrs

relPath

private final java.lang.String relPath
Constructor Detail

SftpFileObject

protected SftpFileObject(FileName name,
                         SftpFileSystem fileSystem)
                  throws FileSystemException
Throws:
FileSystemException
Method Detail

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 class AbstractFileObject
Throws:
java.lang.Exception

onChange

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

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

statSelf

private void statSelf()
               throws java.lang.Exception
Fetches file attrs from server.

Throws:
java.lang.Exception

setStat

private void setStat(com.jcraft.jsch.SftpATTRS attrs)
Set attrs from listChildrenResolved


doCreateFolder

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

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

doGetLastModifiedTime

protected long doGetLastModifiedTime()
                              throws java.lang.Exception
Description copied from class: AbstractFileObject
Returns the last modified time of this file. Is only called if AbstractFileObject.doGetType() does not return FileType.IMAGINARY.

This implementation throws an exception.

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

doSetLastModifiedTime

protected void doSetLastModifiedTime(long modtime)
                              throws java.lang.Exception
Sets the last modified time of this file. Is only called if doGetType() does not return FileType.IMAGINARY.

Overrides:
doSetLastModifiedTime in class AbstractFileObject
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.
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
Rename the file.

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

doListChildrenResolved

protected FileObject[] doListChildrenResolved()
                                       throws java.lang.Exception
Lists the children of this file.

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

doListChildren

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

Specified by:
doListChildren 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

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

getInputStream

java.io.InputStream getInputStream(long filePointer)
                             throws java.io.IOException
Creates an input stream to read the file content from.

Throws:
java.io.IOException

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

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