Interface Session<F>
- Type Parameters:
F
- the target system file type.
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
CachingSessionFactory.CachedSession
,FtpSession
,SftpSession
public interface Session<F> extends Closeable
Common abstraction for a Session with a remote File system.
- Since:
- 2.0
- Author:
- Josh Long, Mario Gray, Mark Fisher, Oleg Zhurakousky, Gary Russell, Alen Turkovic, Artem Bilan
-
Method Summary
Modifier and Type Method Description void
append(InputStream inputStream, String destination)
Append to a file.void
close()
default void
dirty()
Mark this session as dirty, indicating that it should not be reused and any delegated sessions should be taken care of before closing.boolean
exists(String path)
Check if the remote file or directory exists.boolean
finalizeRaw()
Invoke after closing the InputStream fromreadRaw(String)
.Object
getClientInstance()
Get the underlying client library's client instance for this session.String
getHostPort()
Return the host:port pair this session is connected to.boolean
isOpen()
F[]
list(String path)
String[]
listNames(String path)
boolean
mkdir(String directory)
void
read(String source, OutputStream outputStream)
InputStream
readRaw(String source)
Retrieve a remote file as a rawInputStream
.boolean
remove(String path)
void
rename(String pathFrom, String pathTo)
boolean
rmdir(String directory)
Remove a remote directory.default boolean
test()
Test the session is still alive, e.g.void
write(InputStream inputStream, String destination)
-
Method Details
-
remove
- Throws:
IOException
-
list
- Throws:
IOException
-
read
- Throws:
IOException
-
write
- Throws:
IOException
-
append
Append to a file.- Parameters:
inputStream
- the stream.destination
- the destination.- Throws:
IOException
- an IO Exception.- Since:
- 4.1
-
mkdir
- Throws:
IOException
-
rmdir
Remove a remote directory.- Parameters:
directory
- The directory.- Returns:
- True if the directory was removed.
- Throws:
IOException
- an IO exception.- Since:
- 4.1
-
rename
- Throws:
IOException
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isOpen
boolean isOpen() -
exists
Check if the remote file or directory exists.- Parameters:
path
- the remote path.- Returns:
true
orfalse
if remote path exists or not.- Throws:
IOException
- an IO exception during remote interaction.
-
listNames
- Throws:
IOException
-
readRaw
Retrieve a remote file as a rawInputStream
.- Parameters:
source
- The path of the remote file.- Returns:
- The raw inputStream.
- Throws:
IOException
- Any IOException.- Since:
- 3.0
-
finalizeRaw
Invoke after closing the InputStream fromreadRaw(String)
. Required by some session providers.- Returns:
- true if successful.
- Throws:
IOException
- Any IOException.- Since:
- 3.0
-
getClientInstance
Object getClientInstance()Get the underlying client library's client instance for this session. Returns anObject
to avoid significant changes to -file, -ftp, -sftp modules, which would be required if we added another generic parameter. Implementations should narrow the return type.- Returns:
- The client instance.
- Since:
- 4.1
-
getHostPort
String getHostPort()Return the host:port pair this session is connected to.- Returns:
- the host:port pair this session is connected to.
- Since:
- 5.2
-
test
default boolean test()Test the session is still alive, e.g. when checking out from a pool. The default implementation simply delegates toisOpen()
.- Returns:
- true if the test is successful.
- Since:
- 5.1
-
dirty
default void dirty()Mark this session as dirty, indicating that it should not be reused and any delegated sessions should be taken care of before closing.- Since:
- 5.1.2
- See Also:
CachingSessionFactory.CachedSession.close()
-