KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > SFTPException


1
2 package ch.ethz.ssh2;
3
4 import java.io.IOException JavaDoc;
5
6 import ch.ethz.ssh2.sftp.ErrorCodes;
7
8 /**
9  * Used in combination with the SFTPv3Client. This exception wraps
10  * error messages sent by the SFTP server.
11  *
12  * @author Christian Plattner, plattner@inf.ethz.ch
13  * @version $Id: SFTPException.java,v 1.6 2006/08/18 22:26:35 cplattne Exp $
14  */

15
16 public class SFTPException extends IOException JavaDoc
17 {
18     private static final long serialVersionUID = 578654644222421811L;
19
20     private final String JavaDoc sftpErrorMessage;
21     private final int sftpErrorCode;
22
23     private static String JavaDoc constructMessage(String JavaDoc s, int errorCode)
24     {
25         String JavaDoc[] detail = ErrorCodes.getDescription(errorCode);
26
27         if (detail == null)
28             return s + " (UNKNOW SFTP ERROR CODE)";
29
30         return s + " (" + detail[0] + ": " + detail[1] + ")";
31     }
32
33     SFTPException(String JavaDoc msg, int errorCode)
34     {
35         super(constructMessage(msg, errorCode));
36         sftpErrorMessage = msg;
37         sftpErrorCode = errorCode;
38     }
39
40     /**
41      * Get the error message sent by the server. Often, this
42      * message does not help a lot (e.g., "failure").
43      *
44      * @return the plain string as sent by the server.
45      */

46     public String JavaDoc getServerErrorMessage()
47     {
48         return sftpErrorMessage;
49     }
50
51     /**
52      * Get the error code sent by the server.
53      *
54      * @return an error code as defined in the SFTP specs.
55      */

56     public int getServerErrorCode()
57     {
58         return sftpErrorCode;
59     }
60
61     /**
62      * Get the symbolic name of the error code as given in the SFTP specs.
63      *
64      * @return e.g., "SSH_FX_INVALID_FILENAME".
65      */

66     public String JavaDoc getServerErrorCodeSymbol()
67     {
68         String JavaDoc[] detail = ErrorCodes.getDescription(sftpErrorCode);
69
70         if (detail == null)
71             return "UNKNOW SFTP ERROR CODE " + sftpErrorCode;
72
73         return detail[0];
74     }
75
76     /**
77      * Get the description of the error code as given in the SFTP specs.
78      *
79      * @return e.g., "The filename is not valid."
80      */

81     public String JavaDoc getServerErrorCodeVerbose()
82     {
83         String JavaDoc[] detail = ErrorCodes.getDescription(sftpErrorCode);
84
85         if (detail == null)
86             return "The error code " + sftpErrorCode + " is unknown.";
87
88         return detail[1];
89     }
90 }
91
Popular Tags