/*
*这是我的大四的课程设计
*实现了支持PORT方式的FTP客户端 实现了LOGIN CD PWD PUT GET LIST/DIR等基本功能
*本程序一共有两个类 一个是客户端命令和功能函数的映射类 ParseTableEntry
* 一个是客户端运行程序 SFtpClient
*
*这个类全部摘抄自JAVA2 网络协议内幕
*
*参考资料: JAVA2 网络协议内幕 AL Williams著
* JAVA Online Document
* Thinking in JAVA I/O 部分(wolf的书..hoho)
*
*任何BUG发现或者指教请在BBS与Cyrus联系
*/
import java.lang.reflect.*;
import java.util.StringTokenizer;
public class ParseTableEntry
{
private String word;
private Method func;
public static boolean parse(ParseTableEntry [] parseTable,Object othis,String word,String line,StringTokenizer token)
{
for (int i=0;i {
if(parseTable[i].equals(word)||parseTable[i].equals(""))
{
return parseTable[i].call(othis,line,token);
}
}
return false;
}
public ParseTableEntry(String word,Class c,String methd)
{
Class [] cary = new Class[2];
this.word = word;
cary[0] = String.class;
cary[1] = StringTokenizer.class;
try
{
func = c.getMethod(methd,cary);
}
catch (Exception e)
{
System.err.println("ParseTable: "+e);
}
}
public boolean equals(String s){ return word.compareToIgnoreCase(s)==0; }
public boolean call(Object thisptr,String line,StringTokenizer token)
{
Object arg[] = new Object[2];
arg[0] = (Object)line;
arg[1] = (Object)token;
try
{
Boolean bv;
bv = (Boolean)func.invoke(thisptr,arg);
return bv.booleanValue();
}
catch (Exception e)
{
System.err.println("Invoke: "+e);
}
return false;
}
};