Class Buffers

java.lang.Object
com.headius.backport9.buffer.Buffers

public class Buffers extends 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends Buffer>
    T
    clearBuffer(T buf)
    Invoke Buffer.clear always using Buffer as the target, to avoid binary incompatibility on Java 8.
    static <T extends Buffer>
    T
    flipBuffer(T buf)
    Invoke Buffer.flip always using Buffer as the target, to avoid binary incompatibility on Java 8.
    static <T extends 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 Buffer>
    T
    markBuffer(T buf)
    Invoke Buffer.mark always using Buffer as the target, to avoid binary incompatibility on Java 8.
    static <T extends 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 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 Details

    • Buffers

      public Buffers()
  • Method Details

    • clearBuffer

      public static <T extends 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:
    • flipBuffer

      public static <T extends 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:
    • limitBuffer

      public static <T extends 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:
    • positionBuffer

      public static <T extends 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:
    • markBuffer

      public static <T extends 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:
    • rewindBuffer

      public static <T extends 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: