Class BufferUtils

java.lang.Object
morfologik.stemming.BufferUtils

public final class BufferUtils extends Object
  • Constructor Details

    • BufferUtils

      private BufferUtils()
      No instances.
  • Method Details

    • clearAndEnsureCapacity

      public static ByteBuffer clearAndEnsureCapacity(ByteBuffer buffer, int elements)
      Ensure the buffer's capacity is large enough to hold a given number of elements. If the input buffer is not large enough, a new buffer is allocated and returned.
      Parameters:
      elements - The required number of elements to be appended to the buffer.
      buffer - The buffer to check or null if a new buffer should be allocated.
      Returns:
      Returns the same buffer or a new buffer with the given capacity.
    • clearAndEnsureCapacity

      public static CharBuffer clearAndEnsureCapacity(CharBuffer buffer, int elements)
      Ensure the buffer's capacity is large enough to hold a given number of elements. If the input buffer is not large enough, a new buffer is allocated and returned.
      Parameters:
      elements - The required number of elements to be appended to the buffer.
      buffer - The buffer to check or null if a new buffer should be allocated.
      Returns:
      Returns the same buffer or a new buffer with the given capacity.
    • toString

      public static String toString(ByteBuffer buffer, Charset charset)
      Parameters:
      buffer - The buffer to convert to a string.
      charset - The charset to use when converting bytes to characters.
      Returns:
      A string representation of buffer's content.
    • toString

      public static String toString(CharBuffer buffer)
    • toArray

      public static byte[] toArray(ByteBuffer buffer)
      Parameters:
      buffer - The buffer to read from.
      Returns:
      Returns the remaining bytes from the buffer copied to an array.
    • sharedPrefixLength

      static int sharedPrefixLength(ByteBuffer a, int aStart, ByteBuffer b, int bStart)
      Compute the length of the shared prefix between two byte sequences.
    • sharedPrefixLength

      static int sharedPrefixLength(ByteBuffer a, ByteBuffer b)
      Compute the length of the shared prefix between two byte sequences.
    • bytesToChars

      public static CharBuffer bytesToChars(CharsetDecoder decoder, ByteBuffer bytes, CharBuffer chars)
      Convert byte buffer's content into characters. The input buffer's bytes are not consumed (mark is set and reset).
    • charsToBytes

      public static ByteBuffer charsToBytes(CharsetEncoder encoder, CharBuffer chars, ByteBuffer bytes) throws UnmappableInputException
      Convert chars into bytes.
      Throws:
      UnmappableInputException