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 interface
SftpOutputStreamAsync.ByteInput
private static class
SftpOutputStreamAsync.ChannelReader
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
bb
protected Buffer
buffer
private Buffer[]
bufferPool
protected int
bufferSize
private AbstractSftpClient
clientInstance
protected SftpClient.CloseableHandle
handle
private byte[]
handleId
private SftpMessage
lastMsg
protected org.slf4j.Logger
log
private int
nextBuffer
protected long
offset
private boolean
ownsHandle
private int
packetSize
private java.lang.String
path
protected java.util.Deque<SftpAckData>
pendingAcks
private int
sftpPreamble
private boolean
usePacket
-
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 void
checkStatus(AbstractSftpClient client, Buffer buf)
void
close()
void
flush()
private Buffer
getBuffer(Session session)
AbstractSftpClient
getClient()
java.lang.String
getPath()
The remotely accessed file pathprivate void
internalFlush()
private long
internalTransfer(SftpOutputStreamAsync.ByteInput stream, boolean forceFlush)
boolean
isOpen()
void
setOffset(long offset)
java.lang.String
toString()
long
transferFrom(java.io.InputStream stream)
long
transferFrom(java.nio.channels.ReadableByteChannel stream, long count)
void
write(byte[] b, int off, int len)
void
write(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
-AbstractSftpClient
to 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.OpenMode
s 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
-AbstractSftpClient
to 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.CloseableHandle
of 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
-AbstractSftpClient
to 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.CloseableHandle
of the remote file to write tocloseHandle
- whether to close thehandle
when this output stream is closed
-
-
Method Detail
-
getClient
public final AbstractSftpClient getClient()
- Specified by:
getClient
in 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:
isOpen
in interfacejava.nio.channels.Channel
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in 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:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-