replace DataOutputStream with ByteBuffer due variable array size