org.springframework.core.io.buffer

Class NettyDataBuffer

  • java.lang.Object
    • org.springframework.core.io.buffer.NettyDataBuffer
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.nio.ByteBuffer asByteBuffer()
      Expose this buffer's bytes as a ByteBuffer.
      java.nio.ByteBuffer asByteBuffer(int index, int length)
      Expose a subsequence of this buffer's bytes as a ByteBuffer.
      java.io.InputStream asInputStream()
      Expose this buffer's data as an InputStream.
      java.io.InputStream asInputStream(boolean releaseOnClose)
      Expose this buffer's data as an InputStream.
      java.io.OutputStream asOutputStream()
      Expose this buffer's data as an OutputStream.
      int capacity()
      Return the number of bytes that this buffer can contain.
      NettyDataBuffer capacity(int capacity)
      Set the number of bytes that this buffer can contain.
      boolean equals(java.lang.Object other) 
      NettyDataBufferFactory factory()
      Return the DataBufferFactory that created this buffer.
      byte getByte(int index)
      Read a single byte at the given index from this data buffer.
      io.netty.buffer.ByteBuf getNativeBuffer()
      Directly exposes the native ByteBuf that this buffer is based on.
      int hashCode() 
      int indexOf(java.util.function.IntPredicate predicate, int fromIndex)
      Return the index of the first byte in this buffer that matches the given predicate.
      boolean isAllocated()
      Return true if this buffer is allocated; false if it has been deallocated.
      int lastIndexOf(java.util.function.IntPredicate predicate, int fromIndex)
      Return the index of the last byte in this buffer that matches the given predicate.
      byte read()
      Read a single byte from the current reading position from this data buffer.
      NettyDataBuffer read(byte[] destination)
      Read this buffer's data into the specified destination, starting at the current reading position of this buffer.
      NettyDataBuffer read(byte[] destination, int offset, int length)
      Read at most length bytes of this buffer into the specified destination, starting at the current reading position of this buffer.
      int readableByteCount()
      Return the number of bytes that can be read from this data buffer.
      int readPosition()
      Return the position from which this buffer will read.
      NettyDataBuffer readPosition(int readPosition)
      Set the position from which this buffer will read.
      boolean release()
      Decrease the reference count for this buffer by one, and deallocate it once the count reaches zero.
      PooledDataBuffer retain()
      Increase the reference count for this buffer by one.
      NettyDataBuffer slice(int index, int length)
      Create a new DataBuffer whose contents is a shared subsequence of this data buffer's content.
      java.lang.String toString() 
      int writableByteCount()
      Return the number of bytes that can be written to this data buffer.
      NettyDataBuffer write(byte b)
      Write a single byte into this buffer at the current writing position.
      NettyDataBuffer write(byte[] source)
      Write the given source into this buffer, startin at the current writing position of this buffer.
      NettyDataBuffer write(byte[] source, int offset, int length)
      Write at most length bytes of the given source into this buffer, starting at the current writing position of this buffer.
      NettyDataBuffer write(io.netty.buffer.ByteBuf... byteBufs)
      Writes one or more Netty ByteBufs to this buffer, starting at the current writing position.
      NettyDataBuffer write(java.nio.ByteBuffer... buffers)
      Write one or more ByteBuffer to this buffer, starting at the current writing position.
      NettyDataBuffer write(DataBuffer... buffers)
      Write one or more DataBuffers to this buffer, starting at the current writing position.
      int writePosition()
      Return the position to which this buffer will write.
      NettyDataBuffer writePosition(int writePosition)
      Set the position to which this buffer will write.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getNativeBuffer

        public io.netty.buffer.ByteBuf getNativeBuffer()
        Directly exposes the native ByteBuf that this buffer is based on.
        Returns:
        the wrapped byte buffer
      • indexOf

        public int indexOf(java.util.function.IntPredicate predicate,
                           int fromIndex)
        Description copied from interface: DataBuffer
        Return the index of the first byte in this buffer that matches the given predicate.
        Specified by:
        indexOf in interface DataBuffer
        Parameters:
        predicate - the predicate to match
        fromIndex - the index to start the search from
        Returns:
        the index of the first byte that matches predicate; or -1 if none match
      • lastIndexOf

        public int lastIndexOf(java.util.function.IntPredicate predicate,
                               int fromIndex)
        Description copied from interface: DataBuffer
        Return the index of the last byte in this buffer that matches the given predicate.
        Specified by:
        lastIndexOf in interface DataBuffer
        Parameters:
        predicate - the predicate to match
        fromIndex - the index to start the search from
        Returns:
        the index of the last byte that matches predicate; or -1 if none match
      • readableByteCount

        public int readableByteCount()
        Description copied from interface: DataBuffer
        Return the number of bytes that can be read from this data buffer.
        Specified by:
        readableByteCount in interface DataBuffer
        Returns:
        the readable byte count
      • writableByteCount

        public int writableByteCount()
        Description copied from interface: DataBuffer
        Return the number of bytes that can be written to this data buffer.
        Specified by:
        writableByteCount in interface DataBuffer
        Returns:
        the writable byte count
      • readPosition

        public int readPosition()
        Description copied from interface: DataBuffer
        Return the position from which this buffer will read.
        Specified by:
        readPosition in interface DataBuffer
        Returns:
        the read position
      • readPosition

        public NettyDataBuffer readPosition(int readPosition)
        Description copied from interface: DataBuffer
        Set the position from which this buffer will read.
        Specified by:
        readPosition in interface DataBuffer
        Parameters:
        readPosition - the new read position
        Returns:
        this buffer
      • writePosition

        public int writePosition()
        Description copied from interface: DataBuffer
        Return the position to which this buffer will write.
        Specified by:
        writePosition in interface DataBuffer
        Returns:
        the write position
      • writePosition

        public NettyDataBuffer writePosition(int writePosition)
        Description copied from interface: DataBuffer
        Set the position to which this buffer will write.
        Specified by:
        writePosition in interface DataBuffer
        Parameters:
        writePosition - the new write position
        Returns:
        this buffer
      • getByte

        public byte getByte(int index)
        Description copied from interface: DataBuffer
        Read a single byte at the given index from this data buffer.
        Specified by:
        getByte in interface DataBuffer
        Parameters:
        index - the index at which the byte will be read
        Returns:
        the byte at the given index
      • capacity

        public int capacity()
        Description copied from interface: DataBuffer
        Return the number of bytes that this buffer can contain.
        Specified by:
        capacity in interface DataBuffer
        Returns:
        the capacity
      • capacity

        public NettyDataBuffer capacity(int capacity)
        Description copied from interface: DataBuffer
        Set the number of bytes that this buffer can contain.

        If the new capacity is lower than the current capacity, the contents of this buffer will be truncated. If the new capacity is higher than the current capacity, it will be expanded.

        Specified by:
        capacity in interface DataBuffer
        Parameters:
        capacity - the new capacity
        Returns:
        this buffer
      • read

        public byte read()
        Description copied from interface: DataBuffer
        Read a single byte from the current reading position from this data buffer.
        Specified by:
        read in interface DataBuffer
        Returns:
        the byte at this buffer's current reading position
      • read

        public NettyDataBuffer read(byte[] destination)
        Description copied from interface: DataBuffer
        Read this buffer's data into the specified destination, starting at the current reading position of this buffer.
        Specified by:
        read in interface DataBuffer
        Parameters:
        destination - the array into which the bytes are to be written
        Returns:
        this buffer
      • read

        public NettyDataBuffer read(byte[] destination,
                                    int offset,
                                    int length)
        Description copied from interface: DataBuffer
        Read at most length bytes of this buffer into the specified destination, starting at the current reading position of this buffer.
        Specified by:
        read in interface DataBuffer
        Parameters:
        destination - the array into which the bytes are to be written
        offset - the index within destination of the first byte to be written
        length - the maximum number of bytes to be written in destination
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(byte b)
        Description copied from interface: DataBuffer
        Write a single byte into this buffer at the current writing position.
        Specified by:
        write in interface DataBuffer
        Parameters:
        b - the byte to be written
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(byte[] source)
        Description copied from interface: DataBuffer
        Write the given source into this buffer, startin at the current writing position of this buffer.
        Specified by:
        write in interface DataBuffer
        Parameters:
        source - the bytes to be written into this buffer
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(byte[] source,
                                     int offset,
                                     int length)
        Description copied from interface: DataBuffer
        Write at most length bytes of the given source into this buffer, starting at the current writing position of this buffer.
        Specified by:
        write in interface DataBuffer
        Parameters:
        source - the bytes to be written into this buffer
        offset - the index within source to start writing from
        length - the maximum number of bytes to be written from source
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(DataBuffer... buffers)
        Description copied from interface: DataBuffer
        Write one or more DataBuffers to this buffer, starting at the current writing position. It is the responsibility of the caller to release the given data buffers.
        Specified by:
        write in interface DataBuffer
        Parameters:
        buffers - the byte buffers to write into this buffer
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(java.nio.ByteBuffer... buffers)
        Description copied from interface: DataBuffer
        Write one or more ByteBuffer to this buffer, starting at the current writing position.
        Specified by:
        write in interface DataBuffer
        Parameters:
        buffers - the byte buffers to write into this buffer
        Returns:
        this buffer
      • write

        public NettyDataBuffer write(io.netty.buffer.ByteBuf... byteBufs)
        Writes one or more Netty ByteBufs to this buffer, starting at the current writing position.
        Parameters:
        byteBufs - the buffers to write into this buffer
        Returns:
        this buffer
      • slice

        public NettyDataBuffer slice(int index,
                                     int length)
        Description copied from interface: DataBuffer
        Create a new DataBuffer whose contents is a shared subsequence of this data buffer's content. Data between this data buffer and the returned buffer is shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.
        Specified by:
        slice in interface DataBuffer
        Parameters:
        index - the index at which to start the slice
        length - the length of the slice
        Returns:
        the specified slice of this data buffer
      • asByteBuffer

        public java.nio.ByteBuffer asByteBuffer()
        Description copied from interface: DataBuffer
        Expose this buffer's bytes as a ByteBuffer. Data between this DataBuffer and the returned ByteBuffer is shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.
        Specified by:
        asByteBuffer in interface DataBuffer
        Returns:
        this data buffer as a byte buffer
      • asByteBuffer

        public java.nio.ByteBuffer asByteBuffer(int index,
                                                int length)
        Description copied from interface: DataBuffer
        Expose a subsequence of this buffer's bytes as a ByteBuffer. Data between this DataBuffer and the returned ByteBuffer is shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.
        Specified by:
        asByteBuffer in interface DataBuffer
        Parameters:
        index - the index at which to start the byte buffer
        length - the length of the returned byte buffer
        Returns:
        this data buffer as a byte buffer
      • asInputStream

        public java.io.InputStream asInputStream()
        Description copied from interface: DataBuffer
        Expose this buffer's data as an InputStream. Both data and read position are shared between the returned stream and this data buffer. The underlying buffer will not be released when the input stream is closed.
        Specified by:
        asInputStream in interface DataBuffer
        Returns:
        this data buffer as an input stream
        See Also:
        DataBuffer.asInputStream(boolean)
      • asInputStream

        public java.io.InputStream asInputStream(boolean releaseOnClose)
        Description copied from interface: DataBuffer
        Expose this buffer's data as an InputStream. Both data and read position are shared between the returned stream and this data buffer.
        Specified by:
        asInputStream in interface DataBuffer
        Parameters:
        releaseOnClose - whether the underlying buffer will be released when the input stream is closed.
        Returns:
        this data buffer as an input stream
      • asOutputStream

        public java.io.OutputStream asOutputStream()
        Description copied from interface: DataBuffer
        Expose this buffer's data as an OutputStream. Both data and write position are shared between the returned stream and this data buffer.
        Specified by:
        asOutputStream in interface DataBuffer
        Returns:
        this data buffer as an output stream
      • isAllocated

        public boolean isAllocated()
        Description copied from interface: PooledDataBuffer
        Return true if this buffer is allocated; false if it has been deallocated.
        Specified by:
        isAllocated in interface PooledDataBuffer
      • release

        public boolean release()
        Description copied from interface: PooledDataBuffer
        Decrease the reference count for this buffer by one, and deallocate it once the count reaches zero.
        Specified by:
        release in interface PooledDataBuffer
        Returns:
        true if the buffer was deallocated; false otherwise.
      • equals

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

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

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