Polishing

This commit is contained in:
Juergen Hoeller
2020-05-18 15:15:46 +02:00
parent 4ec02a7e53
commit 4ad7deda4c
7 changed files with 28 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,12 +46,12 @@ import org.springframework.lang.Nullable;
*/
public class ServerSentEventHttpMessageReader implements HttpMessageReader<Object> {
private static final ResolvableType STRING_TYPE = ResolvableType.forClass(String.class);
private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly();
private static final ResolvableType STRING_TYPE = ResolvableType.forClass(String.class);
@Nullable
private final Decoder<?> decoder;
@@ -129,7 +129,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
sseBuilder.event(line.substring(6).trim());
}
else if (line.startsWith("retry:")) {
sseBuilder.retry(Duration.ofMillis(Long.valueOf(line.substring(6).trim())));
sseBuilder.retry(Duration.ofMillis(Long.parseLong(line.substring(6).trim())));
}
else if (line.startsWith(":")) {
comment = (comment != null ? comment : new StringBuilder());
@@ -142,7 +142,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
if (shouldWrap) {
if (comment != null) {
sseBuilder.comment(comment.toString().substring(0, comment.length() - 1));
sseBuilder.comment(comment.substring(0, comment.length() - 1));
}
return decodedData.map(o -> {
sseBuilder.data(o);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -184,7 +184,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
private Mono<DataBuffer> encodeText(CharSequence text, MediaType mediaType, DataBufferFactory bufferFactory) {
Assert.notNull(mediaType.getCharset(), "Expected MediaType with charset");
byte[] bytes = text.toString().getBytes(mediaType.getCharset());
return Mono.just(bufferFactory.wrap(bytes)); // wrapping, not allocating
return Mono.just(bufferFactory.wrap(bytes)); // wrapping, not allocating
}
@Override