#7243 ByteBufferPool and RetainableByteBufferPool now reset the buffer's endianness on release
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
4ef4bf039d
commit
068c24a744
|
@ -208,7 +208,7 @@ public interface ByteBufferPool
|
|||
public void release(ByteBuffer buffer)
|
||||
{
|
||||
resetUpdateTime();
|
||||
BufferUtil.clear(buffer);
|
||||
BufferUtil.reset(buffer);
|
||||
if (_size == null || _size.incrementAndGet() <= _maxSize)
|
||||
{
|
||||
_queue.offer(buffer);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -245,4 +246,15 @@ public class ArrayByteBufferPoolTest
|
|||
assertThat(buckets[2].size(), equalTo(2));
|
||||
assertThat(buckets[7].size(), equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEndiannessResetOnRelease()
|
||||
{
|
||||
ArrayByteBufferPool bufferPool = new ArrayByteBufferPool();
|
||||
ByteBuffer buffer = bufferPool.acquire(10, true);
|
||||
assertThat(buffer.order(), is(ByteOrder.BIG_ENDIAN));
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
bufferPool.release(buffer);
|
||||
assertThat(buffer.order(), is(ByteOrder.BIG_ENDIAN));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.io.RandomAccessFile;
|
|||
import java.nio.Buffer;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.FileChannel.MapMode;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -155,10 +156,27 @@ public class BufferUtil
|
|||
}
|
||||
|
||||
/**
|
||||
* Clear the buffer to be empty in flush mode.
|
||||
* The position and limit are set to 0;
|
||||
* Resets the buffer's endianness to {@link ByteOrder#BIG_ENDIAN}
|
||||
* and clears the buffer to be empty in flush mode.
|
||||
* The position and limit are set to 0.
|
||||
*
|
||||
* @param buffer The buffer to clear.
|
||||
* @param buffer the buffer to reset.
|
||||
*/
|
||||
public static void reset(ByteBuffer buffer)
|
||||
{
|
||||
if (buffer != null)
|
||||
{
|
||||
buffer.order(ByteOrder.BIG_ENDIAN);
|
||||
buffer.position(0);
|
||||
buffer.limit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the buffer to be empty in flush mode.
|
||||
* The position and limit are set to 0.
|
||||
*
|
||||
* @param buffer the buffer to clear.
|
||||
*/
|
||||
public static void clear(ByteBuffer buffer)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue