M
martijn
Hi,
When I download files over an urlconnection, Im able to monitor
progress by counting the nr bytes read from the stream (see code
below). But When I download a .class file, I can't, it seems to
block.... whats going on here?
URL url = new URL("http://localhost/test/test.class");
URLConnection c = url.openConnection();
c.setUseCaches(true);
int contentLength = c.getContentLength();
InputStream f = c.getInputStream();
BufferedInputStream bis = new BufferedInputStream(f);
byte[] byteData = new byte[contentLength];
int realLength=0, bytesRead;
int length=bis.available();
if(length>5120) length=5120;
byte[] tmpBuff=new byte[length];
System.out.println("Downloading...");
while((bytesRead = bis.read(tmpBuff,0,length)) != -1)
{
System.arraycopy(tmpBuff, 0, byteData, realLength, bytesRead);
realLength+=bytesRead;
System.out.println("read "+bytesRead+" bytes of data...");
}
When I download files over an urlconnection, Im able to monitor
progress by counting the nr bytes read from the stream (see code
below). But When I download a .class file, I can't, it seems to
block.... whats going on here?
URL url = new URL("http://localhost/test/test.class");
URLConnection c = url.openConnection();
c.setUseCaches(true);
int contentLength = c.getContentLength();
InputStream f = c.getInputStream();
BufferedInputStream bis = new BufferedInputStream(f);
byte[] byteData = new byte[contentLength];
int realLength=0, bytesRead;
int length=bis.available();
if(length>5120) length=5120;
byte[] tmpBuff=new byte[length];
System.out.println("Downloading...");
while((bytesRead = bis.read(tmpBuff,0,length)) != -1)
{
System.arraycopy(tmpBuff, 0, byteData, realLength, bytesRead);
realLength+=bytesRead;
System.out.println("read "+bytesRead+" bytes of data...");
}