beautypg.com

Motorola HANDSET C381P User Manual

Page 33

background image

8
Network
APIs

33

try {

is[i] = hc[i].openInputStream();

byteCounts[i] = 0;

readLengths[i] = hc[i].getLength();

System.out.println("readLengths = " +
readLengths[i]);

if (readLengths[i] == -1)

{

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 -= bytes_read;

byteCounts[i] += bytes_read;

}

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();