You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2015/02/23 16:30:16 UTC
[15/15] mina-sshd git commit: [SSHD-410] Do not seek on files when
unnecessary
[SSHD-410] Do not seek on files when unnecessary
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/55d45e95
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/55d45e95
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/55d45e95
Branch: refs/heads/master
Commit: 55d45e955f23ecfbb2382713cd77a04734c8785f
Parents: 90414db
Author: Guillaume Nodet <gn...@apache.org>
Authored: Sun Feb 22 23:56:22 2015 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon Feb 23 16:21:30 2015 +0100
----------------------------------------------------------------------
.../apache/sshd/server/sftp/SftpSubsystem.java | 27 +++++++++++++++++---
1 file changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/55d45e95/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
index f515445..28fba31 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java
@@ -448,6 +448,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
protected class FileHandle extends Handle {
final FileChannel channel;
+ long pos;
final List<FileLock> locks = new ArrayList<>();
public FileHandle(Path file, int flags, int access, Map<String, Object> attrs) throws IOException {
@@ -504,16 +505,34 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste
setAttributes(file, attrs);
}
this.channel = channel;
+ this.pos = 0;
}
public int read(byte[] data, long offset) throws IOException {
- channel.position(offset);
- return channel.read(ByteBuffer.wrap(data));
+ return read(data, 0, data.length, offset);
+ }
+
+ public int read(byte[] data, int doff, int length, long offset) throws IOException {
+ if (pos != offset) {
+ channel.position(offset);
+ pos = offset;
+ }
+ int read = channel.read(ByteBuffer.wrap(data, doff, length));
+ pos += read;
+ return read;
}
public void write(byte[] data, long offset) throws IOException {
- channel.position(offset);
- channel.write(ByteBuffer.wrap(data));
+ write(data, 0, data.length, offset);
+ }
+
+ public void write(byte[] data, int doff, int length, long offset) throws IOException {
+ if (pos != offset) {
+ channel.position(offset);
+ pos = offset;
+ }
+ channel.write(ByteBuffer.wrap(data, doff, length));
+ pos += length;
}
@Override