comparison app/src/main/java/ch/ethz/ssh2/SFTPException.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/ch/ethz/ssh2/SFTPException.java@071eccdff8ea
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please see the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2;
6
7 import java.io.IOException;
8
9 import ch.ethz.ssh2.sftp.ErrorCodes;
10
11 /**
12 * Used in combination with the SFTPv3Client. This exception wraps
13 * error messages sent by the SFTP server.
14 *
15 * @author Christian Plattner
16 * @version 2.50, 03/15/10
17 */
18
19 public class SFTPException extends IOException {
20 private static final long serialVersionUID = 578654644222421811L;
21
22 private final String sftpErrorMessage;
23 private final int sftpErrorCode;
24
25 private static String constructMessage(String s, int errorCode) {
26 String[] detail = ErrorCodes.getDescription(errorCode);
27
28 if (detail == null)
29 return s + " (UNKNOWN SFTP ERROR CODE)";
30
31 return s + " (" + detail[0] + ": " + detail[1] + ")";
32 }
33
34 SFTPException(String msg, int errorCode) {
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 getServerErrorMessage() {
47 return sftpErrorMessage;
48 }
49
50 /**
51 * Get the error code sent by the server.
52 *
53 * @return an error code as defined in the SFTP specs.
54 */
55 public int getServerErrorCode() {
56 return sftpErrorCode;
57 }
58
59 /**
60 * Get the symbolic name of the error code as given in the SFTP specs.
61 *
62 * @return e.g., "SSH_FX_INVALID_FILENAME".
63 */
64 public String getServerErrorCodeSymbol() {
65 String[] detail = ErrorCodes.getDescription(sftpErrorCode);
66
67 if (detail == null)
68 return "UNKNOWN SFTP ERROR CODE " + sftpErrorCode;
69
70 return detail[0];
71 }
72
73 /**
74 * Get the description of the error code as given in the SFTP specs.
75 *
76 * @return e.g., "The filename is not valid."
77 */
78 public String getServerErrorCodeVerbose() {
79 String[] detail = ErrorCodes.getDescription(sftpErrorCode);
80
81 if (detail == null)
82 return "The error code " + sftpErrorCode + " is unknown.";
83
84 return detail[1];
85 }
86 }