
8
Network APIs
try {
is[i] = hc[i].openInputStream();
byteCounts[i] = 0;
readLengths[i] = hc[i].getLength();
System.out.println("readLengths = " +
readLengths[i]);
if (readLengths[i] ==
{
readLengths[i] = BUFFER_SIZE;
}
int bytes_read = 0; int offset = 0;
int bytes_left = (int)readLengths[i];
do
{
bytes_read = is[i].read(buffer, offset,
bytes_left);
offset += bytes_read; bytes_left
}
while (bytes_read > 0);
System.out.println("byte read = " +
byteCounts[i]);
} catch (Exception ex) {
System.out.println("Downloading Failed: "+
ex.getMessage());
numPassed = 0;
}
finally { try {
is[i].close(); is[i] = null; } catch (Exception ex) {}
}
}
/**
*close http connection
*/
if (hc[i] != null)
{
try { hc[i].close();
33