0
   private void performWrite(InputStream dataSource) throws ConnectionException { 
        final byte[] buffer = new byte[16 * 1024];

        BufferedInputStream bufferedInputStream = new BufferedInputStream(dataSource);
        int bytesRead = 0;
        while (bytesRead > -1) {
            bytesRead =  bufferedInputStream.read(buffer);
            Log.d("bytesRead", String.valueOf(bytesRead));
            Socketconnection.write(buffer, 0, bytesRead);
        }
    }

I'm using TCP socket and I'm stuck to why bytesRead goes down to 512 bytes. Can somebody help explain why this is happening? Also, can somebody suggest a solution to this?

D/bytesRead: 16384
D/bytesRead: 16384
D/bytesRead: 16384
D/bytesRead: 16384
D/bytesRead: 13422
D/bytesRead: 1536
D/bytesRead: 512
D/bytesRead: 512
D/bytesRead: 512
D/bytesRead: 512
D/bytesRead: 512
D/bytesRead: 512
......Same...
  • Does this answer your question? [How to read all of Inputstream in Server Socket JAVA](https://stackoverflow.com/questions/19839172/how-to-read-all-of-inputstream-in-server-socket-java) – onkar ruikar Mar 11 '21 at 03:39

0 Answers0