public final class AbstractFileSystem extends Object implements FileSystem
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractFileSystem.OpenDirectory |
protected class |
AbstractFileSystem.OpenFile |
| Modifier and Type | Field and Description |
|---|---|
protected AbstractFileFactory<?> |
fileFactory |
protected Map<String,AbstractFileSystem.OpenDirectory> |
openDirectories |
protected Map<String,AbstractFileSystem.OpenFile> |
openFiles |
AUTHORIZED_KEYS_STORE, OPEN_APPEND, OPEN_CREATE, OPEN_EXCLUSIVE, OPEN_READ, OPEN_TEXT, OPEN_TRUNCATE, OPEN_WRITE, SCP, SFTP, SHELL| Constructor and Description |
|---|
AbstractFileSystem(AbstractFileFactory<?> fileFactory,
Connection con,
String protocolInUse) |
| Modifier and Type | Method and Description |
|---|---|
void |
closeFile(byte[] handle)
Close an open file or directory.
|
boolean |
closeFile(byte[] handle,
boolean remove) |
protected boolean |
closeFile(String handle,
boolean remove) |
void |
closeFilesystem()
The filesystem instance is being closed and no further use of the
instance is required.
|
void |
copyData(byte[] handle,
UnsignedInteger64 offset,
UnsignedInteger64 length,
byte[] toHandle,
UnsignedInteger64 toOffset) |
void |
copyFile(String oldpath,
String newpath,
boolean overwrite) |
void |
createSymbolicLink(String link,
String target)
Create a symbolic link.
|
boolean |
fileExists(String path)
Determine whether a file exists and return the result
|
Connection |
getConnection() |
String |
getDefaultPath()
Get the default path for the current session.
|
SftpFileAttributes |
getFileAttributes(byte[] handle)
Get the attributes for a given file handle.
|
SftpFileAttributes |
getFileAttributes(String path)
Get the attributes for a given file.
|
AbstractFileFactory<?> |
getFileFactory() |
AbstractFile |
getFileForHandle(byte[] handle) |
protected String |
getHandle(byte[] b) |
protected byte[] |
getHandle(String handle) |
String |
getPathForHandle(byte[] handle)
Return the path for a given handle.
|
String |
getRealPath(String path)
Get the real path for a given path.
|
void |
init(Connection con,
String protocolInUse) |
boolean |
makeDirectory(String path,
SftpFileAttributes attrs)
Create a directory.
|
byte[] |
openDirectory(String path)
Open a directory for reading and allocate an open file handle.
|
byte[] |
openDirectory(String path,
SftpFileFilter filter) |
byte[] |
openFile(String path,
UnsignedInteger32 flags,
SftpFileAttributes attrs)
Open a file for reading/writing and allocate an open file handle.
|
void |
populateEvent(Event evt)
Populate any extra fields in a file system event.
|
SftpFile[] |
readDirectory(byte[] handle)
Read the contents of a directory.
|
int |
readFile(byte[] handle,
UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
Read a block of data from an open file.
|
SftpFile |
readSymbolicLink(String path)
Read the target location of a symbolic link.
|
void |
removeDirectory(String path)
Remove an empty directory from the file system.
|
void |
removeFile(String path)
Remove a file.
|
void |
renameFile(String oldpath,
String newpath)
Rename a file.
|
protected AbstractFile |
resolveFile(String path,
Connection con) |
void |
setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
Set the open files attributes
|
void |
setFileAttributes(String path,
SftpFileAttributes attrs)
Set the files attributes.
|
void |
writeFile(byte[] handle,
UnsignedInteger64 offset,
byte[] data,
int off,
int len)
Write a block of data to an open file.
|
protected Map<String,AbstractFileSystem.OpenFile> openFiles
protected Map<String,AbstractFileSystem.OpenDirectory> openDirectories
protected AbstractFileFactory<?> fileFactory
public AbstractFileSystem(AbstractFileFactory<?> fileFactory, Connection con, String protocolInUse)
public AbstractFileFactory<?> getFileFactory()
public void init(Connection con, String protocolInUse)
protected AbstractFile resolveFile(String path, Connection con) throws PermissionDeniedException, IOException
PermissionDeniedExceptionIOExceptionpublic void closeFilesystem()
FileSystemcloseFilesystem in interface FileSystempublic boolean makeDirectory(String path, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemmakeDirectory in interface FileSystempath - String the absolute path to the new directory.PermissionDeniedException - if the user cannot perform this
operation.FileNotFoundException - if the parent directory does not exist.IOExceptionpublic SftpFileAttributes getFileAttributes(byte[] handle) throws IOException, InvalidHandleException, PermissionDeniedException
FileSystemgetFileAttributes in interface FileSystemhandle - byte[]IOExceptionInvalidHandleExceptionPermissionDeniedExceptionpublic SftpFileAttributes getFileAttributes(String path) throws IOException, FileNotFoundException, PermissionDeniedException
FileSystemgetFileAttributes in interface FileSystempath - String the absolute path to the fileIOExceptionFileNotFoundException - if the file cannot be foundPermissionDeniedException - if the user does not have access to
this fileSftpFileAttributespublic byte[] openDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemopenDirectory in interface FileSystempath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic byte[] openDirectory(String path, SftpFileFilter filter) throws PermissionDeniedException, FileNotFoundException, IOException
protected byte[] getHandle(String handle)
protected String getHandle(byte[] b)
public SftpFile[] readDirectory(byte[] handle) throws InvalidHandleException, EOFException, IOException, PermissionDeniedException
FileSystemRead the contents of a directory. Each call to this method should return one or more file objects with full file attributes for each file. The client will call this method repeatedly until an EOFException is thrown indicating that there are no more files to read from the directory. If there are no files to list then the EOFException should be thrown upon first call.
IMPORTANT: Each SftpFile object should be initialized with the relative path of the file AND NOT the absolute path.
readDirectory in interface FileSystemhandle - byte[]InvalidHandleException - the handle supplied is invalid.EOFException - thrown once all the files contained with the
directory have been read.IOException - an error occurredPermissionDeniedExceptionpublic byte[] openFile(String path, UnsignedInteger32 flags, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemopenFile in interface FileSystempath - Stringflags - UnsignedInteger32attrs - SftpFileAttributesPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic int readFile(byte[] handle,
UnsignedInteger64 offset,
byte[] buf,
int start,
int numBytesToRead)
throws InvalidHandleException,
EOFException,
IOException
FileSystemreadFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64buf - byte[]start - intnumBytesToRead - intInvalidHandleExceptionEOFExceptionIOExceptionpublic void writeFile(byte[] handle,
UnsignedInteger64 offset,
byte[] data,
int off,
int len)
throws InvalidHandleException,
IOException
FileSystemwriteFile in interface FileSystemhandle - byte[]offset - UnsignedInteger64data - byte[]off - intlen - intInvalidHandleExceptionIOExceptionpublic void closeFile(byte[] handle)
throws InvalidHandleException,
IOException
FileSystemcloseFile in interface FileSystemhandle - byte[]InvalidHandleExceptionIOExceptionpublic boolean closeFile(byte[] handle,
boolean remove)
throws InvalidHandleException,
IOException
InvalidHandleExceptionIOExceptionprotected boolean closeFile(String handle, boolean remove) throws InvalidHandleException, IOException
InvalidHandleExceptionIOExceptionpublic void removeFile(String path) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystemremoveFile in interface FileSystempath - StringPermissionDeniedExceptionIOExceptionFileNotFoundExceptionpublic void renameFile(String oldpath, String newpath) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemrenameFile in interface FileSystemoldpath - Stringnewpath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic void copyFile(String oldpath, String newpath, boolean overwrite) throws PermissionDeniedException, FileNotFoundException, IOException
public String getDefaultPath() throws IOException, PermissionDeniedException
FileSystemgetDefaultPath in interface FileSystemFileNotFoundException - if the users default path does not exist.IOExceptionPermissionDeniedExceptionpublic void removeDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystemremoveDirectory in interface FileSystempath - StringPermissionDeniedExceptionFileNotFoundExceptionIOExceptionpublic void setFileAttributes(String path, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystemsetFileAttributes in interface FileSystempath - Stringattrs - SftpFileAttributesPermissionDeniedExceptionIOExceptionFileNotFoundExceptionpublic void setFileAttributes(byte[] handle,
SftpFileAttributes attrs)
throws PermissionDeniedException,
IOException,
InvalidHandleException
FileSystemsetFileAttributes in interface FileSystemhandle - byte[]attrs - SftpFileAttributesPermissionDeniedExceptionIOExceptionInvalidHandleExceptionpublic SftpFile readSymbolicLink(String path) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystemreadSymbolicLink in interface FileSystempath - StringUnsupportedFileOperationExceptionFileNotFoundExceptionIOExceptionPermissionDeniedExceptionpublic void createSymbolicLink(String link, String target) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystemcreateSymbolicLink in interface FileSystemlink - Stringtarget - StringUnsupportedFileOperationExceptionFileNotFoundExceptionIOExceptionPermissionDeniedExceptionpublic boolean fileExists(String path) throws IOException, PermissionDeniedException
FileSystemfileExists in interface FileSystempath - StringIOExceptionPermissionDeniedExceptionpublic String getRealPath(String path) throws IOException, FileNotFoundException, PermissionDeniedException
FileSystemgetRealPath in interface FileSystempath - String the path to canonicalize.IOException - if an unrecoverable error occurs.FileNotFoundException - if the path cannot be found.PermissionDeniedExceptionpublic AbstractFile getFileForHandle(byte[] handle) throws IOException, InvalidHandleException
IOExceptionInvalidHandleExceptionpublic void populateEvent(Event evt)
FileSystempopulateEvent in interface FileSystempublic Connection getConnection()
public String getPathForHandle(byte[] handle) throws IOException, InvalidHandleException
FileSystemgetPathForHandle in interface FileSystemIOExceptionInvalidHandleExceptionpublic void copyData(byte[] handle,
UnsignedInteger64 offset,
UnsignedInteger64 length,
byte[] toHandle,
UnsignedInteger64 toOffset)
throws IOException,
PermissionDeniedException,
InvalidHandleException
Copyright © 2025. All rights reserved.