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
PermissionDeniedException
IOException
public void closeFilesystem()
FileSystem
closeFilesystem
in interface FileSystem
public boolean makeDirectory(String path, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
makeDirectory
in interface FileSystem
path
- String the absolute path to the new directory.PermissionDeniedException
- if the user cannot perform this
operation.FileNotFoundException
- if the parent directory does not exist.IOException
public SftpFileAttributes getFileAttributes(byte[] handle) throws IOException, InvalidHandleException, PermissionDeniedException
FileSystem
getFileAttributes
in interface FileSystem
handle
- byte[]IOException
InvalidHandleException
PermissionDeniedException
public SftpFileAttributes getFileAttributes(String path) throws IOException, FileNotFoundException, PermissionDeniedException
FileSystem
getFileAttributes
in interface FileSystem
path
- String the absolute path to the fileIOException
FileNotFoundException
- if the file cannot be foundPermissionDeniedException
- if the user does not have access to
this fileSftpFileAttributes
public byte[] openDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
openDirectory
in interface FileSystem
path
- StringPermissionDeniedException
FileNotFoundException
IOException
public 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
FileSystem
Read 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 FileSystem
handle
- byte[]InvalidHandleException
- the handle supplied is invalid.EOFException
- thrown once all the files contained with the
directory have been read.IOException
- an error occurredPermissionDeniedException
public byte[] openFile(String path, UnsignedInteger32 flags, SftpFileAttributes attrs) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
openFile
in interface FileSystem
path
- Stringflags
- UnsignedInteger32attrs
- SftpFileAttributesPermissionDeniedException
FileNotFoundException
IOException
public int readFile(byte[] handle, UnsignedInteger64 offset, byte[] buf, int start, int numBytesToRead) throws InvalidHandleException, EOFException, IOException
FileSystem
readFile
in interface FileSystem
handle
- byte[]offset
- UnsignedInteger64buf
- byte[]start
- intnumBytesToRead
- intInvalidHandleException
EOFException
IOException
public void writeFile(byte[] handle, UnsignedInteger64 offset, byte[] data, int off, int len) throws InvalidHandleException, IOException
FileSystem
writeFile
in interface FileSystem
handle
- byte[]offset
- UnsignedInteger64data
- byte[]off
- intlen
- intInvalidHandleException
IOException
public void closeFile(byte[] handle) throws InvalidHandleException, IOException
FileSystem
closeFile
in interface FileSystem
handle
- byte[]InvalidHandleException
IOException
public boolean closeFile(byte[] handle, boolean remove) throws InvalidHandleException, IOException
InvalidHandleException
IOException
protected boolean closeFile(String handle, boolean remove) throws InvalidHandleException, IOException
InvalidHandleException
IOException
public void removeFile(String path) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystem
removeFile
in interface FileSystem
path
- StringPermissionDeniedException
IOException
FileNotFoundException
public void renameFile(String oldpath, String newpath) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
renameFile
in interface FileSystem
oldpath
- Stringnewpath
- StringPermissionDeniedException
FileNotFoundException
IOException
public void copyFile(String oldpath, String newpath, boolean overwrite) throws PermissionDeniedException, FileNotFoundException, IOException
public String getDefaultPath() throws IOException, PermissionDeniedException
FileSystem
getDefaultPath
in interface FileSystem
FileNotFoundException
- if the users default path does not exist.IOException
PermissionDeniedException
public void removeDirectory(String path) throws PermissionDeniedException, FileNotFoundException, IOException
FileSystem
removeDirectory
in interface FileSystem
path
- StringPermissionDeniedException
FileNotFoundException
IOException
public void setFileAttributes(String path, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, FileNotFoundException
FileSystem
setFileAttributes
in interface FileSystem
path
- Stringattrs
- SftpFileAttributesPermissionDeniedException
IOException
FileNotFoundException
public void setFileAttributes(byte[] handle, SftpFileAttributes attrs) throws PermissionDeniedException, IOException, InvalidHandleException
FileSystem
setFileAttributes
in interface FileSystem
handle
- byte[]attrs
- SftpFileAttributesPermissionDeniedException
IOException
InvalidHandleException
public SftpFile readSymbolicLink(String path) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystem
readSymbolicLink
in interface FileSystem
path
- StringUnsupportedFileOperationException
FileNotFoundException
IOException
PermissionDeniedException
public void createSymbolicLink(String link, String target) throws UnsupportedFileOperationException, FileNotFoundException, IOException, PermissionDeniedException
FileSystem
createSymbolicLink
in interface FileSystem
link
- Stringtarget
- StringUnsupportedFileOperationException
FileNotFoundException
IOException
PermissionDeniedException
public boolean fileExists(String path) throws IOException, PermissionDeniedException
FileSystem
fileExists
in interface FileSystem
path
- StringIOException
PermissionDeniedException
public String getRealPath(String path) throws IOException, FileNotFoundException, PermissionDeniedException
FileSystem
getRealPath
in interface FileSystem
path
- String the path to canonicalize.IOException
- if an unrecoverable error occurs.FileNotFoundException
- if the path cannot be found.PermissionDeniedException
public AbstractFile getFileForHandle(byte[] handle) throws IOException, InvalidHandleException
IOException
InvalidHandleException
public void populateEvent(Event evt)
FileSystem
populateEvent
in interface FileSystem
public Connection getConnection()
public String getPathForHandle(byte[] handle) throws IOException, InvalidHandleException
FileSystem
getPathForHandle
in interface FileSystem
IOException
InvalidHandleException
public void copyData(byte[] handle, UnsignedInteger64 offset, UnsignedInteger64 length, byte[] toHandle, UnsignedInteger64 toOffset) throws IOException, PermissionDeniedException, InvalidHandleException
Copyright © 2023. All rights reserved.