Package org.springframework.core.io.buffer

# Class DefaultDataBufferFactory

java.lang.Object
org.springframework.core.io.buffer.DefaultDataBufferFactory

All Implemented Interfaces:
  `DataBufferFactory`

public class DefaultDataBufferFactory extends Object implements DataBufferFactory
Default implementation of the `DataBufferFactory` interface. Allows for specification of the default initial capacity at construction time, as well as whether heap-based or direct buffers are to be preferred.

Since:
  5.0
Author:
  Arjen Poutsma

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_INITIAL_CAPACITY`
The default capacity when none is specified.
`static final DefaultDataBufferFactory`
`sharedInstance`
Shared instance based on the default constructor.

## Constructor Summary

Constructors
Constructor
Description
`DefaultDataBufferFactory()`
Creates a new `DefaultDataBufferFactory` with default settings.
`DefaultDataBufferFactory(boolean preferDirect)`
Creates a new `DefaultDataBufferFactory`, indicating whether direct buffers should be created by `allocateBuffer()` and `allocateBuffer(int)`.
`DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity)`
Creates a new `DefaultDataBufferFactory`, indicating whether direct buffers should be created by `allocateBuffer()` and `allocateBuffer(int)`, and what the capacity is to be used for `allocateBuffer()`.

## Method Summary

Modifier and Type
Method
Description
`DefaultDataBuffer`
`allocateBuffer()`
Deprecated.
`DefaultDataBuffer`
`allocateBuffer(int initialCapacity)`
Allocate a data buffer of the given initial capacity.
`boolean`
`isDirect()`
Indicates whether this factory allocates direct buffers (i.e.
`DefaultDataBuffer`
`join(List<? extends DataBuffer> dataBuffers)`
Return a new `DataBuffer` composed of the `dataBuffers` elements joined together.
`String`
`toString()`
`DefaultDataBuffer`
`wrap(byte[] bytes)`
Wrap the given `byte` array in a `DataBuffer`.
`DefaultDataBuffer`
`wrap(ByteBuffer byteBuffer)`
Wrap the given `ByteBuffer` in a `DataBuffer`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
The default capacity when none is specified.

See Also:
  - `DefaultDataBufferFactory()`
  - `DefaultDataBufferFactory(boolean)`
  - Constant Field Values

### sharedInstance

public static final DefaultDataBufferFactory sharedInstance
Shared instance based on the default constructor.

Since:
  5.3

## Constructor Details

### DefaultDataBufferFactory

public DefaultDataBufferFactory()
Creates a new `DefaultDataBufferFactory` with default settings.

See Also:
  - `sharedInstance`

### DefaultDataBufferFactory

public DefaultDataBufferFactory(boolean preferDirect)
Creates a new `DefaultDataBufferFactory`, indicating whether direct buffers should be created by `allocateBuffer()` and `allocateBuffer(int)`.

Parameters:
  `preferDirect` - `true` if direct buffers are to be preferred; `false` otherwise

### DefaultDataBufferFactory

public DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity)
Creates a new `DefaultDataBufferFactory`, indicating whether direct buffers should be created by `allocateBuffer()` and `allocateBuffer(int)`, and what the capacity is to be used for `allocateBuffer()`.

Parameters:
  `preferDirect` - `true` if direct buffers are to be preferred; `false` otherwise

## Method Details

### allocateBuffer

@Deprecated public DefaultDataBuffer allocateBuffer()
Deprecated.
Description copied from interface: `DataBufferFactory`
Allocate a data buffer of a default initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.

Specified by:
  `allocateBuffer` in interface `DataBufferFactory`
Returns:
  the allocated buffer

### allocateBuffer

public DefaultDataBuffer allocateBuffer(int initialCapacity)
Description copied from interface: `DataBufferFactory`
Allocate a data buffer of the given initial capacity. Depending on the underlying implementation and its configuration, this will be heap-based or direct buffer.

Specified by:
  `allocateBuffer` in interface `DataBufferFactory`
Parameters:
  `initialCapacity` - the initial capacity of the buffer to allocate
Returns:
  the allocated buffer

### wrap

public DefaultDataBuffer wrap(ByteBuffer byteBuffer)
Description copied from interface: `DataBufferFactory`
Wrap the given `ByteBuffer` in a `DataBuffer`. Unlike allocating, wrapping does not use new memory.

Specified by:
  `wrap` in interface `DataBufferFactory`
Parameters:
  `byteBuffer` - the NIO byte buffer to wrap
Returns:
  the wrapped buffer

### wrap

public DefaultDataBuffer wrap(byte[] bytes)
Description copied from interface: `DataBufferFactory`
Wrap the given `byte` array in a `DataBuffer`. Unlike allocating, wrapping does not use new memory.

Specified by:
  `wrap` in interface `DataBufferFactory`
Parameters:
  `bytes` - the byte array to wrap
Returns:
  the wrapped buffer

### join

public DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers)
Return a new `DataBuffer` composed of the `dataBuffers` elements joined together. Depending on the implementation, the returned buffer may be a single buffer containing all data of the provided buffers, or it may be a true composite that contains references to the buffers.

Note that the given data buffers do not have to be released, as they are released as part of the returned composite.

This implementation creates a single `DefaultDataBuffer` to contain the data in `dataBuffers`.

Specified by:
  `join` in interface `DataBufferFactory`
Parameters:
  `dataBuffers` - the data buffers to be composed
Returns:
  a buffer that is composed of the `dataBuffers` argument

### isDirect

public boolean isDirect()
Description copied from interface: `DataBufferFactory`
Indicates whether this factory allocates direct buffers (i.e. non-heap, native memory).

Specified by:
  `isDirect` in interface `DataBufferFactory`
Returns:
  `true` if this factory allocates direct buffers; `false` otherwise

### toString

public String toString()

Overrides:
  `toString` in class `Object`