I am reading data from socket channle by connecting to remote server from my machine. I am reading all the data but the data is going to be duplicate in some cases. buffer.clear() is not clearing all the data. Suppose if I read first 100 bytes. Whne reading next 100 bytes and if there any spaces then the spaces are going to replace with previous data. Why is it happening. How do I read data with duplicate even if there any spaces in the data. Here is the code i am trying to use to read data.