Package de.linusdev.lutils.struct.utils
Class BufferUtils
java.lang.Object
de.linusdev.lutils.struct.utils.BufferUtils
Util class for creating, slicing and aligning
Buffer-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull ByteBuffercreateAligned(int capacity, long alignment) creates an aligned directByteBufferstatic longgetHeapAddress(@NotNull ByteBuffer buffer) static @NotNull StringreadString(@NotNull ByteBuffer str, boolean endsWithZero) The string must fill the wholeByteBuffer.static @NotNull ByteBufferslice(@NotNull ByteBuffer buffer, int start, int length) Works the same as the java 13Buffer.slice(int, int)method.
-
Constructor Details
-
BufferUtils
public BufferUtils()
-
-
Method Details
-
createAligned
creates an aligned directByteBuffer- Parameters:
capacity- the capacity of the bufferalignment- the alignment of the buffer address- Returns:
- an aligned buffer with given capacity
-
getHeapAddress
- Parameters:
buffer-ByteBufferto get the address of- Returns:
- the address of given
buffer
-
readString
@NotNull public static @NotNull String readString(@NotNull @NotNull ByteBuffer str, boolean endsWithZero) The string must fill the wholeByteBuffer.- Parameters:
str-ByteBuffercontaining the stringendsWithZero-trueif the string ends with a 0 character (this character will then be removed.)- Returns:
String
-
slice
@NotNull public static @NotNull ByteBuffer slice(@NotNull @NotNull ByteBuffer buffer, int start, int length) Works the same as the java 13Buffer.slice(int, int)method.- Parameters:
buffer-ByteBufferto slicestart- start poslength- index- Returns:
- slice of given buffer
-