Package org.simpleframework.http.core
Class CloseEncoder
java.lang.Object
org.simpleframework.http.core.CloseEncoder
- All Implemented Interfaces:
BodyEncoder
The
CloseEncoder
is used to close a connection once
all of the content has been produced. This is typically used if
the connected client supports the HTTP/1.0 protocol and there is
no Connection header with the keep-alive token. For reasons of
performance this should not be used for HTTP/1.1 clients.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BodyObserver
This is the observer used to notify the selector of events.private final ByteWriter
This is the underlying writer used to deliver the raw data. -
Constructor Summary
ConstructorsConstructorDescriptionCloseEncoder
(BodyObserver observer, ByteWriter writer) Constructor for theCloseEncoder
object. -
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 complaint format and sent it to the client.void
encode
(byte[] array, int off, int len) This method is used to encode the provided array of bytes in a HTTP/1.1 complaint 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 len) 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.
-
Field Details
-
observer
This is the observer used to notify the selector of events. -
writer
This is the underlying writer used to deliver the raw data.
-
-
Constructor Details
-
CloseEncoder
Constructor for theCloseEncoder
object. This is used to create a producer that will close the underlying socket as a means to signal that the response is fully sent. This is typically used with HTTP/1.0 connections.- Parameters:
observer
- this is used to deliver signals to the kernelwriter
- this is used to send to the underlying transport
-
-
Method Details
-
encode
This method is used to encode the provided array of bytes in a HTTP/1.1 complaint 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.- Specified by:
encode
in interfaceBodyEncoder
- 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 complaint 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.- Specified by:
encode
in interfaceBodyEncoder
- Parameters:
array
- this is the array of bytes to send to the clientoff
- this is the offset within the array to send fromlen
- 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.- Specified by:
encode
in interfaceBodyEncoder
- 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.- Specified by:
encode
in interfaceBodyEncoder
- Parameters:
buffer
- this is the buffer of bytes to send to the clientoff
- this is the offset within the buffer to send fromlen
- 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.- Specified by:
flush
in interfaceBodyEncoder
- 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 close the underlying transport which tells the client that all of the content has been sent over the connection.- Specified by:
close
in interfaceBodyEncoder
- Throws:
IOException
-