@@ -332,6 +332,24 @@ default void clear()
332
332
BufferUtil .clear (getByteBuffer ());
333
333
}
334
334
335
+ /**
336
+ * @return the number of bytes that can be added, appended or put into this buffer,
337
+ * assuming it is {@link #asMutable() mutable}.
338
+ */
339
+ default long space ()
340
+ {
341
+ return capacity () - remaining ();
342
+ }
343
+
344
+ /**
345
+ * @return true if no more bytes can be added, appended or put to this buffer,
346
+ * assuming it is {@link #asMutable() mutable}.
347
+ */
348
+ default boolean isFull ()
349
+ {
350
+ return space () == 0L ;
351
+ }
352
+
335
353
/**
336
354
* <p>Skips, advancing the ByteBuffer position, the given number of bytes.</p>
337
355
*
@@ -517,23 +535,6 @@ default String toDetailString()
517
535
*/
518
536
interface Mutable extends RetainableByteBuffer
519
537
{
520
- /**
521
- * @return the number of bytes that can be added, appended or put into this buffer.
522
- */
523
- default long space ()
524
- {
525
- return capacity () - remaining ();
526
- }
527
-
528
- /**
529
- * @return true if the {@link #size()} is equals to the {@link #maxSize()} and no more bytes can be added, appended
530
- * or put to this buffer.
531
- */
532
- default boolean isFull ()
533
- {
534
- return space () == 0 ;
535
- }
536
-
537
538
/**
538
539
* Add the passed {@link ByteBuffer} to this buffer, growing this buffer if necessary and possible.
539
540
* The source {@link ByteBuffer} is passed by reference and the caller gives up "ownership", so implementations of
@@ -799,23 +800,13 @@ public Mutable asMutable()
799
800
@ Override
800
801
public boolean isFull ()
801
802
{
802
- // Do not call asMutable() as it would throw if retained
803
- // while this operation is read-only so we do not care
804
- // about being retained or not.
805
- if (getWrapped () instanceof Mutable mutable )
806
- return mutable .isFull ();
807
- return true ;
803
+ return getWrapped ().isFull ();
808
804
}
809
805
810
806
@ Override
811
807
public long space ()
812
808
{
813
- // Do not call asMutable() as it would throw if retained
814
- // while this operation is read-only so we do not care
815
- // about being retained or not.
816
- if (getWrapped () instanceof Mutable mutable )
817
- return mutable .space ();
818
- return 0L ;
809
+ return getWrapped ().space ();
819
810
}
820
811
821
812
@ Override
0 commit comments