Class BufferUtils

java.lang.Object
de.murmelmeister.murmelapi.utils.BufferUtils

public final class BufferUtils extends Object
Utility class for reading and writing UTF-8 strings to/from ByteBuffer.
  • Constructor Details

    • BufferUtils

      public BufferUtils()
  • Method Details

    • encodeUTF

      public static byte[] encodeUTF(String value)
      Encodes the given string into a UTF-8 byte array prefixed with its length.

      The resulting byte array begins with a 4-byte integer representing the length of the UTF-8 encoded string, followed by the UTF-8 encoded bytes of the string.

      Parameters:
      value - The string to encode
      Returns:
      A byte array containing the UTF-8 encoded string prefixed with its length
    • decodeUTF

      public static String decodeUTF(byte[] bytes)
      Decodes a UTF-8 encoded string from the given byte array.

      The byte array is expected to start with a 4-byte integer that specifies the length of the UTF-8 encoded string, followed by the string's byte representation.

      Parameters:
      bytes - The byte array containing the UTF-8 encoded string, prefixed with its length
      Returns:
      The decoded string