Top Description Fields Constructors Methods
org.springframework.core.io.buffer

public Class LimitedDataBufferList

extends ArrayList<DataBuffer>
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.util.ArrayList, .Collection, .List, java.util.function.Predicate, reactor.core.publisher.Flux

Custom List to collect data buffers with and enforce a limit on the total number of bytes buffered. For use with "collect" or other buffering operators in declarative APIs, e.g. Flux.

Adding elements increases the byte count and if the limit is exceeded, DataBufferLimitException is raised. clear() resets the count. Remove and set are not supported.

Note

This class does not automatically release the buffers it contains. It is usually preferable to use hooks such as Flux#doOnDiscard that also take care of cancel and error signals, or otherwise releaseAndClear() can be used.

Author
Rossen Stoyanchev
Since
5.1.11

Field Summary

Modifier and TypeField and Description
private int
private final int

Constructor Summary

AccessConstructor and Description
public
LimitedDataBufferList(int maxByteCount)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(DataBuffer
element to be appended to this list
buffer
)

Overrides java.util.ArrayList.add.

Implements java.util.List.add, java.util.Collection.add.

Appends the specified element to the end of this list.

public void
add(int
index at which the specified element is to be inserted
index
,
DataBuffer
element to be inserted
buffer
)

Overrides java.util.ArrayList.add.

Implements java.util.List.add.

Inserts the specified element at the specified position in this list.

public boolean
addAll(Collection<? extends DataBuffer>
collection containing elements to be added to this list
collection
)

Overrides java.util.ArrayList.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.

public boolean
addAll(int
index at which to insert the first element from the specified collection
index
,
Collection<? extends DataBuffer>
collection containing elements to be added to this list
collection
)

Overrides java.util.ArrayList.addAll.

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list, starting at the specified position.

public void
clear()

Overrides java.util.ArrayList.clear.

Implements java.util.List.clear, java.util.Collection.clear.

Removes all of the elements from this list.

private void
public void
releaseAndClear()

Shortcut to release all data buffers and then clear().

public DataBuffer
remove(int
the index of the element to be removed
index
)

Overrides java.util.ArrayList.remove.

Implements java.util.List.remove.

Removes the element at the specified position in this list.

public boolean
remove(Object
element to be removed from this list, if present
o
)

Overrides java.util.ArrayList.remove.

Implements java.util.List.remove, java.util.Collection.remove.

Removes the first occurrence of the specified element from this list, if it is present.

public boolean
removeAll(Collection<?>
collection containing elements to be removed from this list
c
)

Overrides java.util.ArrayList.removeAll.

Implements java.util.List.removeAll, java.util.Collection.removeAll.

Removes from this list all of its elements that are contained in the specified collection.

public boolean
removeIf(Predicate<? super DataBuffer>
a predicate which returns true for elements to be removed
filter
)

Overrides java.util.ArrayList.removeIf.

Overrides default java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate (optional operation).

protected void
removeRange(int
index of first element to be removed
fromIndex
,
int
index after last element to be removed
toIndex
)

Overrides java.util.ArrayList.removeRange.

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.

public DataBuffer
set(int
index of the element to replace
index
,
DataBuffer
element to be stored at the specified position
element
)

Overrides java.util.ArrayList.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element.

private void
updateCount(int bytesToAdd)

Inherited from java.util.ArrayList:
addFirstaddLastclonecontainsensureCapacityequalsforEachgetgetFirstgetLasthashCodeindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorremoveFirstremoveLastreplaceAllretainAllsizesortspliteratorsubListtoArraytoArraytrimToSize

Field Detail

byteCountback to summary
private int byteCount
maxByteCountback to summary
private final int maxByteCount

Constructor Detail

LimitedDataBufferListback to summary
public LimitedDataBufferList(int maxByteCount)

Method Detail

addback to summary
public boolean add(DataBuffer buffer)

Overrides java.util.ArrayList.add.

Implements java.util.List.add, java.util.Collection.add.

