Class Buffers


  • public class Buffers
    extends java.lang.Object
    Utility functions to help avoid binary incompatibility due to variadic return types on Java 9. Java 9 introduced new overloads of several Buffer methods on its subclasses. Because those methods return the actual type of the subclass, they are incompatible with Java 8 where no such overloads exist. This utility casts all buffers to Buffer and makes the call from there, avoiding binding directly to the overloads that don't exist on Java 8.
    • Constructor Summary

      Constructors 
      Constructor Description
      Buffers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.nio.Buffer>
      T
      clearBuffer​(T buf)
      Invoke Buffer.clear always using Buffer as the target, to avoid binary incompatibility on Java 8.
      static <T extends java.nio.Buffer>
      T
      flipBuffer​(T buf)
      Invoke Buffer.flip always using Buffer as the target, to avoid binary incompatibility on Java 8.
      static <T extends java.nio.Buffer>
      T
      limitBuffer​(T buf, int limit)
      Invoke Buffer.limit always using Buffer as the target, to avoid binary incompatibility on Java 8.
      static <T extends java.nio.Buffer>
      T
      markBuffer​(T buf)
      Invoke Buffer.mark always using Buffer as the target, to avoid binary incompatibility on Java 8.
      static <T extends java.nio.Buffer>
      T
      positionBuffer​(T buf, int limit)
      Invoke Buffer.position always using Buffer as the target, to avoid binary incompatibility on Java 8.
      static <T extends java.nio.Buffer>
      T
      rewindBuffer​(T buf)
      Invoke Buffer.rewind always using Buffer as the target, to avoid binary incompatibility on Java 8.
      • Methods inherited from class java.lang.Object

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

      • Buffers

        public Buffers()
    • Method Detail

      • clearBuffer

        public static <T extends java.nio.Buffer> T clearBuffer​(T buf)
        Invoke Buffer.clear always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        Returns:
        the buffer
        See Also:
        Buffer.clear()
      • flipBuffer

        public static <T extends java.nio.Buffer> T flipBuffer​(T buf)
        Invoke Buffer.flip always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        Returns:
        the buffer
        See Also:
        Buffer.flip()
      • limitBuffer

        public static <T extends java.nio.Buffer> T limitBuffer​(T buf,
                                                                int limit)
        Invoke Buffer.limit always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        limit - the new limit
        Returns:
        the buffer
        See Also:
        Buffer.limit(int)
      • positionBuffer

        public static <T extends java.nio.Buffer> T positionBuffer​(T buf,
                                                                   int limit)
        Invoke Buffer.position always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        limit - the new limit
        Returns:
        the buffer
        See Also:
        Buffer.position()
      • markBuffer

        public static <T extends java.nio.Buffer> T markBuffer​(T buf)
        Invoke Buffer.mark always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        Returns:
        the buffer
        See Also:
        Buffer.mark()
      • rewindBuffer

        public static <T extends java.nio.Buffer> T rewindBuffer​(T buf)
        Invoke Buffer.rewind always using Buffer as the target, to avoid binary incompatibility on Java 8.
        Type Parameters:
        T - any java.nio.Buffer type
        Parameters:
        buf - the buffer
        Returns:
        the buffer
        See Also:
        Buffer.rewind()