Skip to content

Commit 350944b

Browse files
committed
move read-only operations from RBB.Mutable to RBB
Signed-off-by: Ludovic Orban <[email protected]>
1 parent 3d02739 commit 350944b

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java

+20-29
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,24 @@ default void clear()
332332
BufferUtil.clear(getByteBuffer());
333333
}
334334

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+
335353
/**
336354
* <p>Skips, advancing the ByteBuffer position, the given number of bytes.</p>
337355
*
@@ -517,23 +535,6 @@ default String toDetailString()
517535
*/
518536
interface Mutable extends RetainableByteBuffer
519537
{
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-
537538
/**
538539
* Add the passed {@link ByteBuffer} to this buffer, growing this buffer if necessary and possible.
539540
* The source {@link ByteBuffer} is passed by reference and the caller gives up "ownership", so implementations of
@@ -799,23 +800,13 @@ public Mutable asMutable()
799800
@Override
800801
public boolean isFull()
801802
{
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();
808804
}
809805

810806
@Override
811807
public long space()
812808
{
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();
819810
}
820811

821812
@Override

0 commit comments

Comments
 (0)