Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ private[spark] class ChunkedByteBufferInputStream(
dispose: Boolean)
extends InputStream {

private[this] var chunks = chunkedByteBuffer.getChunks().iterator
// Filter out empty chunks since `read()` assumes all chunks are non-empty.
private[this] var chunks = chunkedByteBuffer.getChunks().filter(_.hasRemaining).iterator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment above, saying that we do this filter because read assumes chunks has no empty chunk?

private[this] var currentChunk: ByteBuffer = {
if (chunks.hasNext) {
chunks.next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ChunkedByteBufferSuite extends SparkFunSuite with SharedSparkContext {
val empty = ByteBuffer.wrap(Array.empty[Byte])
val bytes1 = ByteBuffer.wrap(Array.tabulate(256)(_.toByte))
val bytes2 = ByteBuffer.wrap(Array.tabulate(128)(_.toByte))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(empty, bytes1, bytes2))
val chunkedByteBuffer = new ChunkedByteBuffer(Array(empty, bytes1, empty, bytes2))
assert(chunkedByteBuffer.size === bytes1.limit() + bytes2.limit())

val inputStream = chunkedByteBuffer.toInputStream(dispose = false)
Expand Down