Hadoop源码分析6: Buffer 细节

Hadoop源码分析6: <wbr>Buffer <wbr>细节


0 <= position <= limit <= capacity

Buffer.clear():     清空数据。limit = capacity,position = 0
Buffer.flip():     调整指针供读写。limit = position,position = 0
Buffer.rewind():    读写的指针重回原位置。limit 不变,     position = 0
Buffer.remaining(): 返回 limit-position
Buffer.compact():    删除position以下内容,上面内容下移,position = limit-position, limit =capacity
SocketChannel.read(Buffer buffer):limit不变,position=position +n , n为读出前实际数据长度,即position上移n,奉行最大限度读原则,即读到limit
SocketChannel.writer(Bufferbuffer):limit不变,position=position + n ,n为写入入的数据长度,即position上移n,奉行最大限度写原则,即写到limit

原文地址:https://www.cnblogs.com/leeeee/p/7276534.html