Class FileDataBodyPart
- java.lang.Object
-
- org.glassfish.jersey.media.multipart.BodyPart
-
- org.glassfish.jersey.media.multipart.FormDataBodyPart
-
- org.glassfish.jersey.media.multipart.file.FileDataBodyPart
-
public class FileDataBodyPart extends FormDataBodyPart
An extension ofFormDataBodyPart
for associatingFile
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
fileEntity
private MediaTypePredictor
predictor
-
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(java.lang.String name, java.io.File fileEntity)
Constructs the body part with the provided name and file, it predicts theMediaType
of the file provided.FileDataBodyPart(java.lang.String name, java.io.File fileEntity, javax.ws.rs.core.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 java.io.File
getFileEntity()
Gets the file for this body part.MediaTypePredictor
getPredictor()
Gets the media type predictor.protected javax.ws.rs.core.MediaType
predictMediaType()
Predicts the media type of the current fileEntity.protected javax.ws.rs.core.MediaType
predictMediaType(java.io.File file)
Predicts the media type of the providedFile
.void
setEntity(java.lang.Object entity)
This operation is not supported from this implementation.void
setFileEntity(java.io.File fileEntity)
Sets the fileEntity for thisFormDataBodyPart
.void
setFileEntity(java.io.File fileEntity, javax.ws.rs.core.MediaType mediaType)
Sets theMediaType
and fileEntity for thisFormDataBodyPart
.void
setPredictor(MediaTypePredictor predictor)
Sets the media type predictor.void
setValue(javax.ws.rs.core.MediaType mediaType, java.lang.Object value)
This operation is not supported from this implementation.-
Methods inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
getContentDisposition, 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
-
-
-
-
Field Detail
-
fileEntity
private java.io.File fileEntity
-
predictor
private MediaTypePredictor predictor
-
-
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(java.lang.String name, java.io.File fileEntity)
Constructs the body part with the provided name and file, it predicts theMediaType
of 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, javax.ws.rs.core.MediaType)
-
FileDataBodyPart
public FileDataBodyPart(java.lang.String name, java.io.File fileEntity, javax.ws.rs.core.MediaType mediaType) throws java.lang.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
- theMediaType
of the body part.- Throws:
java.lang.IllegalArgumentException
- if the fileEntity isnull
.
-
-
Method Detail
-
getFileEntity
public java.io.File getFileEntity()
Gets the file for this body part.- Returns:
- file entity for this body part.
-
setValue
public void setValue(javax.ws.rs.core.MediaType mediaType, java.lang.Object value) throws java.lang.UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setValue
in classFormDataBodyPart
- Parameters:
mediaType
- the media type for this field value.value
- the field value as a Java object.- Throws:
java.lang.UnsupportedOperationException
- Operation not supported.- See Also:
setFileEntity(java.io.File, javax.ws.rs.core.MediaType)
-
setEntity
public void setEntity(java.lang.Object entity) throws java.lang.UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setEntity
in classBodyPart
- Parameters:
entity
- the new entity object.- Throws:
java.lang.UnsupportedOperationException
- Operation not supported.- See Also:
setFileEntity(java.io.File)
-
setFileEntity
public void setFileEntity(java.io.File fileEntity)
Sets the fileEntity for thisFormDataBodyPart
.- Parameters:
fileEntity
- the entity of thisFormDataBodyPart
.
-
setFileEntity
public void setFileEntity(java.io.File fileEntity, javax.ws.rs.core.MediaType mediaType)
Sets theMediaType
and fileEntity for thisFormDataBodyPart
.- Parameters:
fileEntity
- the entity of this body part.mediaType
- the media type.
-
predictMediaType
protected javax.ws.rs.core.MediaType predictMediaType()
Predicts the media type of the current fileEntity.- Returns:
- predicted
MediaType
.
-
predictMediaType
protected javax.ws.rs.core.MediaType predictMediaType(java.io.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.
-
-