Shared static instance of DefaultDataBufferFactory
This commit is contained in:
@@ -186,7 +186,7 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder {
|
||||
this.body = Flux.just(body).
|
||||
map(s -> {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
return new DefaultDataBufferFactory().wrap(bytes);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.context.i18n.LocaleContext;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.Hints;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpCookie;
|
||||
@@ -151,11 +150,10 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||
public ServerRequest.Builder body(String body) {
|
||||
Assert.notNull(body, "Body must not be null");
|
||||
releaseBody();
|
||||
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
this.body = Flux.just(body).
|
||||
map(s -> {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
return dataBufferFactory.wrap(bytes);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -21,7 +21,6 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.util.DigestUtils;
|
||||
@@ -39,13 +38,12 @@ import org.springframework.util.StreamUtils;
|
||||
*/
|
||||
public class ContentVersionStrategy extends AbstractFileNameVersionStrategy {
|
||||
|
||||
private static final DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<String> getResourceVersion(Resource resource) {
|
||||
Flux<DataBuffer> flux =
|
||||
DataBufferUtils.read(resource, dataBufferFactory, StreamUtils.BUFFER_SIZE);
|
||||
Flux<DataBuffer> flux = DataBufferUtils.read(
|
||||
resource, DefaultDataBufferFactory.sharedInstance, StreamUtils.BUFFER_SIZE);
|
||||
|
||||
return DataBufferUtils.join(flux)
|
||||
.map(buffer -> {
|
||||
byte[] result = new byte[buffer.readableByteCount()];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -29,7 +29,6 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||
@@ -59,8 +58,6 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
|
||||
private final boolean externallyManaged;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor that creates and manages an instance of a Jetty
|
||||
@@ -157,7 +154,8 @@ public class JettyWebSocketClient implements WebSocketClient, Lifecycle {
|
||||
private Object createHandler(URI url, WebSocketHandler handler, MonoProcessor<Void> completion) {
|
||||
return new JettyWebSocketHandlerAdapter(handler, session -> {
|
||||
HandshakeInfo info = createHandshakeInfo(url, session);
|
||||
return new JettyWebSocketSession(session, info, this.bufferFactory, completion);
|
||||
return new JettyWebSocketSession(
|
||||
session, info, DefaultDataBufferFactory.sharedInstance, completion);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -55,8 +55,6 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
private static final Log logger = LogFactory.getLog(StandardWebSocketClient.class);
|
||||
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
private final WebSocketContainer webSocketContainer;
|
||||
|
||||
|
||||
@@ -129,7 +127,7 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
protected StandardWebSocketSession createWebSocketSession(Session session, HandshakeInfo info,
|
||||
MonoProcessor<Void> completion) {
|
||||
|
||||
return new StandardWebSocketSession(session, info, this.bufferFactory, completion);
|
||||
return new StandardWebSocketSession(session, info, DefaultDataBufferFactory.sharedInstance, completion);
|
||||
}
|
||||
|
||||
private ClientEndpointConfig createEndpointConfig(Configurator configurator, List<String> subProtocols) {
|
||||
@@ -140,7 +138,7 @@ public class StandardWebSocketClient implements WebSocketClient {
|
||||
}
|
||||
|
||||
protected DataBufferFactory bufferFactory() {
|
||||
return this.bufferFactory;
|
||||
return DefaultDataBufferFactory.sharedInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -65,8 +65,6 @@ public class UndertowWebSocketClient implements WebSocketClient {
|
||||
|
||||
private final Consumer<ConnectionBuilder> builderConsumer;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with the {@link XnioWorker} to pass to
|
||||
@@ -198,7 +196,8 @@ public class UndertowWebSocketClient implements WebSocketClient {
|
||||
DefaultNegotiation negotiation, WebSocketChannel channel) {
|
||||
|
||||
HandshakeInfo info = createHandshakeInfo(url, negotiation);
|
||||
UndertowWebSocketSession session = new UndertowWebSocketSession(channel, info, this.bufferFactory, completion);
|
||||
DataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance;
|
||||
UndertowWebSocketSession session = new UndertowWebSocketSession(channel, info, bufferFactory, completion);
|
||||
UndertowWebSocketHandlerAdapter adapter = new UndertowWebSocketHandlerAdapter(session);
|
||||
|
||||
channel.getReceiveSetter().set(adapter);
|
||||
|
||||
Reference in New Issue
Block a user