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 2014/09/10 13:03:18 UTC
git commit: [SSHD-343] Return substatus int programatically in
SshException
Repository: mina-sshd
Updated Branches:
refs/heads/master 8fb0e52c5 -> 649fac4a1
[SSHD-343] Return substatus int programatically in SshException
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/649fac4a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/649fac4a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/649fac4a
Branch: refs/heads/master
Commit: 649fac4a16d40c05a97f72d291fe6585d8af8e41
Parents: 8fb0e52
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Sep 10 13:03:04 2014 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Sep 10 13:03:04 2014 +0200
----------------------------------------------------------------------
.../org/apache/sshd/client/SftpException.java | 44 ++++++++++++++++++++
.../sshd/client/sftp/DefaultSftpClient.java | 17 ++++----
2 files changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/649fac4a/sshd-core/src/main/java/org/apache/sshd/client/SftpException.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SftpException.java b/sshd-core/src/main/java/org/apache/sshd/client/SftpException.java
new file mode 100644
index 0000000..80e9064
--- /dev/null
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SftpException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.client;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class SftpException extends IOException {
+
+ private final int status;
+
+ public SftpException(int status, String msg) {
+ super(msg);
+ this.status = status;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ @Override
+ public String toString() {
+ String message = getLocalizedMessage();
+ return "SFTP error (" + status + "): " + message;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/649fac4a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
index 2f0a808..6e39489 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.sshd.ClientSession;
import org.apache.sshd.client.SftpClient;
+import org.apache.sshd.client.SftpException;
import org.apache.sshd.client.channel.ChannelSubsystem;
import org.apache.sshd.common.SshException;
import org.apache.sshd.common.util.Buffer;
@@ -277,7 +278,7 @@ public class DefaultSftpClient implements SftpClient {
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else {
throw new SshException("Unexpected SFTP packet received: " + type);
}
@@ -292,7 +293,7 @@ public class DefaultSftpClient implements SftpClient {
String msg = buffer.getString();
String lang = buffer.getString();
if (substatus != SSH_FX_OK) {
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
}
} else {
throw new SshException("Unexpected SFTP packet received: " + type);
@@ -307,7 +308,7 @@ public class DefaultSftpClient implements SftpClient {
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else if (type == SSH_FXP_HANDLE) {
String handle = buffer.getString();
return new Handle(handle);
@@ -324,7 +325,7 @@ public class DefaultSftpClient implements SftpClient {
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else if (type == SSH_FXP_ATTRS) {
return readAttributes(buffer);
} else {
@@ -340,7 +341,7 @@ public class DefaultSftpClient implements SftpClient {
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else if (type == SSH_FXP_NAME) {
int len = buffer.getInt();
if (len != 1) {
@@ -452,7 +453,7 @@ public class DefaultSftpClient implements SftpClient {
return checkData(receive(send(SSH_FXP_READ, buffer)), dstoff, dst);
}
- protected int checkData(Buffer buffer, int dstoff, byte[] dst) throws SshException {
+ protected int checkData(Buffer buffer, int dstoff, byte[] dst) throws IOException {
int len;
int length = buffer.getInt();
int type = buffer.getByte();
@@ -464,7 +465,7 @@ public class DefaultSftpClient implements SftpClient {
if (substatus == SSH_FX_EOF) {
return -1;
}
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else if (type == SSH_FXP_DATA) {
len = buffer.getInt();
buffer.getRawBytes(dst, dstoff, len);
@@ -518,7 +519,7 @@ public class DefaultSftpClient implements SftpClient {
if (substatus == SSH_FX_EOF) {
return null;
}
- throw new SshException("SFTP error (" + substatus + "): " + msg);
+ throw new SftpException(substatus, msg);
} else if (type == SSH_FXP_NAME) {
int len = buffer.getInt();
DirEntry[] entries = new DirEntry[len];