Class BufferPart

  • All Implemented Interfaces:
    Part

    class BufferPart
    extends java.lang.Object
    implements Part
    The BufferPart is used to represent a part within a request message. Typically a part represents either a text parameter or a file, with associated headers. The contents of the part can be acquire as an InputStream or as a string encoded in the default HTTP encoding ISO-8859-1 or in the encoding specified with the Content-Type header.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Body body
      This is the body that forms the payload for the part.
      private Segment segment
      This is the segment representing the headers for the part.
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferPart​(Segment segment, Buffer buffer)
      Constructor for the BufferPart object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getContent()
      This is used to acquire the content of the part as a string.
      ContentType getContentType()
      This is used to acquire the content type for this part.
      ContentDisposition getDisposition()
      This is used to acquire the content disposition for the part.
      java.lang.String getFileName()
      This method is used to acquire the file name of the part.
      java.lang.String getHeader​(java.lang.String name)
      This is used to acquire the header value for the specified header name.
      java.io.InputStream getInputStream()
      This is used to acquire an InputStream for the part.
      java.lang.String getName()
      This method is used to acquire the name of the part.
      boolean isFile()
      This method is used to determine the type of a part.
      • Methods inherited from class java.lang.Object

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

      • segment

        private final Segment segment
        This is the segment representing the headers for the part.
      • body

        private final Body body
        This is the body that forms the payload for the part.
    • Constructor Detail

      • BufferPart

        public BufferPart​(Segment segment,
                          Buffer buffer)
        Constructor for the BufferPart object. This is used to create a part from a multipart body. Each part will contain the headers associated with it as well as the body.
        Parameters:
        segment - this holds the headers for the part
        buffer - this represents the body for the part
    • Method Detail

      • isFile

        public boolean isFile()
        This method is used to determine the type of a part. Typically a part is either a text parameter or a file. If this is true then the content represented by the associated part is a file.
        Specified by:
        isFile in interface Part
        Returns:
        this returns true if the associated part is a file
      • getName

        public java.lang.String getName()
        This method is used to acquire the name of the part. Typically this is used when the part represents a text parameter rather than a file. However, this can also be used with a file part.
        Specified by:
        getName in interface Part
        Returns:
        this returns the name of the associated part
      • getFileName

        public java.lang.String getFileName()
        This method is used to acquire the file name of the part. This is used when the part represents a text parameter rather than a file. However, this can also be used with a file part.
        Specified by:
        getFileName in interface Part
        Returns:
        this returns the file name of the associated part
      • getContent

        public java.lang.String getContent()
                                    throws java.io.IOException
        This is used to acquire the content of the part as a string. The encoding of the string is taken from the content type. If no content type is sent the content is decoded in the standard default of ISO-8859-1.
        Specified by:
        getContent in interface Part
        Returns:
        this returns a string representing the content
        Throws:
        java.io.IOException - thrown if the content can not be created
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        This is used to acquire an InputStream for the part. Acquiring the stream allows the content of the part to be consumed by reading the stream. Each invocation of this method will produce a new stream starting from the first byte.
        Specified by:
        getInputStream in interface Part
        Returns:
        this returns the stream for this part object
        Throws:
        java.io.IOException - thrown if the stream can not be created
      • getContentType

        public ContentType getContentType()
        This is used to acquire the content type for this part. This is typically the type of content for a file part, as provided by a MIME type from the HTTP "Content-Type" header.
        Specified by:
        getContentType in interface Part
        Returns:
        this returns the content type for the part object
      • getDisposition

        public ContentDisposition getDisposition()
        This is used to acquire the content disposition for the part. The content disposition contains the Content-Disposition header details sent with the part in the multipart request body.
        Returns:
        value of the header mapped to the specified name
      • getHeader

        public java.lang.String getHeader​(java.lang.String name)
        This is used to acquire the header value for the specified header name. Providing the header values through this method ensures any special processing for a know content type can be handled by an application.
        Specified by:
        getHeader in interface Part
        Parameters:
        name - the name of the header to get the value for
        Returns:
        value of the header mapped to the specified name