0
|
1 package net.sourceforge.jsocks;
|
|
2
|
|
3 /**
|
|
4 Exception thrown by various socks classes to indicate errors
|
|
5 with protocol or unsuccessful server responses.
|
|
6 */
|
|
7 public class SocksException extends java.io.IOException {
|
|
8 private static final long serialVersionUID = 6141184566248512277L;
|
|
9
|
|
10 /**
|
|
11 Construct a SocksException with given error code.
|
|
12 <p>
|
|
13 Tries to look up message which corresponds to this error code.
|
|
14 @param errCode Error code for this exception.
|
|
15 */
|
|
16 public SocksException(int errCode) {
|
|
17 this.errCode = errCode;
|
|
18
|
|
19 if ((errCode >> 16) == 0) {
|
|
20 //Server reply error message
|
|
21 errString = errCode <= serverReplyMessage.length ?
|
|
22 serverReplyMessage[errCode] :
|
|
23 UNASSIGNED_ERROR_MESSAGE;
|
|
24 }
|
|
25 else {
|
|
26 //Local error
|
|
27 errCode = (errCode >> 16) - 1;
|
|
28 errString = errCode <= localErrorMessage.length ?
|
|
29 localErrorMessage[errCode] :
|
|
30 UNASSIGNED_ERROR_MESSAGE;
|
|
31 }
|
|
32 }
|
|
33 /**
|
|
34 Constructs a SocksException with given error code and message.
|
|
35 @param errCode Error code.
|
|
36 @param errString Error Message.
|
|
37 */
|
|
38 public SocksException(int errCode, String errString) {
|
|
39 this.errCode = errCode;
|
|
40 this.errString = errString;
|
|
41 }
|
|
42 /**
|
|
43 Get the error code associated with this exception.
|
|
44 @return Error code associated with this exception.
|
|
45 */
|
|
46 public int getErrorCode() {
|
|
47 return errCode;
|
|
48 }
|
|
49 /**
|
|
50 Get human readable representation of this exception.
|
|
51 @return String represntation of this exception.
|
|
52 */
|
|
53 public String toString() {
|
|
54 return errString;
|
|
55 }
|
|
56
|
|
57 static final String UNASSIGNED_ERROR_MESSAGE =
|
|
58 "Unknown error message";
|
|
59 static final String serverReplyMessage[] = {
|
|
60 "Succeeded",
|
|
61 "General SOCKS server failure",
|
|
62 "Connection not allowed by ruleset",
|
|
63 "Network unreachable",
|
|
64 "Host unreachable",
|
|
65 "Connection refused",
|
|
66 "TTL expired",
|
|
67 "Command not supported",
|
|
68 "Address type not supported"
|
|
69 };
|
|
70
|
|
71 static final String localErrorMessage[] = {
|
|
72 "SOCKS server not specified",
|
|
73 "Unable to contact SOCKS server",
|
|
74 "IO error",
|
|
75 "None of Authentication methods are supported",
|
|
76 "Authentication failed",
|
|
77 "General SOCKS fault"
|
|
78 };
|
|
79
|
|
80 String errString;
|
|
81 public int errCode;
|
|
82
|
|
83 }//End of SocksException class
|
|
84
|