Class MultiByteHttpData

  • All Implemented Interfaces:
    io.netty.buffer.ByteBufHolder, io.netty.handler.codec.http.multipart.FileUpload, io.netty.handler.codec.http.multipart.HttpData, io.netty.handler.codec.http.multipart.InterfaceHttpData, io.netty.util.ReferenceCounted, Comparable<io.netty.handler.codec.http.multipart.InterfaceHttpData>

    public class MultiByteHttpData
    extends io.netty.handler.codec.http.multipart.AbstractHttpData
    implements io.netty.handler.codec.http.multipart.FileUpload
    A FileUpload implementation that is responsible for sending Multi<Byte> as a file in a multipart message. It is meant to be used by the PausableHttpPostRequestEncoder When created, MultiByteHttpData will subscribe to the underlying Multi and request BUFFER_SIZE of bytes. Before reading the next chunk of data with getChunk(int), the post encoder checks if data isReady(int) and if not, triggers suspend(int). That's because a chunk smaller than requested is treated as the end of input. Then, when the requested amount of bytes is ready, or the underlying Multi is completed, `resumption` is executed.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.handler.codec.http.multipart.InterfaceHttpData

        io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_BUFFER_SIZE  
      • Fields inherited from class io.netty.handler.codec.http.multipart.AbstractHttpData

        definedSize, size
    • Constructor Detail

      • MultiByteHttpData

        public MultiByteHttpData​(String name,
                                 String filename,
                                 String contentType,
                                 String contentTransferEncoding,
                                 Charset charset,
                                 io.smallrye.mutiny.Multi<Byte> content,
                                 Consumer<Throwable> errorHandler,
                                 io.vertx.core.Context context,
                                 Runnable resumption)
        Parameters:
        name - name of the parameter
        filename - file name
        contentType - content type
        contentTransferEncoding - "binary" for sending binary files
        charset - the charset
        content - the Multi to send
        errorHandler - error handler invoked when the Multi emits an exception
        context - Vertx context on which the data is sent
        resumption - the action to execute when the requested amount of bytes is ready, or the Multi is completed
    • Method Detail

      • setContent

        public void setContent​(io.netty.buffer.ByteBuf buffer)
                        throws IOException
        Specified by:
        setContent in interface io.netty.handler.codec.http.multipart.HttpData
        Throws:
        IOException
      • addContent

        public void addContent​(io.netty.buffer.ByteBuf buffer,
                               boolean last)
                        throws IOException
        Specified by:
        addContent in interface io.netty.handler.codec.http.multipart.HttpData
        Throws:
        IOException
      • setContent

        public void setContent​(File file)
                        throws IOException
        Specified by:
        setContent in interface io.netty.handler.codec.http.multipart.HttpData
        Throws:
        IOException
      • setContent

        public void setContent​(InputStream inputStream)
                        throws IOException
        Specified by:
        setContent in interface io.netty.handler.codec.http.multipart.HttpData
        Throws:
        IOException
      • delete

        public void delete()
        Specified by:
        delete in interface io.netty.handler.codec.http.multipart.HttpData
      • get

        public byte[] get()
                   throws IOException
        Specified by:
        get in interface io.netty.handler.codec.http.multipart.HttpData
        Throws:
        IOException
      • getByteBuf

        public io.netty.buffer.ByteBuf getByteBuf()
        Specified by:
        getByteBuf in interface io.netty.handler.codec.http.multipart.HttpData
      • isReady

        public boolean isReady​(int chunkSize)
        check if it is possible to read the next chunk of data of a given size
        Parameters:
        chunkSize - amount of bytes
        Returns:
        true if the requested amount of bytes is ready to be read or the Multi is completed, i.e. there will be no more bytes to read
      • getChunk

        public io.netty.buffer.ByteBuf getChunk​(int toRead)

        NOTE: should only be invoked when isReady(int) returns true
        Specified by:
        getChunk in interface io.netty.handler.codec.http.multipart.HttpData
        Parameters:
        toRead - amount of bytes to read
        Returns:
        ByteBuf with the requested bytes
      • getString

        public String getString()
        Specified by:
        getString in interface io.netty.handler.codec.http.multipart.HttpData
      • getString

        public String getString​(Charset encoding)
        Specified by:
        getString in interface io.netty.handler.codec.http.multipart.HttpData
      • renameTo

        public boolean renameTo​(File dest)
        Specified by:
        renameTo in interface io.netty.handler.codec.http.multipart.HttpData
      • isInMemory

        public boolean isInMemory()
        Specified by:
        isInMemory in interface io.netty.handler.codec.http.multipart.HttpData
      • getFile

        public File getFile()
        Specified by:
        getFile in interface io.netty.handler.codec.http.multipart.HttpData
      • copy

        public io.netty.handler.codec.http.multipart.FileUpload copy()
        Specified by:
        copy in interface io.netty.buffer.ByteBufHolder
        Specified by:
        copy in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        copy in interface io.netty.handler.codec.http.multipart.HttpData
      • duplicate

        public io.netty.handler.codec.http.multipart.FileUpload duplicate()
        Specified by:
        duplicate in interface io.netty.buffer.ByteBufHolder
        Specified by:
        duplicate in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        duplicate in interface io.netty.handler.codec.http.multipart.HttpData
      • retainedDuplicate

        public io.netty.handler.codec.http.multipart.FileUpload retainedDuplicate()
        Specified by:
        retainedDuplicate in interface io.netty.buffer.ByteBufHolder
        Specified by:
        retainedDuplicate in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        retainedDuplicate in interface io.netty.handler.codec.http.multipart.HttpData
      • replace

        public io.netty.handler.codec.http.multipart.FileUpload replace​(io.netty.buffer.ByteBuf content)
        Specified by:
        replace in interface io.netty.buffer.ByteBufHolder
        Specified by:
        replace in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        replace in interface io.netty.handler.codec.http.multipart.HttpData
      • retain

        public io.netty.handler.codec.http.multipart.FileUpload retain​(int increment)
        Specified by:
        retain in interface io.netty.buffer.ByteBufHolder
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.HttpData
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.InterfaceHttpData
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
        Overrides:
        retain in class io.netty.handler.codec.http.multipart.AbstractHttpData
      • retain

        public io.netty.handler.codec.http.multipart.FileUpload retain()
        Specified by:
        retain in interface io.netty.buffer.ByteBufHolder
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.HttpData
        Specified by:
        retain in interface io.netty.handler.codec.http.multipart.InterfaceHttpData
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
        Overrides:
        retain in class io.netty.handler.codec.http.multipart.AbstractHttpData
      • touch

        public io.netty.handler.codec.http.multipart.FileUpload touch()
        Specified by:
        touch in interface io.netty.buffer.ByteBufHolder
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.HttpData
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.InterfaceHttpData
        Specified by:
        touch in interface io.netty.util.ReferenceCounted
        Specified by:
        touch in class io.netty.handler.codec.http.multipart.AbstractHttpData
      • touch

        public io.netty.handler.codec.http.multipart.FileUpload touch​(Object hint)
        Specified by:
        touch in interface io.netty.buffer.ByteBufHolder
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.FileUpload
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.HttpData
        Specified by:
        touch in interface io.netty.handler.codec.http.multipart.InterfaceHttpData
        Specified by:
        touch in interface io.netty.util.ReferenceCounted
        Specified by:
        touch in class io.netty.handler.codec.http.multipart.AbstractHttpData
      • hashCode

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

        public int compareTo​(io.netty.handler.codec.http.multipart.InterfaceHttpData o)
        Specified by:
        compareTo in interface Comparable<io.netty.handler.codec.http.multipart.InterfaceHttpData>
      • getHttpDataType

        public io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType getHttpDataType()
        Specified by:
        getHttpDataType in interface io.netty.handler.codec.http.multipart.InterfaceHttpData
      • getFilename

        public String getFilename()
        Specified by:
        getFilename in interface io.netty.handler.codec.http.multipart.FileUpload
      • setFilename

        public void setFilename​(String filename)
        Specified by:
        setFilename in interface io.netty.handler.codec.http.multipart.FileUpload
      • setContentType

        public void setContentType​(String contentType)
        Specified by:
        setContentType in interface io.netty.handler.codec.http.multipart.FileUpload
      • getContentType

        public String getContentType()
        Specified by:
        getContentType in interface io.netty.handler.codec.http.multipart.FileUpload
      • getContentTransferEncoding

        public String getContentTransferEncoding()
        Specified by:
        getContentTransferEncoding in interface io.netty.handler.codec.http.multipart.FileUpload
      • setContentTransferEncoding

        public void setContentTransferEncoding​(String contentTransferEncoding)
        Specified by:
        setContentTransferEncoding in interface io.netty.handler.codec.http.multipart.FileUpload
      • length

        public long length()
        Specified by:
        length in interface io.netty.handler.codec.http.multipart.HttpData
        Overrides:
        length in class io.netty.handler.codec.http.multipart.AbstractHttpData