Package org.apache.sshd.sftp.client.impl
Class SftpOutputStreamAsync
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.sshd.common.util.io.output.OutputStreamWithChannel
-
- org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,java.nio.channels.Channel,SftpClientHolder
public class SftpOutputStreamAsync extends OutputStreamWithChannel implements SftpClientHolder
Implements an output stream for a given remote file
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceSftpOutputStreamAsync.ByteInputprivate static classSftpOutputStreamAsync.ChannelReader
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bbprotected Bufferbufferprivate Buffer[]bufferPoolprotected intbufferSizeprivate AbstractSftpClientclientInstanceprotected SftpClient.CloseableHandlehandleprivate byte[]handleIdprivate SftpMessagelastMsgprotected org.slf4j.Loggerlogprivate intnextBufferprotected longoffsetprivate booleanownsHandleprivate intpacketSizeprivate java.lang.Stringpathprotected java.util.Deque<SftpAckData>pendingAcksprivate intsftpPreambleprivate booleanusePacket
-
Constructor Summary
Constructors Constructor Description SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode)Creates a new stream to write data to a remote file.SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, SftpClient.CloseableHandle handle)Creates a new stream to write data to a remote file.SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, SftpClient.CloseableHandle handle, boolean closeHandle)Creates a new stream to write data to a remote file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckStatus(AbstractSftpClient client, Buffer buf)voidclose()voidflush()private BuffergetBuffer(Session session)AbstractSftpClientgetClient()java.lang.StringgetPath()The remotely accessed file pathprivate voidinternalFlush()private longinternalTransfer(SftpOutputStreamAsync.ByteInput stream, boolean forceFlush)booleanisOpen()voidsetOffset(long offset)java.lang.StringtoString()longtransferFrom(java.io.InputStream stream)longtransferFrom(java.nio.channels.ReadableByteChannel stream, long count)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Field Detail
-
log
protected final org.slf4j.Logger log
-
bb
protected final byte[] bb
-
bufferSize
protected final int bufferSize
-
buffer
protected Buffer buffer
-
handle
protected SftpClient.CloseableHandle handle
-
offset
protected long offset
-
pendingAcks
protected final java.util.Deque<SftpAckData> pendingAcks
-
clientInstance
private final AbstractSftpClient clientInstance
-
path
private final java.lang.String path
-
handleId
private final byte[] handleId
-
ownsHandle
private final boolean ownsHandle
-
bufferPool
private final Buffer[] bufferPool
-
packetSize
private final int packetSize
-
sftpPreamble
private final int sftpPreamble
-
usePacket
private final boolean usePacket
-
nextBuffer
private int nextBuffer
-
lastMsg
private SftpMessage lastMsg
-
-
Constructor Detail
-
SftpOutputStreamAsync
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, java.util.Collection<SftpClient.OpenMode> mode) throws java.io.IOException
Creates a new stream to write data to a remote file.- Parameters:
client-AbstractSftpClientto use for writing databufferSize- SFTP packet length to use. Most servers have a limit of 256kB. If zero, the stream picks a size such that each SFTP packet fits into a single SSH packet, i.e., roughly 32kB.path- remote path to write tomode-SftpClient.OpenModes for opening the file.- Throws:
java.io.IOException- if the remote file cannot be opened
-
SftpOutputStreamAsync
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, SftpClient.CloseableHandle handle)
Creates a new stream to write data to a remote file.- Parameters:
client-AbstractSftpClientto use for writing databufferSize- SFTP packet length to use. Most servers have a limit of 256kB. If zero, the stream picks a size such that each SFTP packet fits into a single SSH packet, i.e., roughly 32kB.handle-SftpClient.CloseableHandleof the remote file to write to; will be closed when this output stream is closed
-
SftpOutputStreamAsync
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, java.lang.String path, SftpClient.CloseableHandle handle, boolean closeHandle)
Creates a new stream to write data to a remote file.- Parameters:
client-AbstractSftpClientto use for writing databufferSize- SFTP packet length to use. Most servers have a limit of 256kB. If zero, the stream picks a size such that each SFTP packet fits into a single SSH packet, i.e., roughly 32kB.handle-SftpClient.CloseableHandleof the remote file to write tocloseHandle- whether to close thehandlewhen this output stream is closed
-
-
Method Detail
-
getClient
public final AbstractSftpClient getClient()
- Specified by:
getClientin interfaceSftpClientHolder
-
setOffset
public void setOffset(long offset)
-
getPath
public final java.lang.String getPath()
The remotely accessed file path- Returns:
- Remote file path
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
transferFrom
public long transferFrom(java.io.InputStream stream) throws java.io.IOException- Throws:
java.io.IOException
-
transferFrom
public long transferFrom(java.nio.channels.ReadableByteChannel stream, long count) throws java.io.IOException- Throws:
java.io.IOException
-
internalTransfer
private long internalTransfer(SftpOutputStreamAsync.ByteInput stream, boolean forceFlush) throws java.io.IOException
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
internalFlush
private void internalFlush() throws java.io.IOException- Throws:
java.io.IOException
-
checkStatus
private void checkStatus(AbstractSftpClient client, Buffer buf) throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-