Downloading Zip files too slow

I have two concerns...

1. I want to keep track of all the bytes downloaded thus allowing user to stop and resume downloading of the files... my code below works fine.. but it is too slow.. as it is counting each byte.. is there an alternative to this ?

2. When i add BUFFEREDouputSTREAM to speed up the process... 1. i dont have to count bytes downloaded 2. Zip file downloaded is corrupt it has differnt size on server and onlocal drive.

I wiill highly appreciate help from anyone. Thanks.

[CODE]

URL url = new URL(s1);

java.io.InputStream inputstream = url.openStream();

DataInputStream datainputstream = new DataInputStream(inputstream);

FileOutputStream fileoutputstream = new FileOutputStream(dto, true);

//BufferedOutputStream bufferedOutputStream= new BufferedOutputStream(fileoutputstream);

PrintStream printstream = new PrintStream(fileoutputstream);

datainputstream.skipBytes(already);

int j;

do

{

l++;

j = datainputstream.read();

if(l > 6000)

{

l = 0;

Thread.yield();

}

String s = String.valueOf(j);

if(j != -1)

{

printstream.write(j);

i = i + 1;

k++;

}

already++;

} while(j != -1);

}

catch(Exception _ex) { _ex.printStackTrace(); }

[1353 byte] By [netsolpk] at [2007-9-30 4:16:39]
# 1

> I have two concerns...

> 1. I want to keep track of all the bytes downloaded

> thus allowing user to stop and resume downloading of

> the files... my code below works fine.. but it is too

> slow.. as it is counting each byte.. is there an

> alternative to this ?

Why do you think that counting has anything do with it?

Sockets send packets not bytes, so the information is already buffered.

>

> 2. When i add BUFFEREDouputSTREAM to speed up the

> process... 1. i dont have to count bytes downloaded 2.

> Zip file downloaded is corrupt it has differnt size on

> server and onlocal drive.

>

The usual cause of this problem is because a byte buffer is being used and instead of using the bytes that were read the byte buffer length is used. The two are not the same.

jschell at 2007-7-1 12:27:50 > top of Java-index,Archived Forums,Socket Programming...