Sending to OutputStream but Read with inputstream read not throwing -1

Solution 1:

Maybe someting like this: Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. A subclass must provide an implementation of this method. Returns: the next byte of data, or -1 if the end of the stream is reached. Throws: IOException – if an I/O error occurs.

Solution 2:

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

https://developer.android.com/reference/java/io/InputStream#read()

As fanyang said, the read function returns a value between 0 and 255, and returning -1 means the end of the stream.