+package org.wamblee.crawler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
*
*/
-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);
}
/**
- * @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;
throw new RuntimeException("Fatal transport error: " + e.getMessage());
} finally {
// Release the connection.
- method.releaseConnection();
+ aMethod.releaseConnection();
}
}