Interface DataBufFactory
public interface DataBufFactory
A factory for creation of data buf instances in various forms.
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionCreates a readonly copy of the given data buffer.Creates an empty buffer which can be expanded by writing to it.createWithExpectedSize(int byteSize) Creates an empty mutable data buffer which pre-allocates the specified amount of expected bytes rather than dynamically growing during write operations.static @NonNull DataBufFactoryGet the default factory for data buffers integrated into cloudnet.fromBytes(byte[] bytes) Creates a new readonly buffer wrapping the given byte array and using it as it's data source.mutableCopyOf(@NonNull DataBuf dataBuf) Creates a mutable copy of the given data buffer.
-
Method Details
-
defaultFactory
Get the default factory for data buffers integrated into cloudnet. This is current a factory which wraps netty byte buffers.Returned buffers created by this factory should NEVER get cast to any implementation of a buffer as the factory might change and return different buffers when we should ever decide to use another networking library for CloudNet.
- Returns:
- the default integrated data buf factory.
-
createEmpty
Creates an empty buffer which can be expanded by writing to it.- Returns:
- a new, empty data buf.
-
fromBytes
-
copyOf
Creates a readonly copy of the given data buffer. The copied variant of the buffer will start the read process from the first byte rather than re-using the current index of the original buffer.A factory is only expected to be able to copy a buffer created by it. Cross factory copy might be possible but is not a requirement. Use
factory.createOf(buffer.toByteArray)if you want to be sure that the buffer can be copied.- Parameters:
dataBuf- the buffer to copy.- Returns:
- a copied variant of the given buffer.
- Throws:
IllegalArgumentException- if the buffer cannot be copied.NullPointerException- if the given buffer is null.
-
mutableCopyOf
Creates a mutable copy of the given data buffer. The copied variant of the buffer will start the read and write process from the first byte rather than re-using the current index of the original buffer.A factory is only expected to be able to copy a buffer created by it. Cross factory copy might be possible but is not a requirement. Use
factory.createOf(buffer.toByteArray)if you want to be sure that the buffer can be copied.- Parameters:
dataBuf- the buffer to copy.- Returns:
- a copied variant of the given buffer.
- Throws:
IllegalArgumentException- if the buffer cannot be copied.NullPointerException- if the given buffer is null.
-
createWithExpectedSize
Creates an empty mutable data buffer which pre-allocates the specified amount of expected bytes rather than dynamically growing during write operations.- Parameters:
byteSize- the expected amount of bytes which get written.- Returns:
- a new, mutable buffer with the given amount of bytes pre-allocated.
-