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:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.Channel
,ClientChannelHolder
,ClientSessionHolder
,SubsystemClient
,ChannelHolder
,NamedResource
,SessionContextHolder
,SessionHolder<ClientSession>
,FullAccessSftpClient
,RawSftpClient
,SftpClient
- Enclosing class:
- SftpFileSystem
private final class SftpFileSystem.Wrapper extends AbstractSftpClient
-
-
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
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicInteger
count
private SftpClient
delegate
private int
readSize
private int
writeSize
-
Fields inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
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
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Wrapper(SftpClient delegate, int readSize, int writeSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
canonicalPath(java.lang.String path)
The effective "normalized" remote pathvoid
close()
void
close(SftpClient.Handle handle)
Close the handle obtained from one of theopen
methodsClientChannel
getClientChannel()
ClientSession
getClientSession()
java.nio.charset.Charset
getNameDecodingCharset()
java.util.NavigableMap<java.lang.String,byte[]>
getServerExtensions()
int
getVersion()
void
increment()
boolean
isClosing()
boolean
isOpen()
void
link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic)
Create a linkjava.lang.Iterable<SftpClient.DirEntry>
listDir(SftpClient.Handle handle)
void
lock(SftpClient.Handle handle, long offset, long length, int mask)
SftpClient.Attributes
lstat(java.lang.String path)
Retrieve remote path meta-data - do not follow symbolic linksvoid
mkdir(java.lang.String path)
Create remote directorySftpClient.CloseableHandle
open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options)
Opens a remote file with the specified mode(s)SftpClient.CloseableHandle
openDir(java.lang.String path)
Obtain a handle for a directoryjava.io.InputStream
read(java.lang.String path)
java.io.InputStream
read(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode)
Read a remote file's data via an input streamjava.io.InputStream
read(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)
java.io.InputStream
read(java.lang.String path, SftpClient.OpenMode... mode)
int
read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len)
java.lang.Iterable<SftpClient.DirEntry>
readDir(java.lang.String path)
java.util.List<SftpClient.DirEntry>
readDir(SftpClient.Handle handle)
java.lang.String
readLink(java.lang.String path)
Retrieve target of a linkBuffer
receive(int id)
Buffer
receive(int id, long timeout)
Buffer
receive(int id, java.time.Duration timeout)
void
remove(java.lang.String path)
void
rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options)
void
rmdir(java.lang.String path)
Remove remote directoryint
send(int cmd, Buffer buffer)
void
setNameDecodingCharset(java.nio.charset.Charset cs)
void
setStat(java.lang.String path, SftpClient.Attributes attributes)
Update remote node meta-datavoid
setStat(SftpClient.Handle handle, SftpClient.Attributes attributes)
Update remote node meta-dataSftpClient.Attributes
stat(java.lang.String path)
Retrieve remote path meta-data - follow symbolic links if encounteredSftpClient.Attributes
stat(SftpClient.Handle handle)
Retrieve file/directory handle meta-datavoid
symLink(java.lang.String linkPath, java.lang.String targetPath)
Create symbolic linkvoid
unlock(SftpClient.Handle handle, long offset, long length)
java.io.OutputStream
write(java.lang.String path)
java.io.OutputStream
write(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode)
Write to a remote file via an output streamjava.io.OutputStream
write(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)
java.io.OutputStream
write(java.lang.String path, SftpClient.OpenMode... mode)
void
write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len)
Write data to (open) file handle-
Methods inherited from class org.apache.sshd.sftp.client.impl.AbstractSftpClient
checkAttributes, checkAttributesResponse, checkCommandStatus, checkData, checkDataResponse, checkDirResponse, checkHandle, checkHandleResponse, checkOneName, checkOneNameResponse, checkResponseStatus, checkResponseStatus, 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 Detail
-
delegate
private final SftpClient delegate
-
count
private final java.util.concurrent.atomic.AtomicInteger count
-
readSize
private final int readSize
-
writeSize
private final int writeSize
-
-
Constructor Detail
-
Wrapper
private Wrapper(SftpClient delegate, int readSize, int writeSize)
-
-
Method Detail
-
getVersion
public int getVersion()
- Returns:
- The negotiated SFTP protocol version
-
getClientSession
public ClientSession getClientSession()
- Returns:
- The underlying
ClientSession
used
-
getClientChannel
public ClientChannel getClientChannel()
- Returns:
- The underlying
ClientChannel
used
-
getServerExtensions
public java.util.NavigableMap<java.lang.String,byte[]> getServerExtensions()
- Returns:
- An (unmodifiable)
NavigableMap
of the reported server extensions. where key=extension name (case insensitive)
-
getNameDecodingCharset
public java.nio.charset.Charset getNameDecodingCharset()
- Returns:
- The (never
null
)Charset
used to decode referenced files/folders names - See Also:
SftpModuleProperties.NAME_DECODING_CHARSET
-
setNameDecodingCharset
public void setNameDecodingCharset(java.nio.charset.Charset cs)
-
isClosing
public boolean isClosing()
-
isOpen
public boolean isOpen()
-
close
public void close() throws java.io.IOException
- Throws:
java.io.IOException
-
increment
public void increment()
-
open
public SftpClient.CloseableHandle open(java.lang.String path, java.util.Collection<SftpClient.OpenMode> options) throws java.io.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:
java.io.IOException
- If failed to open the remote file
-
close
public void close(SftpClient.Handle handle) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
remove
public void remove(java.lang.String path) throws java.io.IOException
- Specified by:
remove
in interfaceSftpClient
- Overrides:
remove
in classAbstractSftpClient
- Parameters:
path
- The remote path to remove- Throws:
java.io.IOException
- If failed to execute
-
rename
public void rename(java.lang.String oldPath, java.lang.String newPath, java.util.Collection<SftpClient.CopyMode> options) throws java.io.IOException
- Specified by:
rename
in interfaceSftpClient
- Overrides:
rename
in classAbstractSftpClient
- Throws:
java.io.IOException
-
read
public int read(SftpClient.Handle handle, long fileOffset, byte[] dst, int dstOffset, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(SftpClient.Handle handle, long fileOffset, byte[] src, int srcOffset, int len) throws java.io.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:
java.io.IOException
- If failed to write the data
-
mkdir
public void mkdir(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Create remote directory- Specified by:
mkdir
in interfaceSftpClient
- Overrides:
mkdir
in classAbstractSftpClient
- Parameters:
path
- Remote directory path- Throws:
java.io.IOException
- If failed to execute
-
rmdir
public void rmdir(java.lang.String path) throws java.io.IOException
Description copied from interface:SftpClient
Remove remote directory- Specified by:
rmdir
in interfaceSftpClient
- Overrides:
rmdir
in classAbstractSftpClient
- Parameters:
path
- Remote directory path- Throws:
java.io.IOException
- If failed to execute
-
openDir
public SftpClient.CloseableHandle openDir(java.lang.String path) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
readDir
public java.util.List<SftpClient.DirEntry> readDir(SftpClient.Handle handle) throws java.io.IOException
- 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:
java.io.IOException
- If failed to access the remote site
-
listDir
public java.lang.Iterable<SftpClient.DirEntry> listDir(SftpClient.Handle handle) throws java.io.IOException
- 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:
java.io.IOException
- If failed to access the directory
-
canonicalPath
public java.lang.String canonicalPath(java.lang.String path) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
stat
public SftpClient.Attributes stat(java.lang.String path) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
lstat
public SftpClient.Attributes lstat(java.lang.String path) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
stat
public SftpClient.Attributes stat(SftpClient.Handle handle) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
setStat
public void setStat(java.lang.String path, SftpClient.Attributes attributes) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
setStat
public void setStat(SftpClient.Handle handle, SftpClient.Attributes attributes) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
readLink
public java.lang.String readLink(java.lang.String path) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
symLink
public void symLink(java.lang.String linkPath, java.lang.String targetPath) throws java.io.IOException
Description copied from interface:SftpClient
Create symbolic link- Parameters:
linkPath
- The link locationtargetPath
- The referenced target by the link- Throws:
java.io.IOException
- If failed to execute- See Also:
SftpClient.link(String, String, boolean)
-
readDir
public java.lang.Iterable<SftpClient.DirEntry> readDir(java.lang.String path) throws java.io.IOException
- 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:
java.io.IOException
- If failed to access the remote site- See Also:
SftpClient.readDir(Handle)
-
read
public java.io.InputStream read(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public java.io.InputStream read(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public java.io.InputStream read(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
- Specified by:
read
in interfaceSftpClient
- Overrides:
read
in classAbstractSftpClient
- Throws:
java.io.IOException
-
read
public java.io.InputStream read(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.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:
java.io.IOException
- If failed to execute
-
write
public java.io.OutputStream write(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path, SftpClient.OpenMode... mode) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
- Specified by:
write
in interfaceSftpClient
- Overrides:
write
in classAbstractSftpClient
- Throws:
java.io.IOException
-
write
public java.io.OutputStream write(java.lang.String path, int bufferSize, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.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:
java.io.IOException
- If failed to execute
-
link
public void link(java.lang.String linkPath, java.lang.String targetPath, boolean symbolic) throws java.io.IOException
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:
java.io.IOException
- If failed to execute
-
lock
public void lock(SftpClient.Handle handle, long offset, long length, int mask) throws java.io.IOException
- Specified by:
lock
in interfaceSftpClient
- Overrides:
lock
in classAbstractSftpClient
- Throws:
java.io.IOException
-
unlock
public void unlock(SftpClient.Handle handle, long offset, long length) throws java.io.IOException
- Specified by:
unlock
in interfaceSftpClient
- Overrides:
unlock
in classAbstractSftpClient
- Throws:
java.io.IOException
-
send
public int send(int cmd, Buffer buffer) throws java.io.IOException
- Parameters:
cmd
- Command to send - Note: only lower 8-bits are usedbuffer
- TheBuffer
containing the command data- Returns:
- The assigned request id
- Throws:
java.io.IOException
- if failed to send command
-
receive
public Buffer receive(int id) throws java.io.IOException
- Parameters:
id
- The expected request id- Returns:
- The received response
Buffer
containing the request id - Throws:
java.io.IOException
- If connection closed or interrupted
-
receive
public Buffer receive(int id, long timeout) throws java.io.IOException
- 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:
java.io.IOException
- If connection closed or interrupted
-
receive
public Buffer receive(int id, java.time.Duration timeout) throws java.io.IOException
- 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:
java.io.IOException
- If connection closed or interrupted
-
-