@@ -20,58 +20,109 @@ public interface BodyTransformers {
20
20
*/
21
21
long DEFAULT_MAX_BUFFERED_SIZE = 256 * 1024 ;
22
22
23
+ /**
24
+ * Like {@link #transform(MediaType, MediaType, long, Function)} with {@link #DEFAULT_MAX_BUFFERED_SIZE} maximum buffered bytes.
25
+ */
23
26
@ 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 );
26
29
}
27
30
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
+ */
28
44
@ 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 );
31
47
}
32
48
33
49
/**
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}.
35
52
*
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
37
55
* @return the transformer instance
38
56
*/
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 );
41
59
}
42
60
43
61
/**
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}.
45
71
*
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
47
74
* @return the transformer instance
48
75
*/
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 );
51
85
}
52
86
53
87
/**
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}.
55
90
*
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
57
93
* @return the transformer instance
58
94
*/
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 );
61
97
}
62
98
63
99
/**
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}.
65
108
*
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
67
111
* @return the transformer instance
68
112
*/
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 );
71
122
}
72
123
73
124
/**
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.
75
126
*
76
127
* @return the transformer instance
77
128
*/
0 commit comments