language: Java (sun-jdk-1.7.0_10)
date: 190 days 14 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
 
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
 
import org.w3c.dom.Document;
 
 
public class updater {
    public static void main(String[] args) throws IOException {
                try{
                        DefaultHttpClient httpclient = ClientMaker();
                        HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
                        HttpResponse response = httpclient.execute(get);
                        InputStream in = response.getEntity().getContent();
 
                        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
                        DocumentBuilder builder = domFactory.newDocumentBuilder();
                        Document doc = builder.parse(in);
 
                        //Parse the Xml.
                        XPathFactory factory = XPathFactory.newInstance();
                        XPath xpath = factory.newXPath();
                        XPathExpression expr = xpath.compile("//version/number/text()");
                        String result = (String) expr.evaluate(doc, XPathConstants.STRING);
                        System.out.println(result);
 
                        File f = new File("C:\\Users\\Damien\\Documents\\Eclipse\\MyOutput\\bin\\Version.xml");
                        in = new FileInputStream(f) ;
                        doc = builder.parse(in);
                        expr=xpath.compile("//version/number/text()");
                        String result2 = (String) expr.evaluate(doc, XPathConstants.STRING);
                        System.out.println(result2);
 
 
                        if(Integer.parseInt(result) < Integer.parseInt(result2)){
                                HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar"); 
                                HttpResponse response2 = httpclient.execute(get2);
                                InputStream in2 = response2.getEntity().getContent();
                                File f2 = new File("C:\\Users\\Damien\\Documents\\Eclipse\\path\\to\\MyJar.jar");
                                OutputStream fos = new FileOutputStream(f2);
                                byte buf[] = new byte[1024];
                                int len;
                                while ((len = in2.read(buf)) > 0) {
                                        fos.write(buf, 0, len);
                                }
                                fos.close();
                                in.close();
                        }
                        Process p = Runtime.getRuntime().exec("cmd.exe /C  javaw -jar C:\\Users\\Damien\\Documents\\Eclipse\\path\\to\\MyJar.jar");
                        p.waitFor();
                        p.destroy();
                }catch(Exception e){ e.printStackTrace(); }
 
 
        }
 
        public static DefaultHttpClient ClientMaker() {
                int connectiontimeout = 30000; // 1 second int sockettimeout = 1000;
                HttpParams httpparameters = new BasicHttpParams();
                HttpConnectionParams.setConnectionTimeout(httpparameters,
                                connectiontimeout);
                HttpConnectionParams.setSoTimeout(httpparameters, connectiontimeout);
                DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
                return httpclient;
        }
 
}
 
Main.java:25: class updater is public, should be declared in a file named updater.java
public class updater {
       ^
Main.java:15: package org.apache.http does not exist
import org.apache.http.HttpResponse;
                      ^
Main.java:16: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpGet;
                                     ^
Main.java:17: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
                                  ^
Main.java:18: package org.apache.http.params does not exist
import org.apache.http.params.BasicHttpParams;
                             ^
Main.java:19: package org.apache.http.params does not exist
import org.apache.http.params.HttpConnectionParams;
                             ^
Main.java:20: package org.apache.http.params does not exist
import org.apache.http.params.HttpParams;
                             ^
Main.java:74: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
	public static DefaultHttpClient ClientMaker() {
	              ^
Main.java:28: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
			DefaultHttpClient httpclient = ClientMaker();
			^
Main.java:29: cannot find symbol
symbol  : class HttpGet
location: class updater
			HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
			^
Main.java:29: cannot find symbol
symbol  : class HttpGet
location: class updater
			HttpGet get = new HttpGet("http://www.myserver.com/path/to/Version.xml");
			                  ^
Main.java:30: cannot find symbol
symbol  : class HttpResponse
location: class updater
			HttpResponse response = httpclient.execute(get);
			^
Main.java:53: cannot find symbol
symbol  : class HttpGet
location: class updater
				HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar"); 
				^
Main.java:53: cannot find symbol
symbol  : class HttpGet
location: class updater
				HttpGet get2 = new HttpGet("http://www.myserver.com/path/to/MyJar.jar"); 
				                   ^
Main.java:54: cannot find symbol
symbol  : class HttpResponse
location: class updater
				HttpResponse response2 = httpclient.execute(get2);
				^
Main.java:76: cannot find symbol
symbol  : class HttpParams
location: class updater
		HttpParams httpparameters = new BasicHttpParams();
		^
Main.java:76: cannot find symbol
symbol  : class BasicHttpParams
location: class updater
		HttpParams httpparameters = new BasicHttpParams();
		                                ^
Main.java:77: cannot find symbol
symbol  : variable HttpConnectionParams
location: class updater
		HttpConnectionParams.setConnectionTimeout(httpparameters,
		^
Main.java:79: cannot find symbol
symbol  : variable HttpConnectionParams
location: class updater
		HttpConnectionParams.setSoTimeout(httpparameters, connectiontimeout);
		^
Main.java:80: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
		DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
		^
Main.java:80: cannot find symbol
symbol  : class DefaultHttpClient
location: class updater
		DefaultHttpClient httpclient = new DefaultHttpClient(httpparameters);
		                                   ^
21 errors