Good attempt, but not entirely correct.
Your only mistake (as far as I see) are these lines:
Code:
out.write('\n');
out.write((int) imageFile.length());
This is wrong because: you don't know the size of that integer. If the image is 10,000 bytes, it'll be represented by a 6 character string, but if the image is 100,000 bytes it would be a 7 character string. How do you know where to stop?
An integer on the other is always 4 byte in size (in the memory). It's possible to write an object to an output stream with an ObjectOutputStream. Then reading is done with an ObjectInputStream. If you use this you'll have no problems to determine where the data of the archive ends. The '\n' isn't even required.
I haven't tried it, but I think the following code should roughly be correct:
Code:
(new ObjectOutputStream((OutputStream) out)).write((int) imageFile.length());
A bit longer (more readable):
Code:
outOOS = new ObjectOutputStream((OutputStream) out);
outOOS.write((int) imageFile.length());
Of course I'm assuming there is a constructor
ObjectOutputStream(OutputStream arg1), if there isn't the code is wrong.
It's a bit late now, but if you want more info (or more structured) just ask and I'll respond when I have some more time... (and less beer)