18
18
import io .servicetalk .serializer .api .SerializerDeserializer ;
19
19
import io .servicetalk .serializer .api .StreamingSerializerDeserializer ;
20
20
import io .servicetalk .serializer .utils .FixedLengthStreamingSerializer ;
21
- import io .servicetalk .serializer .utils .StringAsciiSerializer ;
22
- import io .servicetalk .serializer .utils .StringCharsetSerializer ;
23
- import io .servicetalk .serializer .utils .StringUtf8Serializer ;
24
21
import io .servicetalk .serializer .utils .VarIntLengthStreamingSerializer ;
25
22
26
23
import java .nio .charset .Charset ;
39
36
import static io .servicetalk .http .api .HttpHeaderValues .TEXT_PLAIN ;
40
37
import static io .servicetalk .http .api .HttpHeaderValues .TEXT_PLAIN_US_ASCII ;
41
38
import static io .servicetalk .http .api .HttpHeaderValues .TEXT_PLAIN_UTF_8 ;
39
+ import static io .servicetalk .serializer .utils .StringSerializer .stringSerializer ;
42
40
import static java .nio .charset .StandardCharsets .US_ASCII ;
43
41
import static java .nio .charset .StandardCharsets .UTF_8 ;
44
42
@@ -62,30 +60,30 @@ public final class HttpSerializers {
62
60
headers -> headers .set (CONTENT_TYPE , APPLICATION_X_WWW_FORM_URLENCODED_UTF_8 ),
63
61
headers -> hasContentType (headers , APPLICATION_X_WWW_FORM_URLENCODED , UTF_8 ));
64
62
private static final HttpSerializerDeserializer <String > TEXT_UTF_8 =
65
- new DefaultHttpSerializerDeserializer <>(StringUtf8Serializer . INSTANCE ,
63
+ new DefaultHttpSerializerDeserializer <>(stringSerializer ( UTF_8 ) ,
66
64
headers -> headers .set (CONTENT_TYPE , TEXT_PLAIN_UTF_8 ),
67
65
headers -> hasContentType (headers , TEXT_PLAIN , UTF_8 ));
68
66
private static final HttpSerializerDeserializer <String > TEXT_ASCII =
69
- new DefaultHttpSerializerDeserializer <>(StringAsciiSerializer . INSTANCE ,
67
+ new DefaultHttpSerializerDeserializer <>(stringSerializer ( US_ASCII ) ,
70
68
headers -> headers .set (CONTENT_TYPE , TEXT_PLAIN_US_ASCII ),
71
69
headers -> hasContentType (headers , TEXT_PLAIN , US_ASCII ));
72
70
private static final int MAX_BYTES_PER_CHAR_UTF8 = (int ) UTF_8 .newEncoder ().maxBytesPerChar ();
73
71
private static final HttpStreamingSerializerDeserializer <String > TEXT_STREAMING_FIX_LEN_UTF_8 =
74
- streamingSerializer (new FixedLengthStreamingSerializer <>(StringUtf8Serializer . INSTANCE ,
72
+ streamingSerializer (new FixedLengthStreamingSerializer <>(stringSerializer ( UTF_8 ) ,
75
73
str -> str .length () * MAX_BYTES_PER_CHAR_UTF8 ),
76
74
headers -> headers .set (CONTENT_TYPE , APPLICATION_TEXT_FIXED_UTF_8 ),
77
75
headers -> hasContentType (headers , APPLICATION_TEXT_FIXED , UTF_8 ));
78
76
private static final HttpStreamingSerializerDeserializer <String > TEXT_STREAMING_FIX_LEN_ASCII =
79
- streamingSerializer (new FixedLengthStreamingSerializer <>(StringAsciiSerializer . INSTANCE , String ::length ),
77
+ streamingSerializer (new FixedLengthStreamingSerializer <>(stringSerializer ( US_ASCII ) , String ::length ),
80
78
headers -> headers .set (CONTENT_TYPE , APPLICATION_TEXT_FIXED_US_ASCII ),
81
79
headers -> hasContentType (headers , APPLICATION_TEXT_FIXED , US_ASCII ));
82
80
private static final HttpStreamingSerializerDeserializer <String > TEXT_STREAMING_VAR_LEN_UTF_8 =
83
- streamingSerializer (new VarIntLengthStreamingSerializer <>(StringUtf8Serializer . INSTANCE ,
81
+ streamingSerializer (new VarIntLengthStreamingSerializer <>(stringSerializer ( UTF_8 ) ,
84
82
str -> str .length () * MAX_BYTES_PER_CHAR_UTF8 ),
85
83
headers -> headers .set (CONTENT_TYPE , APPLICATION_TEXT_VAR_INT_UTF_8 ),
86
84
headers -> hasContentType (headers , APPLICATION_TEXT_VARINT , UTF_8 ));
87
85
private static final HttpStreamingSerializerDeserializer <String > TEXT_STREAMING_VAR_LEN_ASCII =
88
- streamingSerializer (new VarIntLengthStreamingSerializer <>(StringAsciiSerializer . INSTANCE , String ::length ),
86
+ streamingSerializer (new VarIntLengthStreamingSerializer <>(stringSerializer ( US_ASCII ) , String ::length ),
89
87
headers -> headers .set (CONTENT_TYPE , APPLICATION_TEXT_VAR_INT_US_ASCII ),
90
88
headers -> hasContentType (headers , APPLICATION_TEXT_VARINT , US_ASCII ));
91
89
@@ -114,7 +112,7 @@ public static HttpSerializerDeserializer<Map<String, List<String>>> formUrlEncod
114
112
* href="https://url.spec.whatwg.org/#application/x-www-form-urlencoded">x-www-form-urlencoded specification</a>
115
113
*/
116
114
public static HttpSerializerDeserializer <Map <String , List <String >>> formUrlEncodedSerializer (Charset charset ) {
117
- if (charset == UTF_8 ) {
115
+ if (UTF_8 . equals ( charset ) ) {
118
116
return FORM_ENCODED_UTF_8 ;
119
117
}
120
118
final CharSequence contentType = newAsciiString (APPLICATION_X_WWW_FORM_URLENCODED + "; charset=" +
@@ -152,13 +150,13 @@ public static HttpSerializerDeserializer<String> textSerializerAscii() {
152
150
* @return {@link HttpSerializerDeserializer} that can serialize {@link String}s.
153
151
*/
154
152
public static HttpSerializerDeserializer <String > textSerializer (Charset charset ) {
155
- if (charset == UTF_8 ) {
153
+ if (UTF_8 . equals ( charset ) ) {
156
154
return TEXT_UTF_8 ;
157
- } else if (charset == US_ASCII ) {
155
+ } else if (US_ASCII . equals ( charset ) ) {
158
156
return TEXT_ASCII ;
159
157
}
160
158
final CharSequence contentType = newAsciiString ("text/plain; charset=" + charset .name ());
161
- return new DefaultHttpSerializerDeserializer <>(new StringCharsetSerializer (charset ),
159
+ return new DefaultHttpSerializerDeserializer <>(stringSerializer (charset ),
162
160
headers -> headers .set (CONTENT_TYPE , contentType ),
163
161
headers -> hasContentType (headers , TEXT_PLAIN , charset ));
164
162
}
@@ -221,14 +219,14 @@ public static HttpStreamingSerializerDeserializer<String> textSerializerAsciiVar
221
219
* @see FixedLengthStreamingSerializer
222
220
*/
223
221
public static HttpStreamingSerializerDeserializer <String > textSerializerFixLen (Charset charset ) {
224
- if (charset == UTF_8 ) {
222
+ if (UTF_8 . equals ( charset ) ) {
225
223
return TEXT_STREAMING_FIX_LEN_UTF_8 ;
226
- } else if (charset == US_ASCII ) {
224
+ } else if (US_ASCII . equals ( charset ) ) {
227
225
return TEXT_STREAMING_FIX_LEN_ASCII ;
228
226
}
229
227
final int maxBytesPerChar = (int ) charset .newEncoder ().maxBytesPerChar ();
230
228
CharSequence contentType = newAsciiString (APPLICATION_TEXT_FIXED + "; charset=" + charset .name ());
231
- return streamingSerializer (new FixedLengthStreamingSerializer <>(new StringCharsetSerializer (charset ),
229
+ return streamingSerializer (new FixedLengthStreamingSerializer <>(stringSerializer (charset ),
232
230
str -> str .length () * maxBytesPerChar ),
233
231
headers -> headers .set (CONTENT_TYPE , contentType ),
234
232
headers -> hasContentType (headers , APPLICATION_TEXT_FIXED , charset ));
@@ -244,14 +242,14 @@ public static HttpStreamingSerializerDeserializer<String> textSerializerFixLen(C
244
242
* @see VarIntLengthStreamingSerializer
245
243
*/
246
244
public static HttpStreamingSerializerDeserializer <String > textSerializerVarLen (Charset charset ) {
247
- if (charset == UTF_8 ) {
245
+ if (UTF_8 . equals ( charset ) ) {
248
246
return TEXT_STREAMING_VAR_LEN_UTF_8 ;
249
- } else if (charset == US_ASCII ) {
247
+ } else if (US_ASCII . equals ( charset ) ) {
250
248
return TEXT_STREAMING_VAR_LEN_ASCII ;
251
249
}
252
250
final int maxBytesPerChar = (int ) charset .newEncoder ().maxBytesPerChar ();
253
251
CharSequence contentType = newAsciiString (APPLICATION_TEXT_VARINT + "; charset=" + charset .name ());
254
- return streamingSerializer (new VarIntLengthStreamingSerializer <>(new StringCharsetSerializer (charset ),
252
+ return streamingSerializer (new VarIntLengthStreamingSerializer <>(stringSerializer (charset ),
255
253
str -> str .length () * maxBytesPerChar ),
256
254
headers -> headers .set (CONTENT_TYPE , contentType ),
257
255
headers -> hasContentType (headers , APPLICATION_TEXT_VARINT , charset ));
0 commit comments