Indentation
This commit is contained in:
parent
7036654647
commit
aae6dce046
@ -58,87 +58,87 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
|
|||||||
setComponents(buffers);
|
setComponents(buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same with {@link #slice(int, int)} except that this method returns a list.
|
* Same with {@link #slice(int, int)} except that this method returns a list.
|
||||||
*/
|
*/
|
||||||
public List<ChannelBuffer> decompose(int index, int length) {
|
public List<ChannelBuffer> decompose(int index, int length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index + length > capacity()) {
|
if (index + length > capacity()) {
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
int componentId = componentId(index);
|
int componentId = componentId(index);
|
||||||
List<ChannelBuffer> slice = new ArrayList<ChannelBuffer>(components.length);
|
List<ChannelBuffer> slice = new ArrayList<ChannelBuffer>(components.length);
|
||||||
|
|
||||||
// The first component
|
// The first component
|
||||||
ChannelBuffer first = components[componentId].duplicate();
|
ChannelBuffer first = components[componentId].duplicate();
|
||||||
first.readerIndex(index - indices[componentId]);
|
first.readerIndex(index - indices[componentId]);
|
||||||
|
|
||||||
ChannelBuffer buf = first;
|
ChannelBuffer buf = first;
|
||||||
int bytesToSlice = length;
|
int bytesToSlice = length;
|
||||||
do {
|
do {
|
||||||
int readableBytes = buf.readableBytes();
|
int readableBytes = buf.readableBytes();
|
||||||
if (bytesToSlice <= readableBytes) {
|
if (bytesToSlice <= readableBytes) {
|
||||||
// Last component
|
// Last component
|
||||||
buf.writerIndex(buf.readerIndex() + bytesToSlice);
|
buf.writerIndex(buf.readerIndex() + bytesToSlice);
|
||||||
slice.add(buf);
|
slice.add(buf);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// Not the last component
|
// Not the last component
|
||||||
slice.add(buf);
|
slice.add(buf);
|
||||||
bytesToSlice -= readableBytes;
|
bytesToSlice -= readableBytes;
|
||||||
componentId ++;
|
componentId ++;
|
||||||
|
|
||||||
// Fetch the next component.
|
// Fetch the next component.
|
||||||
buf = components[componentId].duplicate();
|
buf = components[componentId].duplicate();
|
||||||
}
|
}
|
||||||
} while (bytesToSlice > 0);
|
} while (bytesToSlice > 0);
|
||||||
|
|
||||||
// Slice all components because only readable bytes are interesting.
|
// Slice all components because only readable bytes are interesting.
|
||||||
for (int i = 0; i < slice.size(); i ++) {
|
for (int i = 0; i < slice.size(); i ++) {
|
||||||
slice.set(i, slice.get(i).slice());
|
slice.set(i, slice.get(i).slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
return slice;
|
return slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup this ChannelBuffer from the list
|
* Setup this ChannelBuffer from the list
|
||||||
*/
|
*/
|
||||||
private void setComponents(List<ChannelBuffer> newComponents) {
|
private void setComponents(List<ChannelBuffer> newComponents) {
|
||||||
assert !newComponents.isEmpty();
|
assert !newComponents.isEmpty();
|
||||||
|
|
||||||
// Clear the cache.
|
// Clear the cache.
|
||||||
lastAccessedComponentId = 0;
|
lastAccessedComponentId = 0;
|
||||||
|
|
||||||
// Build the component array.
|
// Build the component array.
|
||||||
components = new ChannelBuffer[newComponents.size()];
|
components = new ChannelBuffer[newComponents.size()];
|
||||||
for (int i = 0; i < components.length; i ++) {
|
for (int i = 0; i < components.length; i ++) {
|
||||||
ChannelBuffer c = newComponents.get(i);
|
ChannelBuffer c = newComponents.get(i);
|
||||||
if (c.order() != order()) {
|
if (c.order() != order()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"All buffers must have the same endianness.");
|
"All buffers must have the same endianness.");
|
||||||
}
|
}
|
||||||
|
|
||||||
assert c.readerIndex() == 0;
|
assert c.readerIndex() == 0;
|
||||||
assert c.writerIndex() == c.capacity();
|
assert c.writerIndex() == c.capacity();
|
||||||
|
|
||||||
components[i] = c;
|
components[i] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the component lookup table.
|
// Build the component lookup table.
|
||||||
indices = new int[components.length + 1];
|
indices = new int[components.length + 1];
|
||||||
indices[0] = 0;
|
indices[0] = 0;
|
||||||
for (int i = 1; i <= components.length; i ++) {
|
for (int i = 1; i <= components.length; i ++) {
|
||||||
indices[i] = indices[i - 1] + components[i - 1].capacity();
|
indices[i] = indices[i - 1] + components[i - 1].capacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the indexes.
|
// Reset the indexes.
|
||||||
setIndex(0, capacity());
|
setIndex(0, capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompositeChannelBuffer(CompositeChannelBuffer buffer) {
|
private CompositeChannelBuffer(CompositeChannelBuffer buffer) {
|
||||||
order = buffer.order;
|
order = buffer.order;
|
||||||
|
Loading…
Reference in New Issue
Block a user