Class ContentHeaderHandler
- java.lang.Object
-
- co.arago.hiro.client.util.httpclient.ContentHeaderHandler
-
- Direct Known Subclasses:
HttpResponseParser,StreamContainer
public class ContentHeaderHandler extends java.lang.ObjectDecodes / Encodes the headers Content-Type and Content-Length.- See Also:
- Documentation of Content-Type
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringboundaryDecoded from the Content-Type if it exists.protected java.nio.charset.CharsetcharsetDecoded from the Content-Type if it exists.protected java.lang.LongcontentLengthThe Content-Length as read from the response header.protected java.lang.StringmediaTypeDecoded from the Content-Type.
-
Constructor Summary
Constructors Constructor Description ContentHeaderHandler(java.lang.String mediaType, java.nio.charset.Charset charset, java.lang.Long contentLength)Constructor used when Content-Headers have to be constructed.ContentHeaderHandler(java.net.http.HttpHeaders httpHeaders)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontentIsJson()Check whether the mediaType is application/jsonjava.lang.StringgetBoundary()java.nio.charset.CharsetgetCharset()java.lang.LonggetContentLength()java.lang.StringgetContentType()Constructs the Header Content-Type from the mediaType, charset or boundary.java.lang.StringgetMediaType()booleanhasContentType()voidsetBoundary(java.lang.String boundary)voidsetCharset(java.nio.charset.Charset charset)voidsetContentLength(java.lang.Long contentLength)voidsetContentType(java.lang.String contentType)Decodes a Content-Type header and sets mediaType, charset and boundary from it.voidsetMediaType(java.lang.String mediaType)
-
-
-
Field Detail
-
contentLength
protected java.lang.Long contentLength
The Content-Length as read from the response header. This might be null when this header is missing.
-
mediaType
protected java.lang.String mediaType
Decoded from the Content-Type. Might be null.
-
charset
protected java.nio.charset.Charset charset
Decoded from the Content-Type if it exists. Might be null.
-
boundary
protected java.lang.String boundary
Decoded from the Content-Type if it exists. Might be null.
-
-
Constructor Detail
-
ContentHeaderHandler
public ContentHeaderHandler(java.net.http.HttpHeaders httpHeaders)
Constructor. Creates this object with all its data from the incoming httpHeaders.- Parameters:
httpHeaders- The httpHeaders to decode.
-
ContentHeaderHandler
public ContentHeaderHandler(java.lang.String mediaType, java.nio.charset.Charset charset, java.lang.Long contentLength)Constructor used when Content-Headers have to be constructed.- Parameters:
mediaType- The mime type for the data.charset- The charset - if any. Can be null.contentLength- The length of the content - if any. Can be null.
-
-
Method Detail
-
setContentType
public void setContentType(java.lang.String contentType)
Decodes a Content-Type header and sets mediaType, charset and boundary from it.- Parameters:
contentType- The content-type directly from a HTTP header.- See Also:
- Documentation of Content-Type
-
getContentType
public java.lang.String getContentType()
Constructs the Header Content-Type from the mediaType, charset or boundary.- Returns:
- The HTTP header value for Content-Type.
-
hasContentType
public boolean hasContentType()
-
setContentLength
public void setContentLength(java.lang.Long contentLength)
-
setCharset
public void setCharset(java.nio.charset.Charset charset)
-
setMediaType
public void setMediaType(java.lang.String mediaType)
-
setBoundary
public void setBoundary(java.lang.String boundary)
-
getContentLength
public java.lang.Long getContentLength()
-
getMediaType
public java.lang.String getMediaType()
-
getCharset
public java.nio.charset.Charset getCharset()
-
getBoundary
public java.lang.String getBoundary()
-
contentIsJson
public boolean contentIsJson()
Check whether the mediaType is application/json- Returns:
- true if contentType matches, false if not.
-
-