Class Buffer


  • public final class Buffer
    extends Object
    This is a wrapper around ByteBuffer. It maintains the same semantics and mechanisms of the ByteBuffer.

    Java 9 introduced API changes to some methods in ByteBuffer. Instead of returning instances of Buffer, those methods were rewritten to return instances of ByteBuffer instead. While this is perfectly fine at compile time, running "modern" code on Java 8 and earlier throws NoSuchMethodError. In order to prevent occurrences of this exceptions in the future, Buffer is used consistently in place of ByteBuffer. Since it is not possible to directly convert a Buffer into a ByteBuffer and the other way around, Buffer makes it less likely to develop dangerous code in the future.

    • Method Detail

      • wrap

        public static Buffer wrap​(byte[] buffer)
      • wrap

        public static Buffer wrap​(byte[] buffer,
                                  int pos,
                                  int len)
      • allocate

        public static Buffer allocate​(int cap)
      • allocateDirect

        public static Buffer allocateDirect​(int cap)
      • remaining

        public int remaining()
      • asReadOnlyBuffer

        public Buffer asReadOnlyBuffer()
      • position

        public Buffer position​(int pos)
      • position

        public int position()
      • limit

        public Buffer limit​(int lim)
      • limit

        public int limit()
      • slice

        public Buffer slice()
      • getInt

        public int getInt()
      • getInt

        public int getInt​(int pos)
      • get

        public Buffer get​(byte[] b)
      • get

        public Buffer get​(byte[] b,
                          int pos,
                          int len)
      • get

        public byte get​(int pos)
      • get

        public byte get()
      • reset

        public Buffer reset()
      • update

        public void update​(CRC32 checksum)
      • array

        public byte[] array()
      • capacity

        public int capacity()
      • isDirect

        public boolean isDirect()
      • put

        public Buffer put​(byte[] b)
      • put

        public Buffer put​(byte[] buf,
                          int pos,
                          int len)
      • put

        public Buffer put​(byte b)
      • rewind

        public Buffer rewind()
      • getLong

        public long getLong​(int pos)
      • getLong

        public long getLong()
      • getShort

        public short getShort​(int pos)
      • duplicate

        public Buffer duplicate()
      • hasRemaining

        public boolean hasRemaining()
      • putInt

        public Buffer putInt​(int i)
      • putLong

        public Buffer putLong​(long l)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object