Package org.simpleframework.http.core
Interface BodyEncoder
- All Known Implementing Classes:
ChunkedEncoder
,CloseEncoder
,EmptyEncoder
,FixedLengthEncoder
interface BodyEncoder
The
BodyEncoder
object is used to encode content from
the HTTP response. This acts in much the same way as an output
stream would. As a requirement of RFC 2616 any HTTP/1.1 compliant
server must support a set of transfer types. These are fixed size,
chunked encoded, and connection close. A producer implementation
is required to implement one of this formats for delivery of the
response message.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
This is used to signal to the producer that all content has been written and the user no longer needs to write.void
encode
(byte[] array) This method is used to encode the provided array of bytes in a HTTP/1.1 compliant format and sent it to the client.void
encode
(byte[] array, int off, int size) This method is used to encode the provided array of bytes in a HTTP/1.1 compliant format and sent it to the client.void
encode
(ByteBuffer buffer) This method is used to encode the provided buffer of bytes in a HTTP/1.1 compliant format and sent it to the client.void
encode
(ByteBuffer buffer, int off, int size) This method is used to encode the provided buffer of bytes in a HTTP/1.1 compliant format and sent it to the client.void
flush()
This method is used to flush the contents of the buffer to the client.
-
Method Details
-
encode
This method is used to encode the provided array of bytes in a HTTP/1.1 compliant format and sent it to the client. Once the data has been encoded it is handed to the transport layer within the server, which may choose to buffer the data if the content is too small to send efficiently or if the socket is not write ready.- Parameters:
array
- this is the array of bytes to send to the client- Throws:
IOException
-
encode
This method is used to encode the provided array of bytes in a HTTP/1.1 compliant format and sent it to the client. Once the data has been encoded it is handed to the transport layer within the server, which may choose to buffer the data if the content is too small to send efficiently or if the socket is not write ready.- Parameters:
array
- this is the array of bytes to send to the clientoff
- this is the offset within the array to send fromsize
- this is the number of bytes that are to be sent- Throws:
IOException
-
encode
This method is used to encode the provided buffer of bytes in a HTTP/1.1 compliant format and sent it to the client. Once the data has been encoded it is handed to the transport layer within the server, which may choose to buffer the data if the content is too small to send efficiently or if the socket is not write ready.- Parameters:
buffer
- this is the buffer of bytes to send to the client- Throws:
IOException
-
encode
This method is used to encode the provided buffer of bytes in a HTTP/1.1 compliant format and sent it to the client. Once the data has been encoded it is handed to the transport layer within the server, which may choose to buffer the data if the content is too small to send efficiently or if the socket is not write ready.- Parameters:
buffer
- this is the buffer of bytes to send to the clientoff
- this is the offset within the buffer to send fromsize
- this is the number of bytes that are to be sent- Throws:
IOException
-
flush
This method is used to flush the contents of the buffer to the client. This method will block until such time as all of the data has been sent to the client. If at any point there is an error sending the content an exception is thrown.- Throws:
IOException
-
close
This is used to signal to the producer that all content has been written and the user no longer needs to write. This will either close the underlying transport or it will notify the monitor that the response has completed and the next request can begin. This ensures the content is flushed to the client.- Throws:
IOException
-