Class BufferUtils


  • public final class BufferUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BufferUtils()
      No instances.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.nio.CharBuffer bytesToChars​(java.nio.charset.CharsetDecoder decoder, java.nio.ByteBuffer bytes, java.nio.CharBuffer chars)
      Convert byte buffer's content into characters.
      static java.nio.ByteBuffer charsToBytes​(java.nio.charset.CharsetEncoder encoder, java.nio.CharBuffer chars, java.nio.ByteBuffer bytes)
      Convert chars into bytes.
      static java.nio.ByteBuffer clearAndEnsureCapacity​(java.nio.ByteBuffer buffer, int elements)
      Ensure the buffer's capacity is large enough to hold a given number of elements.
      static java.nio.CharBuffer clearAndEnsureCapacity​(java.nio.CharBuffer buffer, int elements)
      Ensure the buffer's capacity is large enough to hold a given number of elements.
      (package private) static int sharedPrefixLength​(java.nio.ByteBuffer a, int aStart, java.nio.ByteBuffer b, int bStart)
      Compute the length of the shared prefix between two byte sequences.
      (package private) static int sharedPrefixLength​(java.nio.ByteBuffer a, java.nio.ByteBuffer b)
      Compute the length of the shared prefix between two byte sequences.
      static byte[] toArray​(java.nio.ByteBuffer buffer)  
      static java.lang.String toString​(java.nio.ByteBuffer buffer, java.nio.charset.Charset charset)  
      static java.lang.String toString​(java.nio.CharBuffer buffer)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BufferUtils

        private BufferUtils()
        No instances.
    • Method Detail

      • clearAndEnsureCapacity

        public static java.nio.ByteBuffer clearAndEnsureCapacity​(java.nio.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 java.nio.CharBuffer clearAndEnsureCapacity​(java.nio.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 java.lang.String toString​(java.nio.ByteBuffer buffer,
                                                java.nio.charset.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 java.lang.String toString​(java.nio.CharBuffer buffer)
      • toArray

        public static byte[] toArray​(java.nio.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​(java.nio.ByteBuffer a,
                                      int aStart,
                                      java.nio.ByteBuffer b,
                                      int bStart)
        Compute the length of the shared prefix between two byte sequences.
      • sharedPrefixLength

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

        public static java.nio.CharBuffer bytesToChars​(java.nio.charset.CharsetDecoder decoder,
                                                       java.nio.ByteBuffer bytes,
                                                       java.nio.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 java.nio.ByteBuffer charsToBytes​(java.nio.charset.CharsetEncoder encoder,
                                                       java.nio.CharBuffer chars,
                                                       java.nio.ByteBuffer bytes)
                                                throws UnmappableInputException
        Convert chars into bytes.
        Throws:
        UnmappableInputException