| | |
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.net.InetAddress;
|
| | | import java.net.URL;
|
| | | import java.net.URLConnection;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | |
| | | private int port = 21;
|
| | | private String path = "/";
|
| | |
|
| | | private String urlStr = "http://www.7drlb.com/apps/Version.xml";
|
| | |
|
| | | @RequestMapping(value = "/upgrade", method = RequestMethod.GET)
|
| | | public Version index() {
|
| | | Version version = new Version();
|
| | | FTPClient ftpClient = new FTPClient();
|
| | | // FTPClient ftpClient = new FTPClient();
|
| | | try {
|
| | | ftpClient.connect(ip, port);
|
| | | ftpClient.login(userName, userPwd);
|
| | | ftpClient.changeWorkingDirectory(path);
|
| | | //ftpClient.enterRemotePassiveMode();
|
| | | ftpClient.enterLocalPassiveMode();
|
| | | InputStream ins = ftpClient.retrieveFileStream(fileName);
|
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(ins,"utf-8"));
|
| | | // ftpClient.connect(ip, port);
|
| | | // ftpClient.login(userName, userPwd);
|
| | | // ftpClient.changeWorkingDirectory(path);
|
| | | // //ftpClient.enterRemotePassiveMode();
|
| | | // //ftpClient.enterLocalPassiveMode();
|
| | | // ftpClient.enterLocalActiveMode();
|
| | | // //ftpClient.enterRemoteActiveMode(InetAddress.getByName(ip), port);
|
| | | //
|
| | | // InputStream ins = ftpClient.retrieveFileStream(fileName);
|
| | | // BufferedReader reader = new BufferedReader(new InputStreamReader(ins,"utf-8"));
|
| | | // String line;
|
| | | // StringBuilder builder = new StringBuilder();
|
| | | // while ((line = reader.readLine()) != null) {
|
| | | // builder.append(line);
|
| | | // }
|
| | | // reader.close();
|
| | | // if (ins != null) {
|
| | | // ins.close();
|
| | | // }
|
| | | // ftpClient.getReply();
|
| | | // String content = builder.toString();
|
| | | // if(ftpClient.isConnected()) {
|
| | | // ftpClient.logout();
|
| | | // ftpClient.disconnect();
|
| | | // }
|
| | |
|
| | | URL realUrl = new URL(urlStr);
|
| | | URLConnection connection = realUrl.openConnection();
|
| | | connection.connect();
|
| | | StringBuffer result = new StringBuffer();
|
| | | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
| | | String line;
|
| | | StringBuilder builder = new StringBuilder();
|
| | | while ((line = reader.readLine()) != null) {
|
| | | builder.append(line);
|
| | | while ((line = in.readLine()) != null) {
|
| | | result.append(line);
|
| | | }
|
| | | reader.close();
|
| | | if (ins != null) {
|
| | | ins.close();
|
| | | }
|
| | | ftpClient.getReply();
|
| | | String content = builder.toString();
|
| | | if(ftpClient.isConnected()) {
|
| | | ftpClient.logout();
|
| | | ftpClient.disconnect();
|
| | | }
|
| | | String content = result.toString();
|
| | |
|
| | | SAXReader saxReader = new SAXReader();
|
| | | Document document = saxReader.read(new InputSource(new ByteArrayInputStream(content.getBytes("utf-8"))));
|
| | | Element root = document.getRootElement();
|
| | |
| | | }
|
| | | return version;
|
| | | }
|
| | |
|
| | | public static void main(String[] args) {
|
| | | ScreenController sc = new ScreenController();
|
| | | Version a = sc.index();
|
| | | System.out.println(a.getVer());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 地图接口
|
| | | * 开始
|