Class ByteBufWrapper

  • All Implemented Interfaces:
    io.pravega.common.util.BufferView

    @NotThreadSafe
    public class ByteBufWrapper
    extends io.pravega.common.util.AbstractBufferView
    implements io.pravega.common.util.BufferView
    BufferView wrapper for ByteBuf instances.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.pravega.common.util.AbstractBufferView

        io.pravega.common.util.AbstractBufferView.AbstractReader
      • Nested classes/interfaces inherited from interface io.pravega.common.util.BufferView

        io.pravega.common.util.BufferView.Collector<ExceptionT extends java.lang.Exception>, io.pravega.common.util.BufferView.Reader
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBufWrapper​(@NonNull io.netty.buffer.ByteBuf buf)
      Creates a new instance of the ByteBufWrapper wrapping the given ByteBuf.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <ExceptionT extends java.lang.Exception>
      void
      collect​(io.pravega.common.util.BufferView.Collector<ExceptionT> bufferCollector)  
      void copyTo​(java.io.OutputStream target)  
      int copyTo​(java.nio.ByteBuffer byteBuffer)  
      int getAllocatedLength()  
      io.pravega.common.util.BufferView.Reader getBufferViewReader()  
      byte[] getCopy()  
      int getLength()  
      java.io.InputStream getReader()  
      java.io.InputStream getReader​(int offset, int length)  
      java.util.Iterator<java.nio.ByteBuffer> iterateBuffers()  
      void release()
      Invokes ReferenceCounted.release() on the underlying buffer, but only if ReferenceCounted.refCnt() is non-zero.
      void retain()
      Invokes ByteBuf.retain() on the underlying buffer.
      io.pravega.common.util.BufferView slice​(int offset, int length)  
      java.lang.String toString()  
      • Methods inherited from class io.pravega.common.util.AbstractBufferView

        equals, equals, hashCode
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface io.pravega.common.util.BufferView

        slice
    • Constructor Detail

      • ByteBufWrapper

        public ByteBufWrapper​(@NonNull
                              @NonNull io.netty.buffer.ByteBuf buf)
        Creates a new instance of the ByteBufWrapper wrapping the given ByteBuf. This instance will begin at the given buffer's ByteBuf.readerIndex() and will have a length equal to ByteBuf.readableBytes().
        Parameters:
        buf - The ByteBuf to wrap. A read-only duplicate will be made of this buffer; any changes made to the ByteBuf.readerIndex() or ByteBuf.writerIndex() to this object will not be reflected in this ByteBufWrapper instance. This ByteBuf reference count will be incremented by 1 to reflect the new reference added by this wrapper. Invoke release() to release that reference.
    • Method Detail

      • retain

        public void retain()
        Invokes ByteBuf.retain() on the underlying buffer.
        Specified by:
        retain in interface io.pravega.common.util.BufferView
      • release

        public void release()
        Invokes ReferenceCounted.release() on the underlying buffer, but only if ReferenceCounted.refCnt() is non-zero. As opposed from ReferenceCounted.release(), this method will not throw if invoked too many times.
        Specified by:
        release in interface io.pravega.common.util.BufferView
      • collect

        public <ExceptionT extends java.lang.Exception> void collect​(io.pravega.common.util.BufferView.Collector<ExceptionT> bufferCollector)
                                                              throws ExceptionT extends java.lang.Exception
        Specified by:
        collect in interface io.pravega.common.util.BufferView
        Throws:
        ExceptionT extends java.lang.Exception
      • iterateBuffers

        public java.util.Iterator<java.nio.ByteBuffer> iterateBuffers()
        Specified by:
        iterateBuffers in interface io.pravega.common.util.BufferView
      • getLength

        public int getLength()
        Specified by:
        getLength in interface io.pravega.common.util.BufferView
      • getAllocatedLength

        public int getAllocatedLength()
        Specified by:
        getAllocatedLength in interface io.pravega.common.util.BufferView
      • getBufferViewReader

        public io.pravega.common.util.BufferView.Reader getBufferViewReader()
        Specified by:
        getBufferViewReader in interface io.pravega.common.util.BufferView
      • getReader

        public java.io.InputStream getReader()
        Specified by:
        getReader in interface io.pravega.common.util.BufferView
      • getReader

        public java.io.InputStream getReader​(int offset,
                                             int length)
        Specified by:
        getReader in interface io.pravega.common.util.BufferView
      • slice

        public io.pravega.common.util.BufferView slice​(int offset,
                                                       int length)
        Specified by:
        slice in interface io.pravega.common.util.BufferView
      • getCopy

        public byte[] getCopy()
        Specified by:
        getCopy in interface io.pravega.common.util.BufferView
      • copyTo

        public void copyTo​(java.io.OutputStream target)
                    throws java.io.IOException
        Specified by:
        copyTo in interface io.pravega.common.util.BufferView
        Throws:
        java.io.IOException
      • copyTo

        public int copyTo​(java.nio.ByteBuffer byteBuffer)
        Specified by:
        copyTo in interface io.pravega.common.util.BufferView
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object