public interface InstanceWriter
A writer dedicated to a specific instance. Method
write(java.io.OutputStream)
will write the instance
to the output stream, method instanceBytes()
will provide all the bytes of entity.
The caller decided which method to call depending on results of alwaysInMemory()
and contentLength()
.-
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether the byte array is always available.If we can determine the number of bytes to be written to the stream, provide the information here.byte[]
Get the instance as byte array.void
write
(OutputStream stream) Write the instance to the output stream.
-
Method Details
-
contentLength
OptionalLong contentLength()If we can determine the number of bytes to be written to the stream, provide the information here. The returned number must be a valid content length (content-length >= 0)- Returns:
- number of bytes or empty if not possible (or too expensive) to find out
-
alwaysInMemory
boolean alwaysInMemory()Whether the byte array is always available. If trueinstanceBytes()
will ALWAYS be called.- Returns:
- whether the bytes will always be materialized in memory
-
write
Write the instance to the output stream. This method is NEVER called ifalwaysInMemory()
istrue
, otherwise this method is ALWAYS called ifcontentLength()
returns empty. This method MAY be called ifcontentLength()
returns a value.- Parameters:
stream
- to write to
-
instanceBytes
byte[] instanceBytes()Get the instance as byte array. This method is always called ifalwaysInMemory()
returnstrue
. This method is NEVER called ifcontentLength()
returns empty. This method MAY be called ifcontentLength()
returns a value.- Returns:
- bytes of the instance
-