Improved socket data reading capability.

Optimized solution using bytearrayoutputstream