X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=trunk%2Fcrawler%2Fbasic%2Ftest%2Forg%2Fwamblee%2Fcrawler%2FMain.java;fp=trunk%2Fcrawler%2Fbasic%2Fsrc%2FMain.java;h=6d157d51157661bcd22445d35ff8b3bc059dc6bb;hb=8470878078393cdd8bbf85c2b87910e3ab97cbd1;hp=8287a6ecaed381a6ce0558b79618dbc377ae0f49;hpb=28051fec9226f12d62e2d95a1e42bf32e7679545;p=utils diff --git a/trunk/crawler/basic/src/Main.java b/trunk/crawler/basic/test/org/wamblee/crawler/Main.java similarity index 82% rename from trunk/crawler/basic/src/Main.java rename to trunk/crawler/basic/test/org/wamblee/crawler/Main.java index 8287a6ec..6d157d51 100644 --- a/trunk/crawler/basic/src/Main.java +++ b/trunk/crawler/basic/test/org/wamblee/crawler/Main.java @@ -1,3 +1,4 @@ +package org.wamblee.crawler; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -33,18 +34,36 @@ import org.w3c.tidy.Tidy; /** * */ -public class Main { +public final class Main { + + /** + * + */ + private static final int PROXY_PORT = 10000; + + /** + * + */ + private static final int MAX_REDIRECTS = 10; + + /** + * Disabled constructor. + * + */ + private Main() { + // Empty + } private static final String BASE = "http://epg.kml.kiss-technology.com/"; - private static int count = 0; + private static int COUNT = 0; public static void main(String[] aArgs) { HttpClientParams clientParams = new HttpClientParams(); - clientParams.setIntParameter(HttpClientParams.MAX_REDIRECTS, 10); + clientParams.setIntParameter(HttpClientParams.MAX_REDIRECTS, MAX_REDIRECTS); clientParams.setBooleanParameter(HttpClientParams.REJECT_RELATIVE_REDIRECT, false); HttpClient client = new HttpClient(clientParams); - client.getHostConfiguration().setProxy("localhost", 10000); + client.getHostConfiguration().setProxy("localhost", PROXY_PORT); clientParams = client.getParams(); Object obj = clientParams.getParameter(HttpClientParams.MAX_REDIRECTS); @@ -81,27 +100,27 @@ public class Main { } /** - * @param client - * @param method + * @param aClient + * @param aMethod */ - private static int executeMethod(HttpClient client, HttpMethod method) { + private static int executeMethod(HttpClient aClient, HttpMethod aMethod) { //method.setFollowRedirects(true); try { // Execute the method. - int statusCode = client.executeMethod(method); + int statusCode = aClient.executeMethod(aMethod); if (statusCode != HttpStatus.SC_OK) { - System.err.println("Method failed: " + method.getStatusLine()); + System.err.println("Method failed: " + aMethod.getStatusLine()); } // Read the response body. - String filename = "output" + count++; + String filename = "output" + COUNT++; FileOutputStream os = new FileOutputStream(new File(filename)); //os.write(method.getResponseBody()); Tidy tidy = new Tidy(); tidy.setXHTML(true); - tidy.parse(method.getResponseBodyAsStream(), os); + tidy.parse(aMethod.getResponseBodyAsStream(), os); os.close(); System.out.println("Written response to file: " + filename); return statusCode; @@ -111,7 +130,7 @@ public class Main { throw new RuntimeException("Fatal transport error: " + e.getMessage()); } finally { // Release the connection. - method.releaseConnection(); + aMethod.releaseConnection(); } }