zymap commented on PR #4607:
URL: https://github.com/apache/bookkeeper/pull/4607#issuecomment-2918429558
You can try the following code to test the Unpooled.buffer() generated bytes.
```
// you
@org.junit.jupiter.api.Test
public void test() throws InterruptedException {
byte[] bytes = new byte[1024];
while (true) {
var buf = Unpooled.buffer(1024);
buf.writerIndex(1024);
if (ByteBufUtil.compare(buf, Unpooled.wrappedBuffer(bytes)) !=
0) {
System.out.println(ByteBufUtil.hexDump(buf));
}
}
}
````
Here is am example output:
```
02000000c8006af880f8acf800000000010000000000000058920400000400000100000000000000486800000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
```
In the netty Unpooled allocate, there is a method used to generate the
buffer.
```java
public static byte[] allocateUninitializedArray(int size) {
return UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD < 0 ||
UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD > size ?
new byte[size] :
PlatformDependent0.allocateUninitializedArray(size);
}
```
```
int tryAllocateUninitializedArray =
SystemPropertyUtil.getInt("io.netty.uninitializedArrayAllocationThreshold",
1024);
UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD = javaVersion() >= 9 &&
PlatformDependent0.hasAllocateArrayMethod() ?
tryAllocateUninitializedArray : -1;
```
when you go to use `PlatformDependent0.allocateUninitializedArray(size)` ,
the buffer may not cleaned to use, you have to set 0 by yourself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]