Package org.simpleframework.http.core
Class FixedLengthEncoder
- java.lang.Object
-
- org.simpleframework.http.core.FixedLengthEncoder
-
- All Implemented Interfaces:
BodyEncoder
class FixedLengthEncoder extends java.lang.Object implements BodyEncoder
TheFixedLengthEncoderobject produces content without any encoding, but limited to a fixed number of bytes. This is used if the length of the content being delivered is know beforehand. It will simply count the number of bytes being send and signal the server kernel that the next request is ready to read once all of the bytes have been sent to the client.- See Also:
FixedLengthConsumer
-
-
Field Summary
Fields Modifier and Type Field Description private longcountThis is the number of bytes that have been sent so far.private longlimitThis is the number of bytes this producer is limited to.private BodyObserverobserverThis is the observer used to notify the initiator of events.private ByteWriterwriterThis is the underlying writer used to deliver the raw data.
-
Constructor Summary
Constructors Constructor Description FixedLengthEncoder(BodyObserver observer, ByteWriter writer, long limit)Constructor for theFixedLengthEncoderobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to signal to the producer that all content has been written and the user no longer needs to write.voidencode(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.voidencode(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.voidencode(java.nio.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.voidencode(java.nio.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.voidflush()This method is used to flush the contents of the buffer to the client.
-
-
-
Field Detail
-
observer
private BodyObserver observer
This is the observer used to notify the initiator of events.
-
writer
private ByteWriter writer
This is the underlying writer used to deliver the raw data.
-
count
private long count
This is the number of bytes that have been sent so far.
-
limit
private long limit
This is the number of bytes this producer is limited to.
-
-
Constructor Detail
-
FixedLengthEncoder
public FixedLengthEncoder(BodyObserver observer, ByteWriter writer, long limit)
Constructor for theFixedLengthEncoderobject. This is used to create an encoder that will count the number of bytes that are sent over the pipeline, once all bytes have been sent this will signal that the next request is ready to read.- Parameters:
observer- this is used to deliver signals to the kernelwriter- this is used to send to the underlying transportlimit- this is used to limit the number of bytes sent
-
-
Method Detail
-
encode
public void encode(byte[] array) throws java.io.IOExceptionThis 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:
encodein interfaceBodyEncoder- Parameters:
array- this is the array of bytes to send to the client- Throws:
java.io.IOException
-
encode
public void encode(byte[] array, int off, int len) throws java.io.IOExceptionThis 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:
encodein 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:
java.io.IOException
-
encode
public void encode(java.nio.ByteBuffer buffer) throws java.io.IOExceptionThis 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:
encodein interfaceBodyEncoder- Parameters:
buffer- this is the buffer of bytes to send to the client- Throws:
java.io.IOException
-
encode
public void encode(java.nio.ByteBuffer buffer, int off, int len) throws java.io.IOExceptionThis 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:
encodein 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:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionThis 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:
flushin interfaceBodyEncoder- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionThis 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.- Specified by:
closein interfaceBodyEncoder- Throws:
java.io.IOException
-
-