Class AbstractBody
- Direct Known Subclasses:
Body,ChunkedBody,EmptyBody
(Sending a body is handled by one of the AbstractBodyTransferrers.)
To read a body, use the concrete implementation ChunkedBody (iff
"Transfer-Encoding: chunked" is used) or Body (iff not). To construct
a body within Membrane, Body is used by some helper method like
Response.ResponseBuilder.body(String).
This class supports "streaming" the body: If a HTTP message is directly forwarded by Membrane (without any component reading or changing the message's body), the incoming network stream's buffer is directly written to the output stream. This allows Membrane to perform very well in this situation.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddiscard()byte[]Returns the body's content as a byte[] representation.intWarning: Calling this method will trigger reading the body from the client, disabling "streaming".byte[]getRaw()Returns a reconstruction of the over-the-wire byte sequence received.protected abstract byte[]protected booleanbooleanbooleanisRead()protected voidvoidread()protected abstract voidbooleansetTrailer(Header trailer) toString()Supposes UTF-8 encoding.booleanvoidwrite(AbstractBodyTransferrer out, boolean retainCopy) protected abstract voidprotected abstract voidprotected abstract voidIs called when there are no observers that need to read the body.
-
Field Details
-
chunks
-
observers
-
-
Constructor Details
-
AbstractBody
public AbstractBody()
-
-
Method Details
-
read
- Throws:
IOException
-
discard
- Throws:
IOException
-
markAsRead
protected void markAsRead() -
readLocal
- Throws:
IOException
-
getContent
Returns the body's content as a byte[] representation.For example,
getContent()might return a byte representation ofWikipedia in chunks.
The return value does not differ whether "Transfer-Encoding: chunked" is used or not (see Chunked Transfer Encoding ), the example above is taken from there.Please note that a new array is allocated when calling
getContent(). If you do not need the body as one single byte[], you should therefore usegetContentAsStream()instead.- Throws:
IOException
-
getContentAsStream
- Throws:
IOException
-
write
- Throws:
IOException
-
writeAlreadyRead
- Throws:
IOException
-
writeNotRead
- Throws:
IOException
-
writeStreamed
Is called when there are no observers that need to read the body. Streams the body without reading it- Throws:
IOException
-
getLength
Warning: Calling this method will trigger reading the body from the client, disabling "streaming". UseisRead()to determine wether the body already has been read, if necessary.- Returns:
- the length of the return value of
getContent() - Throws:
IOException
-
getRaw
Returns a reconstruction of the over-the-wire byte sequence received.When "Transfer-Encoding: chunked" is used (see Chunked Transfer Encoding ), the return value might be (to follow the example from Wikipedia) a byte representation of
4 Wiki 5 pedia E in chunks. 0
- Throws:
IOException
-
getRawLocal
- Throws:
IOException
-
hasRelevantObservers
protected boolean hasRelevantObservers() -
toString
Supposes UTF-8 encoding. Should therefore not be used for primary functionality. -
isRead
public boolean isRead() -
getObservers
-
wasStreamed
public boolean wasStreamed() -
getTrailer
-
setTrailer
- Returns:
- true, when the body supports trailers and the trailer was therefore set.
-
hasTrailer
public boolean hasTrailer()
-