Skip to content

Commit 583b09a

Browse files
committed
Add scaladoc note about buffer mutability
1 parent 03885df commit 583b09a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/shared/src/main/scala/fs2/Chunk.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu
306306
case _ => Chunk.ArraySlice(toArray, 0, size)
307307
}
308308

309-
/** Converts this chunk to a `java.nio.ByteBuffer`. */
309+
/** Converts this chunk to a `java.nio.ByteBuffer`.
310+
* @note that even "read-only" interaction with a `ByteBuffer` may increment its `position`,
311+
* so this method should be considered as unsafely allocating mutable state.
312+
*/
310313
def toByteBuffer[B >: O](implicit ev: B =:= Byte): JByteBuffer =
311314
this match {
312315
case c: Chunk.ArraySlice[_] if c.values.isInstanceOf[Array[Byte]] =>
@@ -325,7 +328,10 @@ abstract class Chunk[+O] extends Serializable with ChunkPlatform[O] with ChunkRu
325328
JByteBuffer.wrap(this.asInstanceOf[Chunk[Byte]].toArray, 0, size)
326329
}
327330

328-
/** Converts this chunk to a `java.nio.CharBuffer`. */
331+
/** Converts this chunk to a `java.nio.CharBuffer`.
332+
* @note that even "read-only" interaction with a `CharBuffer` may increment its position,
333+
* so this method should be considered as unsafely allocating mutable state.
334+
*/
329335
def toCharBuffer[B >: O](implicit ev: B =:= Char): JCharBuffer =
330336
this match {
331337
case c: Chunk.ArraySlice[_] if c.values.isInstanceOf[Array[Char]] =>

0 commit comments

Comments
 (0)