Uh oh!
buffer.length
should be buffer.length - 1
The index of an array starts at 0 but the length starts at 1, therefore, you must use buffer.length - 1
.
Your program must wait until the Buffer has data available.
URL
is deprecated, BTW.
InputStream is = new BufferedInputStream(uc.getInputStream());
while(is.count < 1024) ;
//do other stuff
is.close();
Where is `buffer` declared?
Perhaps a simple LOGGER.info("InputStream Successfully initialized!")
or System.out.println("InputStream Successfully initialized!");
statement will give a large enough delay to let the buffer fill up.
Sometimes, the minuscule delay caused by a `print` statement can make a surprisingly large difference.