chaokunyang commented on code in PR #1451:
URL: https://github.com/apache/incubator-fury/pull/1451#discussion_r1555453677
##########
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:
Could you elaborate more how `MemoryBuffer` read from the
`InputStream`/`Channel`? There still a interface for such cases. That's what
`AbstractStreamReader` is used for here.
--
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]