这个方法大多数朋友接触的比较少,可能不是很熟悉,但是在HDFS EC解码的时候,大量用到这个方法。因此来学习一下。
主要功能是:创建一个新的byte buffer,这个新的byte buffer的内容是当前buffer内容的一个共享的子序列。什么是共享的?就是这两个buffer做了修改是互相可见的,下面我们的测试用例会说明这一点。新buffer的内容是从当前buffer的position
位置开始,一直到limit-1
位置为止。
官方注释:
/**
* Creates a new byte buffer whose content is a shared subsequence of
* this buffer's content.
*
* <p> The content of the new buffer will start at this buffer's current
* position. Changes to this buffer's content will be visible in the new
* buffer, and vice versa; the two buffers' position, limit, and mark
* values will be independent.
*
* <p> The new buffer's position will be zero, its capacity and its limit
* will be the number of bytes remaining in this buffer, and its mark
* will be undefined.