|
|
|
Java - รบกวนช่วยอธิบายโค้ด Java หน่อยคะ และตีความให้เป็น Flowchart |
|
|
|
|
|
|
|
รบกวนช่วยอธิบายโค้ด java หน่อยคะ พอดีจะทำความเข้าใจเพื่อตีความออกมาในรูปแบบ Flowchart คะ
Code (Java)
package th.co.vlink.tg.csv;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import au.com.bytecode.opencsv.CSVReader;
public class CrewCSVManager {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss", Locale.US);
public Map getCrewMap(String server,String username,String password,String filePath){
Map users= new HashMap<String, String>();
FTPClient ftp = new FTPClient();
try {
//ftp.connect("57.59.2.187");
ftp.connect(server);
//if (!ftp.login("patcels", "P@tcEl$5"))
if (!ftp.login(username,password))
{
ftp.logout();
}
ftp.setFileType(FTP.BINARY_FILE_TYPE);
FTPFile[] files = ftp.listFiles(filePath);
String filenameMax="";
Date timesMax=null;
boolean haveFiles=false;
boolean firstTime=false;
if(files!=null && files.length>0){
int size=files.length;
Date[] times=new Date[size];
String[] name=new String[size];
for (int i = 0; i < size; i++) {
FTPFile file =files[i];
times[i]=file.getTimestamp().getTime();
name[i]=file.getName();
if(name[i].indexOf(".csv")!=-1){
String[] filename=name[i].split(".csv");
Date d=null;
try {
d=dateFormat.parse(filename[0]);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!firstTime){
timesMax=d;// times[i];
filenameMax=name[i];
firstTime=true;
}else{
if(d.after(timesMax)){
timesMax=d;
filenameMax=name[i];
}
}
}
}
haveFiles=true;
}
if(haveFiles && filenameMax!=null && filenameMax.length()>0){
CSVReader reader=null;
InputStreamReader inReader=new InputStreamReader(ftp.retrieveFileStream(filePath+filenameMax));
try {
//reader= new CSVReader(new FileReader(filePath), '|');
reader= new CSVReader(inReader, ',');
String [] nextLine;
try {
while ((nextLine = reader.readNext()) != null) {
String staffNum=nextLine[0];;//STAFF_NUM
if(staffNum!=null && staffNum.length()<7){
int offset=5-staffNum.length();
String offset0="";
for (int i = 0; i < offset; i++) {
offset0=offset0+"0";
}
staffNum="TG"+offset0+staffNum; // uid
}
String crewPosFly=nextLine[4];;//CREW_POS_FLY //job_type
users.put(staffNum, crewPosFly);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}finally{
if(inReader!=null){
inReader.close();
}
if(reader!=null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ftp.noop(); // check that control connection is working OK
ftp.logout();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally
{
if (ftp.isConnected())
{
try
{
ftp.disconnect();
}
catch (IOException f)
{
// do nothing
}
}
}
return users;
}
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
/* PaeManager a = new PaeManager();
a.getPaeMap("/tmp/test.csv");
*/
long end = System.currentTimeMillis();
System.out.println("uses time="+((end-start)/1000d));
}
}
Tag : Java, WebService, JAVA
|
|
|
|
|
|
Date :
2013-10-09 11:33:49 |
By :
stockseii |
View :
1441 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เยอะน่ะครับ ที่สำคัญมันจะต้องรันให้ได้ก่อนครับ
|
|
|
|
|
Date :
2013-10-09 11:46:05 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code มันเยอะน่ะครับ ไล่ยากหน่อยว่ามันทำอะไรไปบ้าง
|
|
|
|
|
Date :
2013-10-09 13:10:00 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|