Munoon commented on code in PR #1451:
URL: https://github.com/apache/incubator-fury/pull/1451#discussion_r1555436359
##########
java/fury-core/src/main/java/org/apache/fury/memory/MemoryBuffer.java:
##########
@@ -100,24 +105,30 @@ public final class MemoryBuffer {
* @param length buffer size
*/
private MemoryBuffer(byte[] buffer, int offset, int length) {
- Preconditions.checkArgument(offset >= 0 && length >= 0);
+ this(buffer, offset, length, null);
+ }
+
+ /**
+ * Creates a new memory buffer that represents the memory of the byte array.
+ *
+ * @param buffer The byte array whose memory is represented by this memory
buffer.
+ * @param offset The offset of the sub array to be used; must be
non-negative and no larger than
+ * <tt>array.length</tt>.
+ * @param length buffer size
+ * @param streamReader a reader for reading from a stream.
+ */
+ private MemoryBuffer(byte[] buffer, int offset, int length, FuryStreamReader
streamReader) {
+ checkArgument(offset >= 0 && length >= 0);
if (offset + length > buffer.length) {
throw new IllegalArgumentException(
String.format("%d exceeds buffer size %d", offset + length,
buffer.length));
}
initHeapBuffer(buffer, offset, length);
- }
-
- private void initHeapBuffer(byte[] buffer, int offset, int length) {
- if (buffer == null) {
- throw new NullPointerException("buffer");
+ if (streamReader != null) {
+ this.streamReader = streamReader;
+ } else {
+ this.streamReader = new BoundChecker();
Review Comment:
Proposal: maybe instead of `BoundChecker` class we can make `MemoryBuffer`
class itself extending `AbstractStreamReader`? In this case we can avoid new
class initialization by simply passing `this` to the `streamReader` field.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]