View Javadoc

1   // ServerResponseException.java
2   // $Id: ServerResponseException.java,v 1.3 2006/02/20 04:52:11 sjardine Exp $
3   //
4   // Copyright 1997, Joe Phillips <jaiger@innovationsw.com>
5   // Copyright 2001, 2002 Innovation Software Group, LLC - http://www.innovationsw.com
6   //
7   // This library is free software; you can redistribute it and/or
8   // modify it under the terms of the GNU Library General Public
9   // License as published by the Free Software Foundation; either
10  // version 2 of the License, or (at your option) any later version.
11  //
12  // This library is distributed in the hope that it will be useful,
13  // but WITHOUT ANY WARRANTY; without even the implied warranty of
14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  // Library General Public License for more details.
16  //
17  // You should have received a copy of the GNU Library General Public
18  // License along with this library; if not, write to the Free
19  // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  //
21  package gnu.inet.ftp;
22  
23  public class ServerResponseException extends Exception {
24      private long code;
25      private String message;
26  
27      /***
28       * basic constructor. creates a new ServerResponseException given the server
29       * error message. The input string must be in the format of 3 digits, a
30       * space and the error message. This is the default format of the server
31       * responses.
32       * 
33       * @param str
34       *                the server error message in the form
35       */
36      public ServerResponseException(java.lang.String str) {
37  	code = -1; // not set yet
38  	message = str;
39      }
40  
41      /***
42       * get the server response code.
43       * 
44       * @exception NumberFormatException
45       *                    the first 3 characters of the message are <i>not</i>
46       *                    a number as they should be in a normal server response
47       * @return server response code as long value
48       */
49      public long getCode() throws NumberFormatException {
50  	code = Integer.parseInt(message.substring(0, 3));
51  	return code;
52      }
53  
54      /***
55       * get the server message.
56       * 
57       * @return the full server response message string
58       */
59      public String getMessage() {
60  	return message;
61      }
62  
63      /***
64       * get a string representing this ServerResponseException
65       * 
66       * @return this ServerResponseException as a String
67       */
68      public String toString() {
69  	return message;
70      }
71  
72  }
73  
74  // ServerResponseException.java