42
42
* Bridges between {@link Flow.Publisher Flow.Publisher<T>} and {@link InputStream}.
43
43
*
44
44
* <p>Note that this class has a near duplicate in
45
- * {@link org.springframework.core.io.buffer.InputStreamSubscriber }.
45
+ * {@link org.springframework.core.io.buffer.SubscriberInputStream }.
46
46
*
47
47
* @author Oleh Dokuka
48
48
* @author Rossen Stoyanchev
49
49
* @since 6.2
50
50
* @param <T> the publisher byte buffer type
51
51
*/
52
- final class InputStreamSubscriber <T > extends InputStream implements Flow .Subscriber <T > {
52
+ final class SubscriberInputStream <T > extends InputStream implements Flow .Subscriber <T > {
53
53
54
- private static final Log logger = LogFactory .getLog (InputStreamSubscriber .class );
54
+ private static final Log logger = LogFactory .getLog (SubscriberInputStream .class );
55
55
56
56
private static final Object READY = new Object ();
57
57
@@ -94,12 +94,12 @@ final class InputStreamSubscriber<T> extends InputStream implements Flow.Subscri
94
94
private Throwable error ;
95
95
96
96
97
- private InputStreamSubscriber (Function <T , byte []> mapper , Consumer <T > onDiscardHandler , int prefetch ) {
97
+ private SubscriberInputStream (Function <T , byte []> mapper , Consumer <T > onDiscardHandler , int demand ) {
98
98
this .mapper = mapper ;
99
99
this .onDiscardHandler = onDiscardHandler ;
100
- this .prefetch = prefetch ;
101
- this .limit = (prefetch == Integer .MAX_VALUE ? Integer .MAX_VALUE : prefetch - (prefetch >> 2 ));
102
- this .queue = new ArrayBlockingQueue <>(prefetch );
100
+ this .prefetch = demand ;
101
+ this .limit = (demand == Integer .MAX_VALUE ? Integer .MAX_VALUE : demand - (demand >> 2 ));
102
+ this .queue = new ArrayBlockingQueue <>(demand );
103
103
this .lock = new ReentrantLock (false );
104
104
}
105
105
@@ -122,17 +122,16 @@ private InputStreamSubscriber(Function<T, byte[]> mapper, Consumer<T> onDiscardH
122
122
* @param publisher the source of {@link DataBuffer} which should be represented as an {@link InputStream}
123
123
* @param mapper function to transform <T> element to {@code byte[]}. Note, <T> should be released during the mapping if needed.
124
124
* @param onDiscardHandler <T> element consumer if returned {@link InputStream} is closed prematurely.
125
- * @param bufferSize the maximum amount of <T> elements prefetched in advance and stored inside {@link InputStream}
125
+ * @param demand the maximum number of buffers to request from the Publisher and buffer on an ongoing basis
126
126
* @return an {@link InputStream} instance representing given {@link Flow.Publisher} messages
127
127
*/
128
- public static <T > InputStream subscribeTo (Flow .Publisher <T > publisher , Function <T , byte []> mapper , Consumer <T > onDiscardHandler , int bufferSize ) {
129
-
128
+ public static <T > InputStream subscribeTo (Flow .Publisher <T > publisher , Function <T , byte []> mapper , Consumer <T > onDiscardHandler , int demand ) {
130
129
Assert .notNull (publisher , "Flow.Publisher must not be null" );
131
130
Assert .notNull (mapper , "mapper must not be null" );
132
131
Assert .notNull (onDiscardHandler , "onDiscardHandler must not be null" );
133
- Assert .isTrue (bufferSize > 0 , "bufferSize must be greater than 0" );
132
+ Assert .isTrue (demand > 0 , "demand must be greater than 0" );
134
133
135
- InputStreamSubscriber <T > iss = new InputStreamSubscriber <>(mapper , onDiscardHandler , bufferSize );
134
+ SubscriberInputStream <T > iss = new SubscriberInputStream <>(mapper , onDiscardHandler , demand );
136
135
publisher .subscribe (iss );
137
136
return iss ;
138
137
}
0 commit comments