Java Reference
In-Depth Information
* This method downloads the specified URL into a Java
* String. This is a very simple method, that you can
* reused anytime you need to quickly grab all data from
* a specific URL.
*
* @param url The URL to download.
* @param timeout The number of milliseconds to wait for
* connection
* @return The contents of the URL that was downloaded.
* @throws IOException Thrown if any sort of error occurs.
*/
public String downloadPage(URL url, int timeout)
throws IOException
{
StringBuilder result = new StringBuilder();
byte buffer[] = new byte[BUFFER_SIZE];
URLConnection http = url.openConnection();
http.setConnectTimeout(100);
InputStream s = http.getInputStream();
int size = 0;
do
{
size = s.read(buffer);
if (size != -1)
result.append(new String(buffer, 0, size));
} while (size != -1);
return result.toString();
}
/**
* Called to process each individual item found.
* @param official Site The official site for this state.
* @param flag The flag for this state.
*/
private void processItem(URL officialSite, URL flag)
{
StringBuilder result = new StringBuilder();
result.append("\"");
result.append(officialSite.toString());
result.append("\",\"");
result.append(flag.toString());
result.append("\"");
Search WWH ::




Custom Search