Class BufferUtils

java.lang.Object
de.linusdev.lutils.struct.utils.BufferUtils

public class BufferUtils extends Object
Util class for creating, slicing and aligning Buffer
  • Constructor Details

    • BufferUtils

      public BufferUtils()
  • Method Details

    • createAligned

      @NotNull public static @NotNull ByteBuffer createAligned(int capacity, long alignment)
      creates an aligned direct ByteBuffer
      Parameters:
      capacity - the capacity of the buffer
      alignment - the alignment of the buffer address
      Returns:
      an aligned buffer with given capacity
    • getHeapAddress

      public static long getHeapAddress(@NotNull @NotNull ByteBuffer buffer)
      Parameters:
      buffer - ByteBuffer to 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 whole ByteBuffer.
      Parameters:
      str - ByteBuffer containing the string
      endsWithZero - true if 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 13 Buffer.slice(int, int) method.
      Parameters:
      buffer - ByteBuffer to slice
      start - start pos
      length - index
      Returns:
      slice of given buffer