Class FileDataBodyPart

  • All Implemented Interfaces:
    jakarta.ws.rs.core.EntityPart

    public class FileDataBodyPart
    extends FormDataBodyPart
    An extension of FormDataBodyPart for associating File File as a body part entity.

    This class may be used to create body parts that contains a file attachments. Appropriate Content-Disposition parameters and Content-Type header will be derived from the file.

    Author:
    Imran M Yousuf (imran at smartitengineering.com), Paul Sandoz, Michal Gajdos
    • Constructor Detail

      • FileDataBodyPart

        public FileDataBodyPart()
        A no-args constructor which expects its client to set the values individually, the attributes to be set are fileEntity and name; the media type will be predicted from the fileEntity if not set explicitly.
      • FileDataBodyPart

        public FileDataBodyPart​(String name,
                                File fileEntity,
                                jakarta.ws.rs.core.MediaType mediaType)
                         throws IllegalArgumentException
        Constructs the body part with all the attributes set for its proper function. If this constructor is used to construct the body part then it is not required to set any other attributes for proper behavior.
        Parameters:
        name - the name of body part.
        fileEntity - the file that represents the entity.
        mediaType - the MediaType of the body part.
        Throws:
        IllegalArgumentException - if the fileEntity is null.
    • Method Detail

      • getFileEntity

        public File getFileEntity()
        Gets the file for this body part.
        Returns:
        file entity for this body part.
      • setFileEntity

        public void setFileEntity​(File fileEntity,
                                  jakarta.ws.rs.core.MediaType mediaType)
        Sets the MediaType and fileEntity for this FormDataBodyPart.
        Parameters:
        fileEntity - the entity of this body part.
        mediaType - the media type.
      • predictMediaType

        protected jakarta.ws.rs.core.MediaType predictMediaType()
        Predicts the media type of the current fileEntity.
        Returns:
        predicted MediaType.
      • predictMediaType

        protected jakarta.ws.rs.core.MediaType predictMediaType​(File file)
        Predicts the media type of the provided File.
        Parameters:
        file - the file from which the media type is predicted.
        Returns:
        predicted MediaType.
      • getPredictor

        public MediaTypePredictor getPredictor()
        Gets the media type predictor.
        Returns:
        the media type predictor.
      • setPredictor

        public void setPredictor​(MediaTypePredictor predictor)
        Sets the media type predictor.
        Parameters:
        predictor - the media type predictor.