Class CloseableByteBuffer

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class CloseableByteBuffer
    extends java.lang.Object
    implements java.io.Closeable
    A wrapper for ByteBuffer that implements the Closeable interface, releasing the ByteBuffer when it is no longer needed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer byteBuffer  
      private java.lang.Runnable onClose  
    • Constructor Summary

      Constructors 
      Constructor Description
      CloseableByteBuffer​(java.nio.ByteBuffer byteBuffer, java.lang.Runnable onClose)
      A wrapper for ByteBuffer that implements the Closeable interface, releasing the ByteBuffer when it is no longer needed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Release the wrapped ByteBuffer.
      java.nio.ByteBuffer getByteBuffer()  
      • Methods inherited from class java.lang.Object

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

      • byteBuffer

        private java.nio.ByteBuffer byteBuffer
      • onClose

        private java.lang.Runnable onClose
    • Constructor Detail

      • CloseableByteBuffer

        CloseableByteBuffer​(java.nio.ByteBuffer byteBuffer,
                            java.lang.Runnable onClose)
        A wrapper for ByteBuffer that implements the Closeable interface, releasing the ByteBuffer when it is no longer needed.
        Parameters:
        byteBuffer - The ByteBuffer to wrap
        onClose - The method to run when close() is called.
    • Method Detail

      • getByteBuffer

        public java.nio.ByteBuffer getByteBuffer()
        Returns:
        The wrapped ByteBuffer.
      • close

        public void close()
                   throws java.io.IOException
        Release the wrapped ByteBuffer.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException