parent
8e1a6c6cf5
commit
5a4a59406b
@ -1,19 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 The Netty Project
|
|
||||||
*
|
|
||||||
* The Netty Project licenses this file to you under the Apache License,
|
|
||||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2012 The Netty Project
|
* Copyright 2012 The Netty Project
|
||||||
*
|
*
|
||||||
@ -829,7 +813,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer nioBuffer;
|
ByteBuffer nioBuffer;
|
||||||
if (hasNioBuffer()) {
|
if (nioBufferCount() == 1) {
|
||||||
nioBuffer = nioBuffer(index, length);
|
nioBuffer = nioBuffer(index, length);
|
||||||
} else {
|
} else {
|
||||||
nioBuffer = ByteBuffer.allocate(length);
|
nioBuffer = ByteBuffer.allocate(length);
|
||||||
|
@ -1,19 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 The Netty Project
|
|
||||||
*
|
|
||||||
* The Netty Project licenses this file to you under the Apache License,
|
|
||||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2012 The Netty Project
|
* Copyright 2012 The Netty Project
|
||||||
*
|
*
|
||||||
@ -1715,22 +1699,35 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
|
|||||||
ByteBuf duplicate();
|
ByteBuf duplicate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} if and only if {@link #nioBuffer()} method will not fail.
|
* Returns the maximum number of NIO {@link ByteBuffer}s that consist this buffer. Note that {@link #nioBuffers()}
|
||||||
|
* or {@link #nioBuffers(int, int)} might return a less number of {@link ByteBuffer}s.
|
||||||
|
*
|
||||||
|
* @return {@code -1} if this buffer has no underlying {@link ByteBuffer}.
|
||||||
|
* the number of the underlying {@link ByteBuffer}s if this buffer has at least one undelying
|
||||||
|
* {@link ByteBuffer}. Note that this method does not return {@code 0} to avoid confusion.
|
||||||
|
*
|
||||||
|
* @see #nioBuffer()
|
||||||
|
* @see #nioBuffer(int, int)
|
||||||
|
* @see #nioBuffers()
|
||||||
|
* @see #nioBuffers(int, int)
|
||||||
*/
|
*/
|
||||||
boolean hasNioBuffer();
|
int nioBufferCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}. The returned buffer
|
* Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}. The returned buffer
|
||||||
* shares the content with this buffer, while changing the position and limit of the returned
|
* shares the content with this buffer, while changing the position and limit of the returned
|
||||||
* NIO buffer does not affect the indexes and marks of this buffer. This method is identical
|
* NIO buffer does not affect the indexes and marks of this buffer. This method is identical
|
||||||
* to {@code buf.asByteBuffer(buf.readerIndex(), buf.readableBytes())}. This method does not
|
* to {@code buf.nioBuffer(buf.readerIndex(), buf.readableBytes())}. This method does not
|
||||||
* modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the
|
* modify {@code readerIndex} or {@code writerIndex} of this buffer. Please note that the
|
||||||
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
|
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
|
||||||
* buffer and it adjusted its capacity.
|
* buffer and it adjusted its capacity.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
||||||
|
*
|
||||||
|
* @see #nioBufferCount()
|
||||||
|
* @see #nioBuffers()
|
||||||
|
* @see #nioBuffers(int, int)
|
||||||
*/
|
*/
|
||||||
ByteBuffer nioBuffer();
|
ByteBuffer nioBuffer();
|
||||||
|
|
||||||
@ -1744,14 +1741,13 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
|
|||||||
*
|
*
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
||||||
|
*
|
||||||
|
* @see #nioBufferCount()
|
||||||
|
* @see #nioBuffers()
|
||||||
|
* @see #nioBuffers(int, int)
|
||||||
*/
|
*/
|
||||||
ByteBuffer nioBuffer(int index, int length);
|
ByteBuffer nioBuffer(int index, int length);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns {@code true} if and only if {@link #nioBuffers()} method will not fail.
|
|
||||||
*/
|
|
||||||
boolean hasNioBuffers();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}'s. The returned buffer
|
* Exposes this buffer's readable bytes as an NIO {@link ByteBuffer}'s. The returned buffer
|
||||||
* shares the content with this buffer, while changing the position and limit of the returned
|
* shares the content with this buffer, while changing the position and limit of the returned
|
||||||
@ -1763,6 +1759,10 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
|
|||||||
*
|
*
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
||||||
|
*
|
||||||
|
* @see #nioBufferCount()
|
||||||
|
* @see #nioBuffer()
|
||||||
|
* @see #nioBuffer(int, int)
|
||||||
*/
|
*/
|
||||||
ByteBuffer[] nioBuffers();
|
ByteBuffer[] nioBuffers();
|
||||||
|
|
||||||
@ -1774,9 +1774,12 @@ public interface ByteBuf extends ChannelBuf, Comparable<ByteBuf> {
|
|||||||
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
|
* returned NIO buffer will not see the changes of this buffer if this buffer is a dynamic
|
||||||
* buffer and it adjusted its capacity.
|
* buffer and it adjusted its capacity.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
* if this buffer cannot create a {@link ByteBuffer} that shares the content with itself
|
||||||
|
*
|
||||||
|
* @see #nioBufferCount()
|
||||||
|
* @see #nioBuffer()
|
||||||
|
* @see #nioBuffer(int, int)
|
||||||
*/
|
*/
|
||||||
ByteBuffer[] nioBuffers(int index, int length);
|
ByteBuffer[] nioBuffers(int index, int length);
|
||||||
|
|
||||||
|
@ -1057,11 +1057,8 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
if (components.size() == 1) {
|
return components.size();
|
||||||
return components.get(0).buf.hasNioBuffer();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1087,11 +1084,6 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
if (index + length > capacity()) {
|
if (index + length > capacity()) {
|
||||||
@ -1114,7 +1106,7 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
|
|||||||
ByteBuf s = c.buf;
|
ByteBuf s = c.buf;
|
||||||
int adjustment = c.offset;
|
int adjustment = c.offset;
|
||||||
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
int localLength = Math.min(length, s.capacity() - (index - adjustment));
|
||||||
buffers.add(toNioBuffer(s, index - adjustment, localLength));
|
buffers.add(s.nioBuffer(index - adjustment, localLength));
|
||||||
index += localLength;
|
index += localLength;
|
||||||
length -= localLength;
|
length -= localLength;
|
||||||
i ++;
|
i ++;
|
||||||
@ -1124,7 +1116,7 @@ public class DefaultCompositeByteBuf extends AbstractByteBuf implements Composit
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ByteBuffer toNioBuffer(ByteBuf buf, int index, int length) {
|
private static ByteBuffer toNioBuffer(ByteBuf buf, int index, int length) {
|
||||||
if (buf.hasNioBuffer()) {
|
if (buf.nioBufferCount() == 1) {
|
||||||
return buf.nioBuffer(index, length);
|
return buf.nioBuffer(index, length);
|
||||||
} else {
|
} else {
|
||||||
return buf.copy(index, length).nioBuffer(0, length);
|
return buf.copy(index, length).nioBuffer(0, length);
|
||||||
|
@ -220,8 +220,8 @@ public class DuplicatedByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return buffer.hasNioBuffer();
|
return buffer.nioBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -229,11 +229,6 @@ public class DuplicatedByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
return buffer.nioBuffer(index, length);
|
return buffer.nioBuffer(index, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return buffer.hasNioBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
return buffer.nioBuffers(index, length);
|
return buffer.nioBuffers(index, length);
|
||||||
|
@ -252,8 +252,8 @@ final class PooledDirectByteBuf extends PooledByteBuf<ByteBuffer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -263,11 +263,6 @@ final class PooledDirectByteBuf extends PooledByteBuf<ByteBuffer> {
|
|||||||
return ((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)).slice();
|
return ((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)).slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
return new ByteBuffer[] { nioBuffer(index, length) };
|
return new ByteBuffer[] { nioBuffer(index, length) };
|
||||||
|
@ -222,8 +222,8 @@ final class PooledHeapByteBuf extends PooledByteBuf<byte[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -233,11 +233,6 @@ final class PooledHeapByteBuf extends PooledByteBuf<byte[]> {
|
|||||||
return ((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)).slice();
|
return ((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)).slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
return new ByteBuffer[] { nioBuffer(index, length) };
|
return new ByteBuffer[] { nioBuffer(index, length) };
|
||||||
|
@ -208,8 +208,8 @@ public class ReadOnlyByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return buffer.hasNioBuffer();
|
return buffer.nioBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -217,11 +217,6 @@ public class ReadOnlyByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
return buffer.nioBuffer(index, length).asReadOnlyBuffer();
|
return buffer.nioBuffer(index, length).asReadOnlyBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return buffer.hasNioBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
return buffer.nioBuffers(index, length);
|
return buffer.nioBuffers(index, length);
|
||||||
|
@ -269,8 +269,8 @@ public class SlicedByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return buffer.hasNioBuffer();
|
return buffer.nioBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -279,11 +279,6 @@ public class SlicedByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
return buffer.nioBuffer(index + adjustment, length);
|
return buffer.nioBuffer(index + adjustment, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return buffer.hasNioBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
checkIndex(index, length);
|
checkIndex(index, length);
|
||||||
|
@ -1,19 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 The Netty Project
|
|
||||||
*
|
|
||||||
* The Netty Project licenses this file to you under the Apache License,
|
|
||||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2012 The Netty Project
|
* Copyright 2012 The Netty Project
|
||||||
*
|
*
|
||||||
@ -727,8 +711,8 @@ public final class SwappedByteBuf implements ByteBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return buf.hasNioBuffer();
|
return buf.nioBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -741,11 +725,6 @@ public final class SwappedByteBuf implements ByteBuf {
|
|||||||
return buf.nioBuffer(index, length).order(order);
|
return buf.nioBuffer(index, length).order(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return buf.hasNioBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers() {
|
public ByteBuffer[] nioBuffers() {
|
||||||
ByteBuffer[] nioBuffers = buf.nioBuffers();
|
ByteBuffer[] nioBuffers = buf.nioBuffers();
|
||||||
|
@ -440,8 +440,8 @@ final class UnpooledDirectByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -454,14 +454,9 @@ final class UnpooledDirectByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
throw new UnsupportedOperationException();
|
return new ByteBuffer[] { nioBuffer(index, length) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -240,8 +240,8 @@ final class UnpooledHeapByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return true;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -250,14 +250,9 @@ final class UnpooledHeapByteBuf extends AbstractByteBuf implements Unsafe {
|
|||||||
return ByteBuffer.wrap(array, index, length);
|
return ByteBuffer.wrap(array, index, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers(int index, int length) {
|
public ByteBuffer[] nioBuffers(int index, int length) {
|
||||||
throw new UnsupportedOperationException();
|
return new ByteBuffer[] { nioBuffer(index, length) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,9 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import static io.netty.buffer.Unpooled.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -27,10 +29,8 @@ import java.util.HashSet;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.After;
|
import static io.netty.buffer.Unpooled.*;
|
||||||
import org.junit.Assume;
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract test class for channel buffers
|
* An abstract test class for channel buffers
|
||||||
@ -1529,7 +1529,7 @@ public abstract class AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNioBuffer1() {
|
public void testNioBuffer1() {
|
||||||
Assume.assumeTrue(buffer.hasNioBuffer());
|
Assume.assumeTrue(buffer.nioBufferCount() == 1);
|
||||||
|
|
||||||
byte[] value = new byte[buffer.capacity()];
|
byte[] value = new byte[buffer.capacity()];
|
||||||
random.nextBytes(value);
|
random.nextBytes(value);
|
||||||
@ -1541,7 +1541,7 @@ public abstract class AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToByteBuffer2() {
|
public void testToByteBuffer2() {
|
||||||
Assume.assumeTrue(buffer.hasNioBuffer());
|
Assume.assumeTrue(buffer.nioBufferCount() == 1);
|
||||||
|
|
||||||
byte[] value = new byte[buffer.capacity()];
|
byte[] value = new byte[buffer.capacity()];
|
||||||
random.nextBytes(value);
|
random.nextBytes(value);
|
||||||
@ -1555,7 +1555,7 @@ public abstract class AbstractChannelBufferTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToByteBuffer3() {
|
public void testToByteBuffer3() {
|
||||||
Assume.assumeTrue(buffer.hasNioBuffer());
|
Assume.assumeTrue(buffer.nioBufferCount() == 1);
|
||||||
|
|
||||||
assertEquals(buffer.order(), buffer.nioBuffer().order());
|
assertEquals(buffer.order(), buffer.nioBuffer().order());
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ public abstract class AbstractCompositeChannelBufferTest extends
|
|||||||
assertEquals(512, payload.readableBytes());
|
assertEquals(512, payload.readableBytes());
|
||||||
|
|
||||||
assertEquals(12 + 512, buffer.readableBytes());
|
assertEquals(12 + 512, buffer.readableBytes());
|
||||||
assertFalse(buffer.hasNioBuffer());
|
assertEquals(2, buffer.nioBufferCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -49,7 +49,7 @@ public class ChannelBuffersTest {
|
|||||||
assertEquals(512, payload.readableBytes());
|
assertEquals(512, payload.readableBytes());
|
||||||
|
|
||||||
assertEquals(12 + 512, buffer.readableBytes());
|
assertEquals(12 + 512, buffer.readableBytes());
|
||||||
assertFalse(buffer.hasNioBuffer());
|
assertEquals(2, buffer.nioBufferCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -133,7 +133,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
throw new IOException("Out of size: " + (size + localsize) +
|
throw new IOException("Out of size: " + (size + localsize) +
|
||||||
" > " + definedSize);
|
" > " + definedSize);
|
||||||
}
|
}
|
||||||
ByteBuffer byteBuffer = buffer.hasNioBuffer() ? buffer.nioBuffer() : buffer.copy().nioBuffer();
|
ByteBuffer byteBuffer = buffer.nioBufferCount() == 1 ? buffer.nioBuffer() : buffer.copy().nioBuffer();
|
||||||
int written = 0;
|
int written = 0;
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
file = tempFile();
|
file = tempFile();
|
||||||
|
@ -14,22 +14,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
ackage io.netty.handler.codec;
|
||||||
* Copyright 2012 The Netty Project
|
|
||||||
*
|
|
||||||
* The Netty Project licenses this file to you under the Apache License,
|
|
||||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at:
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package io.netty.handler.codec;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBuf.Unsafe;
|
import io.netty.buffer.ByteBuf.Unsafe;
|
||||||
@ -684,8 +669,8 @@ final class ReplayingDecoderBuffer implements ByteBuf, Unsafe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNioBuffer() {
|
public int nioBufferCount() {
|
||||||
return buffer.hasNioBuffer();
|
return buffer.nioBufferCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -699,11 +684,6 @@ final class ReplayingDecoderBuffer implements ByteBuf, Unsafe {
|
|||||||
return buffer.nioBuffer(index, length);
|
return buffer.nioBuffer(index, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNioBuffers() {
|
|
||||||
return buffer.hasNioBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer[] nioBuffers() {
|
public ByteBuffer[] nioBuffers() {
|
||||||
throw new UnreplayableOperationException();
|
throw new UnreplayableOperationException();
|
||||||
|
@ -258,7 +258,10 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
|||||||
buf.discardReadBytes();
|
buf.discardReadBytes();
|
||||||
|
|
||||||
asyncWriteInProgress = true;
|
asyncWriteInProgress = true;
|
||||||
if (buf.hasNioBuffers()) {
|
if (buf.nioBufferCount() == 1) {
|
||||||
|
javaChannel().write(
|
||||||
|
buf.nioBuffer(), config.getWriteTimeout(), TimeUnit.MILLISECONDS, this, WRITE_HANDLER);
|
||||||
|
} else {
|
||||||
ByteBuffer[] buffers = buf.nioBuffers(buf.readerIndex(), buf.readableBytes());
|
ByteBuffer[] buffers = buf.nioBuffers(buf.readerIndex(), buf.readableBytes());
|
||||||
if (buffers.length == 1) {
|
if (buffers.length == 1) {
|
||||||
javaChannel().write(
|
javaChannel().write(
|
||||||
@ -268,9 +271,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
|||||||
buffers, 0, buffers.length, config.getWriteTimeout(), TimeUnit.MILLISECONDS,
|
buffers, 0, buffers.length, config.getWriteTimeout(), TimeUnit.MILLISECONDS,
|
||||||
this, GATHERING_WRITE_HANDLER);
|
this, GATHERING_WRITE_HANDLER);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
javaChannel().write(
|
|
||||||
buf.nioBuffer(), config.getWriteTimeout(), TimeUnit.MILLISECONDS, this, WRITE_HANDLER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asyncWriteInProgress) {
|
if (asyncWriteInProgress) {
|
||||||
@ -322,7 +322,12 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
|||||||
expandReadBuffer(byteBuf);
|
expandReadBuffer(byteBuf);
|
||||||
|
|
||||||
asyncReadInProgress = true;
|
asyncReadInProgress = true;
|
||||||
if (byteBuf.hasNioBuffers()) {
|
if (byteBuf.nioBufferCount() == 1) {
|
||||||
|
// Get a ByteBuffer view on the ByteBuf
|
||||||
|
ByteBuffer buffer = byteBuf.nioBuffer(byteBuf.writerIndex(), byteBuf.writableBytes());
|
||||||
|
javaChannel().read(
|
||||||
|
buffer, config.getReadTimeout(), TimeUnit.MILLISECONDS, this, READ_HANDLER);
|
||||||
|
} else {
|
||||||
ByteBuffer[] buffers = byteBuf.nioBuffers(byteBuf.writerIndex(), byteBuf.writableBytes());
|
ByteBuffer[] buffers = byteBuf.nioBuffers(byteBuf.writerIndex(), byteBuf.writableBytes());
|
||||||
if (buffers.length == 1) {
|
if (buffers.length == 1) {
|
||||||
javaChannel().read(
|
javaChannel().read(
|
||||||
@ -332,11 +337,6 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
|
|||||||
buffers, 0, buffers.length, config.getReadTimeout(), TimeUnit.MILLISECONDS,
|
buffers, 0, buffers.length, config.getReadTimeout(), TimeUnit.MILLISECONDS,
|
||||||
this, SCATTERING_READ_HANDLER);
|
this, SCATTERING_READ_HANDLER);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Get a ByteBuffer view on the ByteBuf
|
|
||||||
ByteBuffer buffer = byteBuf.nioBuffer(byteBuf.writerIndex(), byteBuf.writableBytes());
|
|
||||||
javaChannel().read(
|
|
||||||
buffer, config.getReadTimeout(), TimeUnit.MILLISECONDS, this, READ_HANDLER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asyncReadInProgress) {
|
if (asyncReadInProgress) {
|
||||||
|
@ -193,7 +193,7 @@ public final class NioDatagramChannel
|
|||||||
ByteBuf data = packet.data();
|
ByteBuf data = packet.data();
|
||||||
int dataLen = data.readableBytes();
|
int dataLen = data.readableBytes();
|
||||||
ByteBuffer nioData;
|
ByteBuffer nioData;
|
||||||
if (data.hasNioBuffer()) {
|
if (data.nioBufferCount() == 1) {
|
||||||
nioData = data.nioBuffer();
|
nioData = data.nioBuffer();
|
||||||
} else {
|
} else {
|
||||||
nioData = ByteBuffer.allocate(dataLen);
|
nioData = ByteBuffer.allocate(dataLen);
|
||||||
|
@ -241,7 +241,7 @@ public class NioSctpChannel extends AbstractNioMessageChannel implements io.nett
|
|||||||
ByteBuf data = packet.getPayloadBuffer();
|
ByteBuf data = packet.getPayloadBuffer();
|
||||||
int dataLen = data.readableBytes();
|
int dataLen = data.readableBytes();
|
||||||
ByteBuffer nioData;
|
ByteBuffer nioData;
|
||||||
if (data.hasNioBuffer()) {
|
if (data.nioBufferCount() == 1) {
|
||||||
nioData = data.nioBuffer();
|
nioData = data.nioBuffer();
|
||||||
} else {
|
} else {
|
||||||
nioData = ByteBuffer.allocate(dataLen);
|
nioData = ByteBuffer.allocate(dataLen);
|
||||||
|
@ -136,7 +136,7 @@ public class OioSctpChannel extends AbstractOioMessageChannel
|
|||||||
ByteBuf data = packet.getPayloadBuffer();
|
ByteBuf data = packet.getPayloadBuffer();
|
||||||
int dataLen = data.readableBytes();
|
int dataLen = data.readableBytes();
|
||||||
ByteBuffer nioData;
|
ByteBuffer nioData;
|
||||||
if (data.hasNioBuffer()) {
|
if (data.nioBufferCount() == 1) {
|
||||||
nioData = data.nioBuffer();
|
nioData = data.nioBuffer();
|
||||||
} else {
|
} else {
|
||||||
nioData = ByteBuffer.allocate(dataLen);
|
nioData = ByteBuffer.allocate(dataLen);
|
||||||
|
Loading…
Reference in New Issue
Block a user