public abstract class AbstractBody extends Object
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.| Modifier and Type | Field and Description |
|---|---|
protected List<Chunk> |
chunks |
protected List<MessageObserver> |
observers |
| Constructor and Description |
|---|
AbstractBody() |
| Modifier and Type | Method and Description |
|---|---|
void |
discard() |
byte[] |
getContent()
Returns the body's content as a byte[] represenatation.
|
InputStream |
getContentAsStream() |
int |
getLength()
Warning: Calling this method will trigger reading the body from the client, disabling "streaming".
|
List<MessageObserver> |
getObservers() |
byte[] |
getRaw()
Returns a reconstruction of the over-the-wire byte sequence received.
|
protected abstract byte[] |
getRawLocal() |
protected boolean |
hasRelevantObservers() |
boolean |
isRead() |
protected void |
markAsRead() |
void |
read() |
protected abstract void |
readLocal() |
void |
setWasStreamed(boolean wasStreamed) |
String |
toString()
Supposes UTF-8 encoding.
|
boolean |
wasStreamed() |
void |
write(AbstractBodyTransferrer out) |
protected abstract void |
writeAlreadyRead(AbstractBodyTransferrer out) |
protected abstract void |
writeNotRead(AbstractBodyTransferrer out) |
protected abstract void |
writeStreamed(AbstractBodyTransferrer out)
Is called when there are no observers that need to read the body.
|
protected List<MessageObserver> observers
public void read()
throws IOException
IOExceptionpublic void discard()
throws IOException
IOExceptionprotected void markAsRead()
protected abstract void readLocal()
throws IOException
IOExceptionpublic byte[] getContent()
throws IOException
getContent() might return a byte representation of
Wikipedia in chunks.The return value does not differ whether "Transfer-Encoding: chunked" is used or not (see http://en.wikipedia.org/wiki/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 use getContentAsStream() instead.IOExceptionpublic InputStream getContentAsStream() throws IOException
IOExceptionpublic void write(AbstractBodyTransferrer out) throws IOException
IOExceptionprotected abstract void writeAlreadyRead(AbstractBodyTransferrer out) throws IOException
IOExceptionprotected abstract void writeNotRead(AbstractBodyTransferrer out) throws IOException
IOExceptionprotected abstract void writeStreamed(AbstractBodyTransferrer out) throws IOException
IOExceptionpublic int getLength()
throws IOException
isRead() to determine wether the body already has been read, if necessary.getContent()IOExceptionpublic byte[] getRaw()
throws IOException
4 Wiki 5 pedia E in chunks. 0
IOExceptionprotected abstract byte[] getRawLocal()
throws IOException
IOExceptionprotected boolean hasRelevantObservers()
public String toString()
public boolean isRead()
public List<MessageObserver> getObservers()
public boolean wasStreamed()
public void setWasStreamed(boolean wasStreamed)
Copyright © 2022. All Rights Reserved.