DefaultDataBuffer improvements
DefaultDataBuffer.grow(int): - Copy only the remaining data - Update readPosition/writePosition
This commit is contained in:
@@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -266,4 +267,20 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void growDataBuffer() {
|
||||
DataBuffer buffer = stringBuffer("Hello World!");
|
||||
|
||||
byte[] bytes = new byte[5];
|
||||
buffer.read(bytes);
|
||||
assertArrayEquals("Hello".getBytes(StandardCharsets.UTF_8), bytes);
|
||||
|
||||
buffer.write("!!".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
bytes = new byte[9];
|
||||
buffer.read(bytes);
|
||||
assertArrayEquals(" World!!!".getBytes(StandardCharsets.UTF_8), bytes);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user