Class Buffer


  • public final class Buffer
    extends java.lang.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

      • map

        public static Buffer map​(java.nio.channels.FileChannel channel,
                                 java.nio.channels.FileChannel.MapMode mode,
                                 long position,
                                 long size)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • 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()
      • readFully

        public int readFully​(java.nio.channels.FileChannel channel,
                             int position)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • 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​(java.util.zip.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()
      • decode

        public java.nio.CharBuffer decode​(java.nio.charset.Charset charset)
      • hasRemaining

        public boolean hasRemaining()
      • write

        public int write​(java.nio.channels.WritableByteChannel channel)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • putInt

        public Buffer putInt​(int i)
      • putLong

        public Buffer putLong​(long l)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object