Doc from java.util.ArrayList.add.

Appends the specified element to the end of this list.

Parameters
buffer:DataBuffer

element to be appended to this list

Returns:boolean

true (as specified by Collection#add)

Annotations
@Override
addback to summary
public void add(int index, DataBuffer buffer)

Overrides java.util.ArrayList.add.

Implements java.util.List.add.

Doc from java.util.ArrayList.add.

Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

index at which the specified element is to be inserted

buffer:DataBuffer

element to be inserted

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends DataBuffer> collection)

Overrides java.util.ArrayList.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Doc from java.util.ArrayList.addAll.

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this list, and this list is nonempty.)

Parameters
collection:Collection<? extends DataBuffer>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
addAllback to summary
public boolean addAll(int index, Collection<? extends DataBuffer> collection)

Overrides java.util.ArrayList.addAll.

Implements java.util.List.addAll.

Doc from java.util.ArrayList.addAll.

Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.

Parameters
index:int

index at which to insert the first element from the specified collection

collection:Collection<? extends DataBuffer>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
clearback to summary
public void clear()

Overrides java.util.ArrayList.clear.

Implements java.util.List.clear, java.util.Collection.clear.

Doc from java.util.ArrayList.clear.

Removes all of the elements from this list. The list will be empty after this call returns.

Annotations
@Override
raiseLimitExceptionback to summary
private void raiseLimitException()
releaseAndClearback to summary
public void releaseAndClear()

Shortcut to release all data buffers and then clear().

removeback to summary
public DataBuffer remove(int index)

Overrides java.util.ArrayList.remove.

Implements java.util.List.remove.

Doc from java.util.ArrayList.remove.

Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Parameters
index:int

the index of the element to be removed

Returns:DataBuffer

the element that was removed from the list

Annotations
@Override
removeback to summary
public boolean remove(Object o)

Overrides java.util.ArrayList.remove.

Implements java.util.List.remove, java.util.Collection.remove.

Doc from java.util.ArrayList.remove.

Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists). Returns true if this list contained the specified element (or equivalently, if this list changed as a result of the call).

Parameters
o:Object

element to be removed from this list, if present

Returns:boolean

true if this list contained the specified element

Annotations
@Override
removeAllback to summary
public boolean removeAll(Collection<?> c)

Overrides java.util.ArrayList.removeAll.

Implements java.util.List.removeAll, java.util.Collection.removeAll.

Doc from java.util.ArrayList.removeAll.

Removes from this list all of its elements that are contained in the specified collection.

Parameters
c:Collection<?>

collection containing elements to be removed from this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
removeIfback to summary
public boolean removeIf(Predicate<? super DataBuffer> filter)

Overrides java.util.ArrayList.removeIf.

Overrides default java.util.Collection.removeIf.

Doc from java.util.Collection.removeIf.

Removes all of the elements of this collection that satisfy the given predicate (optional operation). Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters
filter:Predicate<? super DataBuffer>

a predicate which returns true for elements to be removed

Returns:boolean

true if any elements were removed

Annotations
@Override
removeRangeback to summary
protected void removeRange(int fromIndex, int toIndex)

Overrides java.util.ArrayList.removeRange.

Doc from java.util.ArrayList.removeRange.

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

Parameters
fromIndex:int

Doc from java.util.AbstractList.removeRange.

index of first element to be removed

toIndex:int

Doc from java.util.AbstractList.removeRange.

index after last element to be removed

Annotations
@Override
setback to summary
public DataBuffer set(int index, DataBuffer element)

Overrides java.util.ArrayList.set.

Implements java.util.List.set.

Doc from java.util.ArrayList.set.

Replaces the element at the specified position in this list with the specified element.

Parameters
index:int

index of the element to replace

element:DataBuffer

element to be stored at the specified position

Returns:DataBuffer

the element previously at the specified position

Annotations
@Override
updateCountback to summary
private void updateCount(int bytesToAdd)