org.apache.sshd.server.filesystem
Class NativeSshFile

java.lang.Object
  extended by org.apache.sshd.server.filesystem.NativeSshFile
All Implemented Interfaces:
SshFile

public class NativeSshFile
extends Object
implements SshFile

Internal class, do not use directly. This class wraps native file object.

Author:
Apache MINA Project

Constructor Summary
protected NativeSshFile(String fileName, File file, String userName)
          Constructor, internal do not use directly.
 
Method Summary
 boolean create()
          Create a new file
 InputStream createInputStream(long offset)
          Create input stream for reading.
 OutputStream createOutputStream(long offset)
          Create output stream for writing.
 boolean delete()
          Delete file.
 boolean doesExist()
          Does this file exists?
 boolean equals(Object obj)
           
 String getAbsolutePath()
          Get full name.
 long getLastModified()
          Get last modified time.
 String getName()
          Get short name.
 SshFile getParentFile()
          Get the immediate parent.
static String getPhysicalName(String rootDir, String currDir, String fileName)
          Get the physical canonical file name.
static String getPhysicalName(String rootDir, String currDir, String fileName, boolean caseInsensitive)
           
 long getSize()
          Get file size.
 void handleClose()
          Handle post-handle-close functionality.
 boolean isDirectory()
          Is it a directory?
 boolean isExecutable()
          Check file exec permission.
 boolean isFile()
          Is it a file?
 boolean isReadable()
          Check read permission.
 boolean isRemovable()
          Has delete permission.
 boolean isWritable()
          Check file write permission.
 List<SshFile> listSshFiles()
          List files.
 boolean mkdir()
          Create directory.
 boolean move(SshFile dest)
          Move file object.
static String normalizeSeparateChar(String pathName)
          Normalize separate character.
 boolean setLastModified(long time)
          Set the last modified time stamp of a file
 void truncate()
          Truncate file to length 0.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NativeSshFile

protected NativeSshFile(String fileName,
                        File file,
                        String userName)
Constructor, internal do not use directly.

Method Detail

getAbsolutePath

public String getAbsolutePath()
Get full name.

Specified by:
getAbsolutePath in interface SshFile
Returns:
a path where the path separator is '/' (even if the operating system uses another character as path separator).

getName

public String getName()
Get short name.

Specified by:
getName in interface SshFile
Returns:
the last part of the file path (the part after the last '/').

isDirectory

public boolean isDirectory()
Is it a directory?

Specified by:
isDirectory in interface SshFile
Returns:
true if the SshFile is a directory

isFile

public boolean isFile()
Is it a file?

Specified by:
isFile in interface SshFile
Returns:
true if the SshFile is a file, false if it is a directory

doesExist

public boolean doesExist()
Does this file exists?

Specified by:
doesExist in interface SshFile
Returns:
true if the SshFile exists

getSize

public long getSize()
Get file size.

Specified by:
getSize in interface SshFile
Returns:
The size of the SshFile in bytes

getLastModified

public long getLastModified()
Get last modified time.

Specified by:
getLastModified in interface SshFile
Returns:
The timestamp of the last modified time for the SshFile

setLastModified

public boolean setLastModified(long time)
Set the last modified time stamp of a file

Specified by:
setLastModified in interface SshFile
Parameters:
time - The last modified time, in milliseconds since the epoch. See File.setLastModified(long).

isReadable

public boolean isReadable()
Check read permission.

Specified by:
isReadable in interface SshFile
Returns:
true if the SshFile is readable by the user

isWritable

public boolean isWritable()
Check file write permission.

Specified by:
isWritable in interface SshFile
Returns:
true if the SshFile is writable by the user

isExecutable

public boolean isExecutable()
Check file exec permission.

Specified by:
isExecutable in interface SshFile
Returns:
true if the SshFile is executable by the user

isRemovable

public boolean isRemovable()
Has delete permission.

Specified by:
isRemovable in interface SshFile
Returns:
true if the SshFile is removable by the user

getParentFile

public SshFile getParentFile()
Description copied from interface: SshFile
Get the immediate parent. Returns the root directory if the current file is the root.

Specified by:
getParentFile in interface SshFile
Returns:

delete

public boolean delete()
Delete file.

Specified by:
delete in interface SshFile
Returns:
true if the operation was successful

create

public boolean create()
               throws IOException
Create a new file

Specified by:
create in interface SshFile
Returns:
true if the file has been created and false if it already exist
Throws:
IOException - if something wrong happen

truncate

public void truncate()
              throws IOException
Truncate file to length 0.

Specified by:
truncate in interface SshFile
Throws:
IOException - if something wrong happen

move

public boolean move(SshFile dest)
Move file object.

Specified by:
move in interface SshFile
Parameters:
dest - The target SshFile to move the current SshFile to
Returns:
true if the operation was successful

mkdir

public boolean mkdir()
Create directory.

Specified by:
mkdir in interface SshFile
Returns:
true if the operation was successful

listSshFiles

public List<SshFile> listSshFiles()
List files. If not a directory or does not exist, null will be returned.

Specified by:
listSshFiles in interface SshFile
Returns:
The List of SshFiles

createOutputStream

public OutputStream createOutputStream(long offset)
                                throws IOException
Create output stream for writing.

Specified by:
createOutputStream in interface SshFile
Parameters:
offset - The number of bytes at where to start writing. If the file is not random accessible, any offset other than zero will throw an exception.
Returns:
An OutputStream used to write to the SshFile
Throws:
IOException

createInputStream

public InputStream createInputStream(long offset)
                              throws IOException
Create input stream for reading.

Specified by:
createInputStream in interface SshFile
Parameters:
offset - The number of bytes of where to start reading. If the file is not random accessible, any offset other than zero will throw an exception.
Returns:
An InputStream used to read the SshFile
Throws:
IOException

handleClose

public void handleClose()
Description copied from interface: SshFile
Handle post-handle-close functionality.

Specified by:
handleClose in interface SshFile

normalizeSeparateChar

public static final String normalizeSeparateChar(String pathName)
Normalize separate character. Separate character should be '/' always.


getPhysicalName

public static final String getPhysicalName(String rootDir,
                                           String currDir,
                                           String fileName)
Get the physical canonical file name. It works like File.getCanonicalPath().

Parameters:
rootDir - The root directory.
currDir - The current directory. It will always be with respect to the root directory.
fileName - The input file name.
Returns:
The return string will always begin with the root directory. It will never be null.

getPhysicalName

public static final String getPhysicalName(String rootDir,
                                           String currDir,
                                           String fileName,
                                           boolean caseInsensitive)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2008-2012 Apache Software Foundation. All Rights Reserved.