Top Description Inners Fields Constructors Methods
org.apache.sshd.sftp.client.impl

public Class SftpOutputStreamAsync

extends OutputStreamWithChannel
implements SftpClientHolder
Class Inheritance
All Implemented Interfaces
org.apache.sshd.sftp.client.SftpClientHolder
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, java.nio.ByteBuffer, java.nio.channels.ReadableByteChannel, java.time.Duration, java.util.Collection, .Deque, .LinkedList, .Objects, org.apache.sshd.common.SshConstants, org.apache.sshd.common.session.Session, org.apache.sshd.common.session.helpers.PacketBuffer, org.apache.sshd.common.util.GenericUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .ByteArrayBuffer, org.apache.sshd.common.util.io.output.OutputStreamWithChannel, org.apache.sshd.core.CoreModuleProperties, org.apache.sshd.sftp.client.SftpClient, .SftpClient.CloseableHandle, .SftpClient.OpenMode, .SftpClientHolder, .SftpMessage, org.apache.sshd.sftp.common.SftpConstants, .SftpException, org.slf4j.Logger, .LoggerFactory

Implements an output stream for a given remote file
Author
Apache MINA SSHD Project

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class

Field Summary

Modifier and TypeField and Description
protected final byte[]
protected Buffer
private final Buffer[]
protected final int
private final AbstractSftpClient
protected SftpClient.CloseableHandle
private final byte[]
private SftpMessage
protected final Logger
private int
protected long
private final boolean
private final int
private final String
protected final Deque<SftpAckData>
private final int
private final boolean

Constructor Summary

AccessConstructor and Description
public
SftpOutputStreamAsync(AbstractSftpClient
AbstractSftpClient to use for writing data
client
,
int
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.
bufferSize
,
String
remote path to write to
path
,
Collection<SftpClient.OpenMode>
OpenModes for opening the file.
mode
)

Creates a new stream to write data to a remote file.

public
SftpOutputStreamAsync(AbstractSftpClient
AbstractSftpClient to use for writing data
client
,
int
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.
bufferSize
,
String path, SftpClient.CloseableHandle
CloseableHandle of the remote file to write to; will be closed when this output stream is closed
handle
)

Creates a new stream to write data to a remote file.

public
SftpOutputStreamAsync(AbstractSftpClient
AbstractSftpClient to use for writing data
client
,
int
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.
bufferSize
,
String path, SftpClient.CloseableHandle
CloseableHandle of the remote file to write to
handle
,
boolean
whether to close the handle when this output stream is closed
closeHandle
)

Creates a new stream to write data to a remote file.

Method Summary

Modifier and TypeMethod and Description
private void
public void
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

private Buffer
getBuffer(Session session)

public final AbstractSftpClient
public final String

Returns:

Remote file path
getPath
()

The remotely accessed file path

private void
private long
internalTransfer(SftpOutputStreamAsync.ByteInput stream, boolean forceFlush)

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

public void
setOffset(long offset)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public long
public long
transferFrom(ReadableByteChannel stream, long count)

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Field Detail

bbback to summary
protected final byte[] bb
bufferback to summary
protected Buffer buffer
bufferPoolback to summary
private final Buffer[] bufferPool
bufferSizeback to summary
protected final int bufferSize
clientInstanceback to summary
private final AbstractSftpClient clientInstance
handleback to summary
protected SftpClient.CloseableHandle handle
handleIdback to summary
private final byte[] handleId
lastMsgback to summary
private SftpMessage lastMsg
logback to summary
protected final Logger log
nextBufferback to summary
private int nextBuffer
offsetback to summary
protected long offset
ownsHandleback to summary
private final boolean ownsHandle
packetSizeback to summary
private final int packetSize
pathback to summary
private final String path
pendingAcksback to summary
protected final Deque<SftpAckData> pendingAcks
sftpPreambleback to summary
private final int sftpPreamble
usePacketback to summary
private final boolean usePacket

Constructor Detail

SftpOutputStreamAsyncback to summary
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, String path, Collection<SftpClient.OpenMode> mode) throws IOException

Creates a new stream to write data to a remote file.

Parameters
client:AbstractSftpClient

AbstractSftpClient to use for writing data

bufferSize:int

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:String

remote path to write to

mode:Collection<SftpClient.OpenMode>

OpenModes for opening the file.

Exceptions
IOException:
if the remote file cannot be opened
SftpOutputStreamAsyncback to summary
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, String path, SftpClient.CloseableHandle handle)

Creates a new stream to write data to a remote file.

Parameters
client:AbstractSftpClient

AbstractSftpClient to use for writing data

bufferSize:int

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

CloseableHandle of the remote file to write to; will be closed when this output stream is closed

SftpOutputStreamAsyncback to summary
public SftpOutputStreamAsync(AbstractSftpClient client, int bufferSize, String path, SftpClient.CloseableHandle handle, boolean closeHandle)

Creates a new stream to write data to a remote file.

Parameters
client:AbstractSftpClient

AbstractSftpClient to use for writing data

bufferSize:int

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

CloseableHandle of the remote file to write to

closeHandle:boolean

whether to close the handle when this output stream is closed

Method Detail

checkStatusback to summary
private void checkStatus(AbstractSftpClient client, Buffer buf) throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.nio.channels.Channel.close, java.io.Closeable.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getBufferback to summary
private Buffer getBuffer(Session session)
getClientback to summary
public final AbstractSftpClient getClient()

Implements org.apache.sshd.sftp.client.SftpClientHolder.getClient.

Annotations
@Override
getPathback to summary
public final String getPath()

The remotely accessed file path

Returns:String

Remote file path

internalFlushback to summary
private void internalFlush() throws IOException
internalTransferback to summary
private long internalTransfer(SftpOutputStreamAsync.ByteInput stream, boolean forceFlush) throws IOException
isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
setOffsetback to summary
public void setOffset(long offset)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
transferFromback to summary
public long transferFrom(InputStream stream) throws IOException
transferFromback to summary
public long transferFrom(ReadableByteChannel stream, long count) throws IOException
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.apache.sshd.sftp.client.impl back to summary

private Interface SftpOutputStreamAsync.ByteInput

Known Direct Implementers
org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync.ChannelReader
Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public int
read(byte[] buffer, int offset, int length)

Method Detail

readback to summary
public int read(byte[] buffer, int offset, int length) throws IOException
org.apache.sshd.sftp.client.impl back to summary

private Class SftpOutputStreamAsync.ChannelReader

extends Object
implements ByteInput
Class Inheritance
  • java.lang.Object
  • org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync.ChannelReader
All Implemented Interfaces
org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync.ByteInput

Field Summary

Modifier and TypeField and Description
private final ReadableByteChannel
private long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
read(byte[] buffer, int offset, int length)

Implements org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync.ByteInput.read.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

srcback to summary
private final ReadableByteChannel src
stillToReadback to summary
private long stillToRead

Constructor Detail

ChannelReaderback to summary
pack-priv ChannelReader(ReadableByteChannel src, long toRead)

Method Detail

readback to summary
public int read(byte[] buffer, int offset, int length) throws IOException

Implements org.apache.sshd.sftp.client.impl.SftpOutputStreamAsync.ByteInput.read.

Annotations
@Override