import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.SimpleFormatter;
import zextend.*;
public class zftpd {
private static String zftpdir = "/var/ftp/";
private static String FTPUSER;
private static String FTPPASS;
public static void main(String[] args) throws Exception{
Startup();
}
public static boolean checklogin(String u,String p) throws Exception{
boolean isUserCorrect = mconnect.selectuser(u);
boolean isUserAvailable = mconnect.GetAvailable(u);
boolean Result = false;
String CorrectPass = mconnect.getpass(u);
String CurrentPass = encrypted.run(p);
if(isUserCorrect = false || CurrentPass != CorrectPass) {
Result = false;
} else if (isUserCorrect = true && CurrentPass == CorrectPass) {
Result = true;
}
return Result;
}
public static void Startup() throws Exception{
System.out.println("---- Welcome to ZFtpServer ----");
Thread.sleep(1000);
System.out.println("---- We are Start Now. ----");
ServerSocket server = new ServerSocket(110);
List<String> get = new LinkedList<>();
Thread zinput = new Thread(
new Runnable() {
public void run() {
while(true) {
try {
Socket s = server.accept();
InputStream input = s.getInputStream();
InputStreamReader ir = new InputStreamReader(input);
BufferedReader br = new BufferedReader(ir);
String Recvstring;
List<String> receive = new LinkedList<>();
while((Recvstring = br.readLine()) != null) {
receive.add(Recvstring);
get.addAll(receive);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
);
Thread zoutput = new Thread(
new Runnable() {
public void run() {
try {
Socket s = server.accept();
OutputStream output = s.getOutputStream();
String i = Collections.min(get);
int mindex = get.indexOf(i);
FTPUSER = get.get(mindex);
FTPPASS = get.get(mindex+1);
boolean lo = checklogin(FTPUSER, FTPPASS);
if(lo = true) {
String r = "true";
output.write(r.getBytes());
output.flush();
} else {
String r = "false";
output.write(r.getBytes());
output.flush();
}
while(true) {
for(int t = 2;t < get.size();t++) {
String comman = get.get(t);
String Re;
byte[] r = new byte[8192];
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
);
}
public class operate {
public static void ls() {
File in = new File(zftpdir);
File[] files = in.listFiles();
int fnumber = 0;
System.out.println("----DirName: " + zftpdir);
if(files != null) {
for(File f : files) {
if(f.isFile()) {
System.out.print("FileName: " + f.getName());
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.print(" CreateTime: " + sf.format(f.lastModified()));
long fsize = f.length();
System.out.println(" File Size: " + fsize);
fnumber++;
} else if(f.isDirectory()) {
System.out.print("Dir: " + f.getName());
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.print(" CreateTime: " + sd.format(f.lastModified()));
System.out.println(" Dir Size: " + f.length());
fnumber++;
}
}
}
System.out.println("----The Directory files number: " + fnumber);
}
public void createfile(String s,int mode) {
String newfile = zftpdir + s;
File w = new File(newfile);
if(w.exists()) {
System.out.println("----File is exists.");
} else {
try {
w.createNewFile();
if(mode == 777) {
w.setReadable(true);
w.setWritable(true);
} else if(mode == 755) {
w.setReadOnly();
}
System.out.println("----File Create Successfully.");
} catch(Exception e) {
e.printStackTrace();
System.out.println("---File Create Failed!!!");
}
}
}
public String GetFile(String s) {
String nameget = zftpdir + s;
String Re = null;
try {
BufferedReader b = new BufferedReader(new FileReader(nameget));
String str;
while((str = b.readLine()) != null) {
Re = str;
}
} catch (IOException e) {
e.printStackTrace();
}
return Re;
}
public void PutFile(String name,byte[] f) {
try {
File n = new File(zftpdir + name);
FileOutputStream fout = new FileOutputStream(name);
if(n.exists()) {
System.out.println("File is exists.");
} else {
n.createNewFile();
fout.write(f);
fout.flush();
}
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
各位博主,请问怎么修改以上代码可以把服务端上函数式接口的执行结果返回给客户端?