Recently I have met a following problem. I should read some pictures and audio files from a server into the java application.
It is a simple problem, but this code example can be useful for someone:

DataInputStream inStream = conn.openDataInputStream();
byte imageData[];
if (length != -1) { //case for known data size
imageData = new byte[length];
inStream.readFully(imageData);

} else { //case for unknown data size
ByteArrayOutputStream btArrOutstrem = new ByteArrayOutputStream();
int ch;
while ((ch = inStream.read()) != -1){
btArrOutstrem.write(ch);
}
imageData = btArrOutstrem.toByteArray();
btArrOutstrem.close();
}

//that’s all folks!
image = Image.createImage(imageData, 0, imageData.length);