Class Buffer

java.lang.Object
org.apache.jackrabbit.oak.commons.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 Details

    • map

      public static Buffer map(FileChannel channel, FileChannel.MapMode mode, long position, long size) throws IOException
      Throws:
      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(FileChannel channel, int position) throws IOException
      Throws:
      IOException
    • flip

      public Buffer flip()
    • getInt

      public int getInt()
    • getInt

      public int getInt(int pos)
    • mark

      public Buffer mark()
    • 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)
    • put

      public Buffer put(Buffer 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 CharBuffer decode(Charset charset)
    • hasRemaining

      public boolean hasRemaining()
    • write

      public int write(WritableByteChannel channel) throws IOException
      Throws:
      IOException
    • putInt

      public Buffer putInt(int i)
    • putLong

      public Buffer putLong(long l)
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object