Java Reference
In-Depth Information
* a specific URL.
*
* @param url The URL to download.
* @return The contents of the URL that was downloaded.
* @throws IOException Thrown if any sort of error occurs.
*/
public String downloadPage(URL url) throws IOException
{
StringBuilder result = new StringBuilder();
byte buffer[] = new byte[BUFFER_SIZE];
InputStream s = url.openStream();
int size = 0;
do
{
size = s.read(buffer);
if (size != -1)
result.append(new String(buffer, 0, size));
} while (size != -1);
return result.toString();
}
/**
* Extract a string of text from between the two specified
* tokens. The case of the two tokens must match.
*
* @param url The URL to download.
* @param token1 The text, or tag, that comes before the
* desired text.
* @param token2 The text, or tag, that comes after the
* desired text.
* @param count Which occurrence of token1 to use, 1 for
* the first.
* @return The contents of the URL that was downloaded.
*/
public String extract(String str, String token1,
String token2, int count)
{
int location1, location2;
location1 = location2 = 0;
do
{
location1 = str.indexOf(token1, location1);
Search WWH ::




Custom Search