Package org.apache.sshd.sftp.client.fs
Class SftpFileSystem.Wrapper
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.client.subsystem.AbstractSubsystemClient
org.apache.sshd.sftp.client.impl.AbstractSftpClient
org.apache.sshd.sftp.client.fs.SftpFileSystem.Wrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ClientChannelHolder
,ClientSessionHolder
,SubsystemClient
,ChannelHolder
,NamedResource
,SessionContextHolder
,SessionHolder<ClientSession>
,FullAccessSftpClient
,RawSftpClient
,SftpClient
,SftpErrorDataHandler
- Enclosing class:
- SftpFileSystem
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.sshd.sftp.client.SftpClient
SftpClient.Attribute, SftpClient.Attributes, SftpClient.CloseableHandle, SftpClient.CopyMode, SftpClient.DirEntry, SftpClient.Handle, SftpClient.OpenMode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicInteger
private final SftpClient
private final int
private final int
Fields inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
errorDataHandler, INIT_COMMAND_SIZE
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
Fields inherited from interface org.apache.sshd.common.NamedResource
BY_NAME_COMPARATOR, NAME_EXTRACTOR
Fields inherited from interface org.apache.sshd.sftp.client.SftpClient
DEFAULT_CHANNEL_MODES, EMPTY_DIR_ENTRIES, IO_BUFFER_SIZE, MIN_BUFFER_SIZE, MIN_READ_BUFFER_SIZE, MIN_WRITE_BUFFER_SIZE
Fields inherited from interface org.apache.sshd.sftp.client.SftpErrorDataHandler
EMPTY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Wrapper
(SftpClient delegate, SftpErrorDataHandler errorHandler, int readSize, int writeSize) -
Method Summary
Modifier and TypeMethodDescriptioncanonicalPath
(String path) The effective "normalized" remote pathvoid
close()
void
close
(SftpClient.Handle handle) Close the handle obtained from one of theopen
methodsNavigableMap<String,
byte[]> int
void
boolean
boolean
isOpen()
void
Create a linklistDir
(SftpClient.Handle handle) void
lock
(SftpClient.Handle handle, long offset, long length, int mask) Retrieve remote path meta-data - do not follow symbolic linksvoid
Create remote directoryopen
(String path, Collection<SftpClient.OpenMode> options) Opens a remote file with the specified mode(s)Obtain a handle for a directoryread
(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) Read a remote file's data via an input streamread
(String path, Collection<SftpClient.OpenMode> mode) read
(String path, SftpClient.OpenMode... mode) int
read
(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) readDir
(SftpClient.Handle handle) Retrieve target of a linkreceive
(int id) receive
(int id, long timeout) void
void
rename
(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) void
Remove remote directoryint
void
void
setStat
(String path, SftpClient.Attributes attributes) Update remote node meta-datavoid
setStat
(SftpClient.Handle handle, SftpClient.Attributes attributes) Update remote node meta-dataRetrieve remote path meta-data - follow symbolic links if encounteredstat
(SftpClient.Handle handle) Retrieve file/directory handle meta-datavoid
Create symbolic linkvoid
unlock
(SftpClient.Handle handle, long offset, long length) write
(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) Write to a remote file via an output streamwrite
(String path, Collection<SftpClient.OpenMode> mode) write
(String path, SftpClient.OpenMode... mode) void
write
(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) Write data to (open) file handleMethods inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
checkAttributes, checkAttributesResponse, checkCommandStatus, checkData, checkDataResponse, checkDirResponse, checkHandle, checkHandleResponse, checkOneName, checkOneNameResponse, checkResponseStatus, checkResponseStatus, errorData, getChannel, getExtension, getExtension, getParsedServerExtensions, getParsedServerExtensions, getReadBufferSize, getReferencedName, getWriteBufferSize, handleUnexpectedAttributesPacket, handleUnexpectedHandlePacket, handleUnexpectedPacket, handleUnknownDataPacket, handleUnknownDirListingPacket, handleUnknownOneNamePacket, openRemoteFileChannel, putReferencedName, read, readAttributes, readDir, throwStatusException, validateIncomingResponse, writeAttributes
Methods inherited from class org.apache.sshd.client.subsystem.AbstractSubsystemClient
toString
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
Methods inherited from interface org.apache.sshd.sftp.client.SftpClient
getExtension, getName, open, open, openRemoteFileChannel, openRemotePathChannel, openRemotePathChannel, read, read, read, read, readEntries, rename, rename, singleSessionInstance, write, write, write
Methods inherited from interface org.apache.sshd.client.subsystem.SubsystemClient
getSession
-
Field Details
-
delegate
-
count
-
readSize
private final int readSize -
writeSize
private final int writeSize
-
-
Constructor Details
-
Wrapper
private Wrapper(SftpClient delegate, SftpErrorDataHandler errorHandler, int readSize, int writeSize)
-
-
Method Details
-
getVersion
public int getVersion()- Returns:
- The negotiated SFTP protocol version
-
getClientSession
- Returns:
- The underlying
ClientSession
used
-
getClientChannel
- Returns:
- The underlying
ClientChannel
used
-
getServerExtensions
- Returns:
- An (unmodifiable)
NavigableMap
of the reported server extensions. where key=extension name (case insensitive)
-
getNameDecodingCharset
- Returns:
- The (never
null
)Charset
used to decode referenced files/folders names - See Also:
-
setNameDecodingCharset
-
isClosing
public boolean isClosing() -
isOpen
public boolean isOpen() -
close
- Throws:
IOException
-
increment
public void increment() -
open
public SftpClient.CloseableHandle open(String path, Collection<SftpClient.OpenMode> options) throws IOException Description copied from interface:SftpClient
Opens a remote file with the specified mode(s)- Specified by:
open
in interfaceSftpClient
- Overrides:
open
in classAbstractSftpClient
- Parameters:
path
- The remote pathoptions
- The desired mode - if none specified thenSftpClient.OpenMode.Read
is assumed- Returns:
- The file's
SftpClient.CloseableHandle
- Throws:
IOException
- If failed to open the remote file
-
close
Description copied from interface:SftpClient
Close the handle obtained from one of theopen
methods- Specified by:
close
in interfaceSftpClient
- Overrides:
close
in classAbstractSftpClient
- Parameters:
handle
- TheHandle
to close- Throws:
IOException
- If failed to execute
-
remove
- Specified by:
remove
in interfaceSftpClient
- Overrides:
remove
in classAbstractSftpClient
- Parameters:
path
- The remote path to remove- Throws:
IOException
- If failed to execute
-
rename
public void rename(String oldPath, String newPath, Collection<SftpClient.CopyMode> options) throws IOException - Specified by:
rename
in interfaceSftpClient
- Overrides:
rename
in classAbstractSftpClient
- Throws:
IOException
-
read
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws IOException - Throws:
IOException
-
write
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws IOException Description copied from interface:SftpClient
Write data to (open) file handle- Specified by:
write
in interfaceSftpClient
- Overrides:
write
in classAbstractSftpClient
- Parameters:
handle
- The fileSftpClient.Handle
fileOffset
- Zero-based offset to write in filesrc
- Data buffersrcOffset
- Offset of valid data in bufferlen
- Number of bytes to write- Throws:
IOException
- If failed to write the data
-
mkdir
Description copied from interface:SftpClient
Create remote directory- Specified by:
mkdir
in interfaceSftpClient
- Overrides:
mkdir
in classAbstractSftpClient
- Parameters:
path
- Remote directory path- Throws:
IOException
- If failed to execute
-
rmdir
Description copied from interface:SftpClient
Remove remote directory- Specified by:
rmdir
in interfaceSftpClient
- Overrides:
rmdir
in classAbstractSftpClient
- Parameters:
path
- Remote directory path- Throws:
IOException
- If failed to execute
-
openDir
Description copied from interface:SftpClient
Obtain a handle for a directory- Specified by:
openDir
in interfaceSftpClient
- Overrides:
openDir
in classAbstractSftpClient
- Parameters:
path
- Remote directory path- Returns:
- The associated directory
SftpClient.Handle
- Throws:
IOException
- If failed to execute
-
readDir
- Parameters:
handle
- DirectorySftpClient.Handle
to read from- Returns:
- A
List
of entries -null
to indicate no more entries Note: the list may be incomplete since the client and server have some internal imposed limit on the number of entries they can process. Therefore several calls to this method may be required (untilnull
). In order to iterate over all the entries useSftpClient.readDir(String)
- Throws:
IOException
- If failed to access the remote site
-
listDir
- Specified by:
listDir
in interfaceSftpClient
- Overrides:
listDir
in classAbstractSftpClient
- Parameters:
handle
- A directorySftpClient.Handle
- Returns:
- An
Iterable
that can be used to iterate over all the directory entries (likeSftpClient.readDir(String)
). Note: the iterable instance is not re-usable - i.e., files can be iterated only once - Throws:
IOException
- If failed to access the directory
-
canonicalPath
Description copied from interface:SftpClient
The effective "normalized" remote path- Specified by:
canonicalPath
in interfaceSftpClient
- Overrides:
canonicalPath
in classAbstractSftpClient
- Parameters:
path
- The requested path - may be relative, and/or contain dots - e.g., ".", "..", "./foo", "../bar"- Returns:
- The effective "normalized" remote path
- Throws:
IOException
- If failed to execute
-
stat
Description copied from interface:SftpClient
Retrieve remote path meta-data - follow symbolic links if encountered- Specified by:
stat
in interfaceSftpClient
- Overrides:
stat
in classAbstractSftpClient
- Parameters:
path
- The remote path- Returns:
- The associated
SftpClient.Attributes
- Throws:
IOException
- If failed to execute
-
lstat
Description copied from interface:SftpClient
Retrieve remote path meta-data - do not follow symbolic links- Specified by:
lstat
in interfaceSftpClient
- Overrides:
lstat
in classAbstractSftpClient
- Parameters:
path
- The remote path- Returns:
- The associated
SftpClient.Attributes
- Throws:
IOException
- If failed to execute
-
stat
Description copied from interface:SftpClient
Retrieve file/directory handle meta-data- Specified by:
stat
in interfaceSftpClient
- Overrides:
stat
in classAbstractSftpClient
- Parameters:
handle
- TheSftpClient.Handle
obtained via one of theopen
calls- Returns:
- The associated
SftpClient.Attributes
- Throws:
IOException
- If failed to execute
-
setStat
Description copied from interface:SftpClient
Update remote node meta-data- Specified by:
setStat
in interfaceSftpClient
- Overrides:
setStat
in classAbstractSftpClient
- Parameters:
path
- The remote pathattributes
- TheSftpClient.Attributes
to update- Throws:
IOException
- If failed to execute
-
setStat
Description copied from interface:SftpClient
Update remote node meta-data- Specified by:
setStat
in interfaceSftpClient
- Overrides:
setStat
in classAbstractSftpClient
- Parameters:
handle
- TheSftpClient.Handle
obtained via one of theopen
callsattributes
- TheSftpClient.Attributes
to update- Throws:
IOException
- If failed to execute
-
readLink
Description copied from interface:SftpClient
Retrieve target of a link- Specified by:
readLink
in interfaceSftpClient
- Overrides:
readLink
in classAbstractSftpClient
- Parameters:
path
- Remote path that represents a link- Returns:
- The link target
- Throws:
IOException
- If failed to execute
-
symLink
Description copied from interface:SftpClient
Create symbolic link- Parameters:
linkPath
- The link locationtargetPath
- The referenced target by the link- Throws:
IOException
- If failed to execute- See Also:
-
readDir
- Specified by:
readDir
in interfaceSftpClient
- Overrides:
readDir
in classAbstractSftpClient
- Parameters:
path
- The remote directory path- Returns:
- An
Iterable
that can be used to iterate over all the directory entries (unlikeSftpClient.readDir(Handle)
) - Throws:
IOException
- If failed to access the remote site- See Also:
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSftpClient
- Overrides:
read
in classAbstractSftpClient
- Throws:
IOException
-
read
public InputStream read(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException Description copied from interface:SftpClient
Read a remote file's data via an input stream- Specified by:
read
in interfaceSftpClient
- Overrides:
read
in classAbstractSftpClient
- Parameters:
path
- The remote file pathbufferSize
- The internal read buffer sizemode
- The remote fileSftpClient.OpenMode
s- Returns:
- An
InputStream
for reading the remote file data - Throws:
IOException
- If failed to execute
-
write
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
write
in interfaceSftpClient
- Overrides:
write
in classAbstractSftpClient
- Throws:
IOException
-
write
public OutputStream write(String path, int bufferSize, Collection<SftpClient.OpenMode> mode) throws IOException Description copied from interface:SftpClient
Write to a remote file via an output stream- Specified by:
write
in interfaceSftpClient
- Overrides:
write
in classAbstractSftpClient
- Parameters:
path
- The remote file pathbufferSize
- The internal write buffer sizemode
- The remote fileSftpClient.OpenMode
s- Returns:
- An
OutputStream
for writing the data - Throws:
IOException
- If failed to execute
-
link
Description copied from interface:SftpClient
Create a link- Specified by:
link
in interfaceSftpClient
- Overrides:
link
in classAbstractSftpClient
- Parameters:
linkPath
- The link locationtargetPath
- The referenced target by the linksymbolic
- Iftrue
then make this a symbolic link, otherwise a hard one- Throws:
IOException
- If failed to execute
-
lock
- Specified by:
lock
in interfaceSftpClient
- Overrides:
lock
in classAbstractSftpClient
- Throws:
IOException
-
unlock
- Specified by:
unlock
in interfaceSftpClient
- Overrides:
unlock
in classAbstractSftpClient
- Throws:
IOException
-
send
- Parameters:
cmd
- Command to send - Note: only lower 8-bits are usedbuffer
- TheBuffer
containing the command data- Returns:
- The assigned request id
- Throws:
IOException
- if failed to send command
-
receive
- Parameters:
id
- The expected request id- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-
receive
- Parameters:
id
- The expected request idtimeout
- The amount of time to wait for the response- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-
receive
- Parameters:
id
- The expected request idtimeout
- The amount of time to wait for the response- Returns:
- The received response
Buffer
containing the request id - Throws:
IOException
- If connection closed or interrupted
-