Thanks
try {
byte[] data = new byte[16384];
byte[] xmlByte;
String xmlString;
this.dataFromURL = new ArrayList<String>();
this.list = new BusStopList();
URL url = null;
float percentage;
int longitude;
int latitude;
for(int i = 1000; i < 10000; i++)
{
url = new URL(params[0] + i + ".xml");
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
while((nRead = is.read(data, 0, data.length)) != -1)
{
buffer.write(data, 0, nRead);
}
buffer.flush();
xmlByte = buffer.toByteArray();
xmlString = new String(xmlByte);
buffer.close();
is.close();
if(!xmlString.contains("invalid"))
{
xmlString = xmlString.replaceAll("\\<.*?>", "");
xmlString = xmlString.replaceAll(" ", "");
xmlString = xmlString.replaceAll("\n\n\n", "\n\n");
xmlString = xmlString.replaceAll("amp;", "");
xmlString = xmlString.replaceAll("Street", "St");
xmlString = xmlString.replaceAll("Avenue", "Ave");
Collections.addAll(dataFromURL, xmlString.split("\n"));
this.dataFromURL.remove(0);
for(int j = 0; i < this.dataFromURL.size(); i++)
{
if(this.dataFromURL.get(j).isEmpty())
this.dataFromURL.remove(j);
}
longitude = (int)(Double.parseDouble(this.dataFromURL.get(2)) *1E6);
latitude = (int)(Double.parseDouble(this.dataFromURL.get(1)) * 1E6);
list.addMapPoint(new MapPoint(longitude, latitude,
this.dataFromURL.get(dataFromURL.size() - 1),
this.dataFromURL.get(3)));
}
this.dataFromURL.clear();
percentage = ((float)(i-1000) / (float)8999) * 100;
publishProgress(Float.valueOf(percentage).intValue());
// Escape early if cancel() is called
if (isCancelled()) break;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

New Topic/Question
Reply




MultiQuote





|