Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

buffer.clear() not working (urgent)  RSS feed

madhavi tondapu
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

try {
requestByteBuffer = ByteBuffer.wrap(request, 0, request.length);

buffer = ByteBuffer.allocate(100);
sbResponse = new StringBuffer();

loop: while ( > 0) {

array = new byte[100];


buffer.get(array, 0, 100);

str = new String(array);



}catch(Exception e) { }

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!