1 package com.coldcore.coloradoftp.command.impl; 2 3 import com.coldcore.coloradoftp.command.Command; 4 import com.coldcore.coloradoftp.command.Reply; 5 6 import java.util.StringTokenizer ; 7 8 11 public class GenericReply implements Reply { 12 13 protected String code; 14 protected String text; 15 protected Command command; 16 17 18 public String getCode() { 19 return code; 20 } 21 22 23 public void setCode(String code) { 24 this.code = code; 25 } 26 27 28 public String getText() { 29 return text; 30 } 31 32 33 public void setText(String text) { 34 this.text = text; 35 } 36 37 38 public Command getCommand() { 39 return command; 40 } 41 42 43 public void setCommand(Command command) { 44 this.command = command; 45 } 46 47 48 public String prepare() { 49 if (code == null || code.trim().length() != 3) throw new IllegalArgumentException ("Invalid code"); 50 if (text == null) text = ""; 51 52 StringBuffer sb = new StringBuffer (); 53 text = text.trim(); 54 code = code.trim(); 55 56 if (text.equals("")) { 58 sb.append(code).append("\r\n"); 59 return sb.toString(); 60 } 61 62 if (text.indexOf("\r\n") == -1) { 64 sb.append(code).append(" ").append(text).append("\r\n"); 65 return sb.toString(); 66 } 67 68 sb.append(code).append("-"); 70 StringTokenizer st = new StringTokenizer (text, "\n"); 71 while (st.hasMoreTokens()) { 72 String line = st.nextToken().trim(); 73 if (!st.hasMoreTokens()) sb.append(code); 74 sb.append(" ").append(line).append("\r\n"); 75 } 76 return sb.toString(); 77 } 78 } 79 | Popular Tags |