I just found that as we don't know the exact size, the buf had additional 0 bytes inside.  So thought we can track it and assuming am using INT I was able to track it.  Anyway changed it back to byteStream.getSize(),  due to some reason this was not working correctly yesterday. Now its fine.