Offer restricted access to DataBuffer's ByteBuffer
This commit introduces DataBuffer::readableByteBuffers and DataBuffer::writableByteBuffers, allowing restricted access to the ByteBuffer used internally by DataBuffer implementations. Closes gh-29943
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -99,9 +99,15 @@ public abstract class PayloadUtils {
|
||||
return NettyDataBufferFactory.toByteBuf(buffer);
|
||||
}
|
||||
|
||||
private static ByteBuffer asByteBuffer(DataBuffer buffer) {
|
||||
return buffer instanceof DefaultDataBuffer ?
|
||||
((DefaultDataBuffer) buffer).getNativeBuffer() : buffer.toByteBuffer();
|
||||
private static ByteBuffer asByteBuffer(DataBuffer dataBuffer) {
|
||||
if (dataBuffer instanceof DefaultDataBuffer defaultDataBuffer) {
|
||||
return defaultDataBuffer.getNativeBuffer();
|
||||
}
|
||||
else {
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocate(dataBuffer.readableByteCount());
|
||||
dataBuffer.toByteBuffer(byteBuffer);
|
||||
return byteBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user