Class FileDataBodyPart
- java.lang.Object
-
- org.glassfish.jersey.media.multipart.BodyPart
-
- org.glassfish.jersey.media.multipart.FormDataBodyPart
-
- org.glassfish.jersey.media.multipart.file.FileDataBodyPart
-
- All Implemented Interfaces:
EntityPart,org.glassfish.jersey.innate.spi.MessageBodyWorkersSettable
public class FileDataBodyPart extends FormDataBodyPart
An extension ofFormDataBodyPartfor associatingFileFile 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jakarta.ws.rs.core.EntityPart
EntityPart.Builder
-
-
Field Summary
-
Fields inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
contentRead
-
Fields inherited from class org.glassfish.jersey.media.multipart.BodyPart
contentDisposition, messageBodyWorkers
-
-
Constructor Summary
Constructors Constructor Description 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(String name, File fileEntity)Constructs the body part with the provided name and file, it predicts theMediaTypeof the file provided.FileDataBodyPart(String name, File fileEntity, MediaType mediaType)Constructs the body part with all the attributes set for its proper function.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FilegetFileEntity()Gets the file for this body part.MediaTypePredictorgetPredictor()Gets the media type predictor.protected MediaTypepredictMediaType()Predicts the media type of the current fileEntity.protected MediaTypepredictMediaType(File file)Predicts the media type of the providedFile.voidsetEntity(Object entity)This operation is not supported from this implementation.voidsetFileEntity(File fileEntity)Sets the fileEntity for thisFormDataBodyPart.voidsetFileEntity(File fileEntity, MediaType mediaType)Sets theMediaTypeand fileEntity for thisFormDataBodyPart.voidsetPredictor(MediaTypePredictor predictor)Sets the media type predictor.voidsetValue(MediaType mediaType, Object value)This operation is not supported from this implementation.-
Methods inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
getContent, getContent, getContent, getContentDisposition, getFileName, getFormDataContentDisposition, getName, getValue, getValueAs, isSimple, setContentDisposition, setFormDataContentDisposition, setName, setValue
-
Methods inherited from class org.glassfish.jersey.media.multipart.BodyPart
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setMediaType, setMessageBodyWorkers, setParent, setProviders, type
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jakarta.ws.rs.core.EntityPart
getHeaders, getMediaType
-
-
-
-
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)
Constructs the body part with the provided name and file, it predicts theMediaTypeof the file provided. For the known media types client will not need to set the media type explicitly.- Parameters:
name- the name of body part.fileEntity- the file that represents the entity.- See Also:
MediaTypePredictor.getMediaTypeFromFile(java.io.File),FileDataBodyPart(java.lang.String, java.io.File, jakarta.ws.rs.core.MediaType)
-
FileDataBodyPart
public FileDataBodyPart(String name, File fileEntity, 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- theMediaTypeof the body part.- Throws:
IllegalArgumentException- if the fileEntity isnull.
-
-
Method Detail
-
getFileEntity
public File getFileEntity()
Gets the file for this body part.- Returns:
- file entity for this body part.
-
setValue
public void setValue(MediaType mediaType, Object value) throws UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setValuein classFormDataBodyPart- Parameters:
mediaType- the media type for this field value.value- the field value as a Java object.- Throws:
UnsupportedOperationException- Operation not supported.- See Also:
setFileEntity(java.io.File, jakarta.ws.rs.core.MediaType)
-
setEntity
public void setEntity(Object entity) throws UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setEntityin classBodyPart- Parameters:
entity- the new entity object.- Throws:
UnsupportedOperationException- Operation not supported.- See Also:
setFileEntity(java.io.File)
-
setFileEntity
public void setFileEntity(File fileEntity)
Sets the fileEntity for thisFormDataBodyPart.- Parameters:
fileEntity- the entity of thisFormDataBodyPart.
-
setFileEntity
public void setFileEntity(File fileEntity, MediaType mediaType)
Sets theMediaTypeand fileEntity for thisFormDataBodyPart.- Parameters:
fileEntity- the entity of this body part.mediaType- the media type.
-
predictMediaType
protected MediaType predictMediaType()
Predicts the media type of the current fileEntity.- Returns:
- predicted
MediaType.
-
predictMediaType
protected MediaType predictMediaType(File file)
Predicts the media type of the providedFile.- 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.
-
-