can we use the available method of the inputStream that we are using?
For example:
.
.
.
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream());
byte[] buffer=new byte(br.available());
.
.
.
BufferedReader doesn't have an available() method for a start.
The InputStream.available() method is not a solution for this problem, or for any other problem I am aware of either.
The OP needs to write his data to a ByteArrayOutputStream and then find out its size, write the size, then get the bytes from the BAOS and write those.