I have the following code which produces an OutOfMemory exception:
byte[] buf = new byte[10240];
int len = 0;
DataOutputStream dataOS = new DataOutputStream(
Depending on the implementation of OutputStream, writing may buffer the content in memory, and not actually send it. If you buffer enough content, you will of course run out of memory.
At some interval, perhaps each time through your loop, you should call OutputStream.flush(). If there is a buffer in use, that will clear it.