Shared static instance of DefaultDataBufferFactory
This commit is contained in:
@@ -271,7 +271,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
|
||||
|
||||
private static class EndFrameBuffer extends DataBufferWrapper {
|
||||
|
||||
private static final DataBuffer BUFFER = new DefaultDataBufferFactory().wrap(new byte[0]);
|
||||
private static final DataBuffer BUFFER = DefaultDataBufferFactory.sharedInstance.wrap(new byte[0]);
|
||||
|
||||
private byte[] delimiter;
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -38,6 +38,12 @@ public class DefaultDataBufferFactory implements DataBufferFactory {
|
||||
*/
|
||||
public static final int DEFAULT_INITIAL_CAPACITY = 256;
|
||||
|
||||
/**
|
||||
* Shared instance based on the default constructor.
|
||||
* @since 5.3
|
||||
*/
|
||||
public static final DefaultDataBufferFactory sharedInstance = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
private final boolean preferDirect;
|
||||
|
||||
@@ -46,6 +52,7 @@ public class DefaultDataBufferFactory implements DataBufferFactory {
|
||||
|
||||
/**
|
||||
* Creates a new {@code DefaultDataBufferFactory} with default settings.
|
||||
* @see #sharedInstance
|
||||
*/
|
||||
public DefaultDataBufferFactory() {
|
||||
this(false);
|
||||
|
||||
@@ -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.
|
||||
@@ -27,9 +27,6 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public class LimitedDataBufferListTests {
|
||||
|
||||
private final static DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
|
||||
@Test
|
||||
void limitEnforced() {
|
||||
Assertions.assertThatThrownBy(() -> new LimitedDataBufferList(5).add(toDataBuffer("123456")))
|
||||
@@ -51,7 +48,8 @@ public class LimitedDataBufferListTests {
|
||||
|
||||
|
||||
private static DataBuffer toDataBuffer(String value) {
|
||||
return bufferFactory.wrap(value.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
return DefaultDataBufferFactory.sharedInstance.wrap(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user