@@ -20,58 +20,109 @@ public interface BodyTransformers {
2020 */
2121 long DEFAULT_MAX_BUFFERED_SIZE = 256 * 1024 ;
2222
23+ /**
24+ * Like {@link #transform(MediaType, MediaType, long, Function)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
25+ */
2326 @ GenIgnore (GenIgnore .PERMITTED_TYPE )
24- static BodyTransformer transform (MediaType consumedMediaType , MediaType producedMediaType , Function <Buffer , Buffer > transformer ) {
25- return transform (consumedMediaType , producedMediaType , DEFAULT_MAX_BUFFERED_SIZE , transformer );
27+ static BodyTransformer transform (MediaType consumes , MediaType produces , Function <Buffer , Buffer > transformer ) {
28+ return transform (consumes , produces , DEFAULT_MAX_BUFFERED_SIZE , transformer );
2629 }
2730
31+ /**
32+ * <p>Create a body transformer that transforms {@code consumes} media type to the {@code produces} media type, by
33+ * applying the {@code transformer} function.</p>
34+ *
35+ * <p>The transformer buffers up to {@code maxBufferedBytes} and then apply the {@code transformer} function. When
36+ * the body exceeds the limit, the transformes signal an error and fail the transformation.</p>
37+ *
38+ * @param consumes the consumed media type
39+ * @param produces the produced media type
40+ * @param maxBufferedBytes the maximum amount of bytes buffered by the body transformer
41+ * @param transformer the transformer
42+ * @return the body transformer
43+ */
2844 @ GenIgnore (GenIgnore .PERMITTED_TYPE )
29- static BodyTransformer transform (MediaType consumedMediaType , MediaType producedMediaType , long maxBufferedBytes , Function <Buffer , Buffer > transformer ) {
30- return new BodyTransformerImpl (transformer , maxBufferedBytes , consumedMediaType , producedMediaType );
45+ static BodyTransformer transform (MediaType consumes , MediaType produces , long maxBufferedBytes , Function <Buffer , Buffer > transformer ) {
46+ return new BodyTransformerImpl (transformer , maxBufferedBytes , consumes , produces );
3147 }
3248
3349 /**
34- * Create a transformer that transforms JSON object to JSON object, the transformer accepts and produces {@code application/json}.
50+ * Create a body transformer that transforms JSON object to JSON object, the transformer consumes and produces
51+ * {@code application/json}.
3552 *
36- * @param fn the operation to transform data
53+ * @param maxBufferedBytes the maximum amount of bytes buffered by the body transformer
54+ * @param transformer the transformer function
3755 * @return the transformer instance
3856 */
39- static BodyTransformer jsonObject (Function <JsonObject , JsonObject > fn ) {
40- return BodyTransformerImpl .transformJsonObject (fn );
57+ static BodyTransformer jsonObject (long maxBufferedBytes , Function <JsonObject , JsonObject > transformer ) {
58+ return BodyTransformerImpl .transformJsonObject (maxBufferedBytes , transformer );
4159 }
4260
4361 /**
44- * Create a transformer that transforms JSON array to JSON array, the transformer accepts and produces {@code application/json}.
62+ * Like {@link #jsonObject(long, Function)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
63+ */
64+ static BodyTransformer jsonObject (Function <JsonObject , JsonObject > transformer ) {
65+ return jsonObject (DEFAULT_MAX_BUFFERED_SIZE , transformer );
66+ }
67+
68+ /**
69+ * Create a body transformer that transforms JSON array to JSON array, the transformer consumes and produces
70+ * {@code application/json}.
4571 *
46- * @param fn the operation to transform data
72+ * @param maxBufferedBytes the maximum amount of bytes buffered by the body transformer
73+ * @param transformer the transformer function
4774 * @return the transformer instance
4875 */
49- static BodyTransformer jsonArray (Function <JsonArray , JsonArray > fn ) {
50- return BodyTransformerImpl .transformJsonArray (fn );
76+ static BodyTransformer jsonArray (long maxBufferedBytes , Function <JsonArray , JsonArray > transformer ) {
77+ return BodyTransformerImpl .transformJsonArray (maxBufferedBytes , transformer );
78+ }
79+
80+ /**
81+ * Like {@link #jsonArray(long, Function)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
82+ */
83+ static BodyTransformer jsonArray (Function <JsonArray , JsonArray > transformer ) {
84+ return jsonArray (DEFAULT_MAX_BUFFERED_SIZE , transformer );
5185 }
5286
5387 /**
54- * Create a transformer that transforms JSON value to JSON value, the transformer accepts and produces {@code application/json}.
88+ * Create a body transformer that transforms JSON value to JSON value, the transformer consumes and produces
89+ * {@code application/json}.
5590 *
56- * @param fn the operation to transform data
91+ * @param maxBufferedBytes the maximum amount of bytes buffered by the body transformer
92+ * @param transformer the transformer function
5793 * @return the transformer instance
5894 */
59- static BodyTransformer jsonValue (Function <Object , Object > fn ) {
60- return BodyTransformerImpl .transformJson ( fn );
95+ static BodyTransformer jsonValue (long maxBufferedBytes , Function <Object , Object > transformer ) {
96+ return BodyTransformerImpl .transformJsonValue ( maxBufferedBytes , transformer );
6197 }
6298
6399 /**
64- * Create a transformer that transforms text to text, the transformer accepts and produces {@code text/plain}.
100+ * Like {@link #jsonValue(long, Function)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
101+ */
102+ static BodyTransformer jsonValue (Function <Object , Object > transformer ) {
103+ return jsonValue (DEFAULT_MAX_BUFFERED_SIZE , transformer );
104+ }
105+
106+ /**
107+ * Create a transformer that transforms text to text, the transformer consumes and produces {@code text/plain}.
65108 *
66- * @param fn the operation to transform data
109+ * @param maxBufferedBytes the maximum amount of bytes buffered by the body transformer
110+ * @param transformer the transformer function
67111 * @return the transformer instance
68112 */
69- static BodyTransformer text (Function <String , String > fn , String encoding ) {
70- return BodyTransformerImpl .transformText (encoding , fn );
113+ static BodyTransformer text (long maxBufferedBytes , Function <String , String > transformer , String encoding ) {
114+ return BodyTransformerImpl .transformText (maxBufferedBytes , encoding , transformer );
115+ }
116+
117+ /**
118+ * Like {@link #text(long, Function, String)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
119+ */
120+ static BodyTransformer text (Function <String , String > transformer , String encoding ) {
121+ return text (DEFAULT_MAX_BUFFERED_SIZE , transformer , encoding );
71122 }
72123
73124 /**
74- * Create a transformer that discards the body, the transformer accepts any media type.
125+ * Create a transformer that discards the body, the transformer consumes any media type.
75126 *
76127 * @return the transformer instance
77128 */
0 commit comments