001 /* 002 * ftp4j - A pure Java FTP client library 003 * 004 * Copyright (C) 2008-2009 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 Lesser General Public License version 008 * 2.1, as published by the Free Software Foundation. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License version 2.1 along with this program. 017 * If not, see <http://www.gnu.org/licenses/>. 018 */ 019 package it.sauronsoftware.ftp4j; 020 021 /** 022 * This class represents FTP server replies in a manageable object oriented way. 023 * 024 * @author Carlo Pelliccia 025 */ 026 public class FTPReply { 027 028 /** 029 * The reply code. 030 */ 031 private int code = 0; 032 033 /** 034 * The reply message(s). 035 */ 036 private String[] messages; 037 038 /** 039 * Build the reply. 040 * 041 * @param code 042 * The code of the reply. 043 * @param message 044 * The textual message(s) in the reply. 045 */ 046 FTPReply(int code, String[] messages) { 047 this.code = code; 048 this.messages = messages; 049 } 050 051 /** 052 * Returns the code of the reply. 053 * 054 * @return The code of the reply. 055 */ 056 public int getCode() { 057 return code; 058 } 059 060 /** 061 * Returns true if the code of the reply is in the range of success codes 062 * (2**). 063 * 064 * @return true if the code of the reply is in the range of success codes 065 * (2**). 066 */ 067 public boolean isSuccessCode() { 068 int aux = code - 200; 069 return aux >= 0 && aux < 100; 070 } 071 072 /** 073 * Returns the textual message(s) of the reply. 074 * 075 * @return The textual message(s) of the reply. 076 */ 077 public String[] getMessages() { 078 return messages; 079 } 080 081 public String toString() { 082 StringBuffer buffer = new StringBuffer(); 083 buffer.append(getClass().getName()); 084 buffer.append(" [code="); 085 buffer.append(code); 086 buffer.append(", message="); 087 for (int i = 0; i < messages.length; i++) { 088 if (i > 0) { 089 buffer.append(" "); 090 } 091 buffer.append(messages[i]); 092 } 093 buffer.append("]"); 094 return buffer.toString(); 095 } 096 097 }