Class SftpRemotePathChannel
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- java.nio.channels.FileChannel
-
- org.apache.sshd.client.subsystem.sftp.SftpRemotePathChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.GatheringByteChannel
,java.nio.channels.InterruptibleChannel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.ScatteringByteChannel
,java.nio.channels.SeekableByteChannel
,java.nio.channels.WritableByteChannel
- Direct Known Subclasses:
SftpFileSystemChannel
public class SftpRemotePathChannel extends java.nio.channels.FileChannel
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<java.lang.Thread>
blockingThreadHolder
private boolean
closeOnExit
static java.lang.String
COPY_BUFSIZE_PROP
static int
DEFAULT_TRANSFER_BUFFER_SIZE
private SftpClient.CloseableHandle
handle
private java.lang.Object
lock
private java.util.Collection<SftpClient.OpenMode>
modes
private java.lang.String
path
private java.util.concurrent.atomic.AtomicLong
posTracker
static java.util.Set<SftpClient.OpenMode>
READ_MODES
private SftpClient
sftp
static java.util.Set<SftpClient.OpenMode>
WRITE_MODES
-
Constructor Summary
Constructors Constructor Description SftpRemotePathChannel(java.lang.String path, SftpClient sftp, boolean closeOnExit, java.util.Collection<SftpClient.OpenMode> modes)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
beginBlocking()
protected long
doRead(java.util.List<java.nio.ByteBuffer> buffers, long position)
protected long
doWrite(java.util.List<java.nio.ByteBuffer> buffers, long position)
private void
endBlocking(boolean completed)
private void
ensureOpen(java.util.Collection<SftpClient.OpenMode> reqModes)
Checks that the channel is open and that its current mode contains at least one of the required onesvoid
force(boolean metaData)
java.lang.String
getRemotePath()
protected void
implCloseChannel()
java.nio.channels.FileLock
lock(long position, long size, boolean shared)
java.nio.MappedByteBuffer
map(java.nio.channels.FileChannel.MapMode mode, long position, long size)
long
position()
java.nio.channels.FileChannel
position(long newPosition)
int
read(java.nio.ByteBuffer dst)
long
read(java.nio.ByteBuffer[] dsts, int offset, int length)
int
read(java.nio.ByteBuffer dst, long position)
long
size()
java.lang.String
toString()
long
transferFrom(java.nio.channels.ReadableByteChannel src, long position, long count)
long
transferTo(long position, long count, java.nio.channels.WritableByteChannel target)
java.nio.channels.FileChannel
truncate(long size)
java.nio.channels.FileLock
tryLock(long position, long size, boolean shared)
int
write(java.nio.ByteBuffer src)
long
write(java.nio.ByteBuffer[] srcs, int offset, int length)
int
write(java.nio.ByteBuffer src, long position)
-
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
-
-
-
Field Detail
-
COPY_BUFSIZE_PROP
public static final java.lang.String COPY_BUFSIZE_PROP
- See Also:
- Constant Field Values
-
DEFAULT_TRANSFER_BUFFER_SIZE
public static final int DEFAULT_TRANSFER_BUFFER_SIZE
- See Also:
- Constant Field Values
-
READ_MODES
public static final java.util.Set<SftpClient.OpenMode> READ_MODES
-
WRITE_MODES
public static final java.util.Set<SftpClient.OpenMode> WRITE_MODES
-
path
private final java.lang.String path
-
modes
private final java.util.Collection<SftpClient.OpenMode> modes
-
closeOnExit
private final boolean closeOnExit
-
sftp
private final SftpClient sftp
-
handle
private final SftpClient.CloseableHandle handle
-
lock
private final java.lang.Object lock
-
posTracker
private final java.util.concurrent.atomic.AtomicLong posTracker
-
blockingThreadHolder
private final java.util.concurrent.atomic.AtomicReference<java.lang.Thread> blockingThreadHolder
-
-
Constructor Detail
-
SftpRemotePathChannel
public SftpRemotePathChannel(java.lang.String path, SftpClient sftp, boolean closeOnExit, java.util.Collection<SftpClient.OpenMode> modes) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getRemotePath
public java.lang.String getRemotePath()
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Specified by:
read
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
read
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst, long position) throws java.io.IOException
- Specified by:
read
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
read
public long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ScatteringByteChannel
- Specified by:
read
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
doRead
protected long doRead(java.util.List<java.nio.ByteBuffer> buffers, long position) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Specified by:
write
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src, long position) throws java.io.IOException
- Specified by:
write
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.GatheringByteChannel
- Specified by:
write
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
doWrite
protected long doWrite(java.util.List<java.nio.ByteBuffer> buffers, long position) throws java.io.IOException
- Throws:
java.io.IOException
-
position
public long position() throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
position
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
position
public java.nio.channels.FileChannel position(long newPosition) throws java.io.IOException
- Specified by:
position
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
position
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException
- Specified by:
size
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
size
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
truncate
public java.nio.channels.FileChannel truncate(long size) throws java.io.IOException
- Specified by:
truncate
in interfacejava.nio.channels.SeekableByteChannel
- Specified by:
truncate
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
force
public void force(boolean metaData) throws java.io.IOException
- Specified by:
force
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
transferTo
public long transferTo(long position, long count, java.nio.channels.WritableByteChannel target) throws java.io.IOException
- Specified by:
transferTo
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
transferFrom
public long transferFrom(java.nio.channels.ReadableByteChannel src, long position, long count) throws java.io.IOException
- Specified by:
transferFrom
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
map
public java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode mode, long position, long size) throws java.io.IOException
- Specified by:
map
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
lock
public java.nio.channels.FileLock lock(long position, long size, boolean shared) throws java.io.IOException
- Specified by:
lock
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
tryLock
public java.nio.channels.FileLock tryLock(long position, long size, boolean shared) throws java.io.IOException
- Specified by:
tryLock
in classjava.nio.channels.FileChannel
- Throws:
java.io.IOException
-
implCloseChannel
protected void implCloseChannel() throws java.io.IOException
- Specified by:
implCloseChannel
in classjava.nio.channels.spi.AbstractInterruptibleChannel
- Throws:
java.io.IOException
-
beginBlocking
private void beginBlocking()
-
endBlocking
private void endBlocking(boolean completed) throws java.nio.channels.AsynchronousCloseException
- Throws:
java.nio.channels.AsynchronousCloseException
-
ensureOpen
private void ensureOpen(java.util.Collection<SftpClient.OpenMode> reqModes) throws java.io.IOException
Checks that the channel is open and that its current mode contains at least one of the required ones- Parameters:
reqModes
- The required modes - ignored ifnull
/empty- Throws:
java.io.IOException
- If channel not open or the required modes are not satisfied
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-