001 /* 002 * ftp4j - A pure Java FTP client library 003 * 004 * Copyright (C) 2008 Carlo Pelliccia (www.sauronsoftware.it) 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 package it.sauronsoftware.ftp4j; 020 021 022 /** 023 * This class helps in represent FTP error codes and messages. 024 * 025 * @author Carlo Pelliccia 026 */ 027 public class FTPException extends Exception { 028 029 private static final long serialVersionUID = 1L; 030 031 private int code; 032 033 private String message; 034 035 public FTPException(int code) { 036 this.code = code; 037 } 038 039 public FTPException(int code, String message) { 040 this.code = code; 041 this.message = message; 042 } 043 044 public FTPException(FTPReply reply) { 045 StringBuffer message = new StringBuffer(); 046 String[] lines = reply.getMessages(); 047 for (int i = 0; i < lines.length; i++) { 048 if (i > 0) { 049 message.append(System.getProperty("line.separator")); 050 } 051 message.append(lines[i]); 052 } 053 this.code = reply.getCode(); 054 this.message = message.toString(); 055 } 056 057 /** 058 * Returns the code of the occurred FTP error. 059 * 060 * @return The code of the occurred FTP error. 061 */ 062 public int getCode() { 063 return code; 064 } 065 066 /** 067 * Returns the message of the occurred FTP error. 068 * 069 * @return The message of the occurred FTP error. 070 */ 071 public String getMessage() { 072 return message; 073 } 074 075 public String toString() { 076 return getClass().getName() + " [code=" + code + ", message= " 077 + message + "]"; 078 } 079 080 }