Package org.frankframework.stream
Class Message
java.lang.Object
org.frankframework.stream.Message
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
- Direct Known Subclasses:
FileMessage
,PartMessage
,PathMessage
,UrlMessage
- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionMessage
(byte[] request) Message
(byte[] request, MessageContext context) Message
(InputStream request) Message
(InputStream request, String charset) Message
(InputStream request, MessageContext context) Message
(Reader request, MessageContext context) Message
(String request, MessageContext context) protected
Message
(ThrowingSupplier<InputStream, Exception> request, MessageContext context, Class<?> requestClass) Constructor for Message using InputStream supplier.protected
Message
(SerializableFileReference request, MessageContext context, Class<?> requestClass) Constructor for Message using aSerializableFileReference
.Message
(Node request, MessageContext context) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
return the request object as a byte array.byte[]
asByteArray
(String defaultEncodingCharset) return the request object as aInputSource
.return the request object as aInputStream
.asInputStream
(String defaultEncodingCharset) static Message
Please note that this method should only be used when you don't know the type of object.asObject()
Deprecated.Please avoid the use of the raw object.asReader()
return the request object as aReader
.void
asSource()
return the request object as aSource
.asString()
return the request object as a String.Can be called whenrequiresStream()
is true to retrieve a copy of (part of) the stream that is in this message, after the stream has been closed.void
captureBinaryStream
(OutputStream outputStream) void
captureBinaryStream
(OutputStream outputStream, int maxSize) Can be called whenrequiresStream()
is true to retrieve a copy of (part of) the stream that is in this message, after the stream has been closed.void
captureCharacterStream
(Writer writer) void
captureCharacterStream
(Writer writer, int maxSize) void
close()
void
closeOnCloseOf
(PipeLineSession session, String requester) void
closeOnCloseOf
(PipeLineSession session, INamedObject requester) protected String
computeDecodingCharset
(String defaultDecodingCharset) If no charset was provided and the requested charset isauto, try to parse the charset.
Creates a copy of this Message object.Representing a charset of binary requestsbyte[]
getMagic()
Reads the first 10k of a message.byte[]
getMagic
(int readLimit) Reads the first N bytes message, specified by parameterreadLimit
.Returns the message identifier and which resource class it representsstatic boolean
hasDataAvailable
(Message message) Check if a message has any data available.boolean
isBinary()
boolean
isClosed()
boolean
isEmpty()
Check if a message is empty.static boolean
Check if the message passed is null or empty.boolean
isNull()
static boolean
boolean
boolean
isRequestOfType
(Class<?> clazz) boolean
static Message
static Message
nullMessage
(MessageContext context) void
preserve()
Notify the message object that the request object will be used multiple times.boolean
If true, the Message should preferably be read using a streaming method, i.e. asReader() or asInputStream(), to avoid copying it into memory.long
size()
toString()
toString can be used to inspect the message.void
-
Field Details
-
MESSAGE_SIZE_UNKNOWN
public static final long MESSAGE_SIZE_UNKNOWN- See Also:
-
MESSAGE_MAX_IN_MEMORY_DEFAULT
public static final long MESSAGE_MAX_IN_MEMORY_DEFAULT- See Also:
-
MESSAGE_MAX_IN_MEMORY_PROPERTY
- See Also:
-
-
Constructor Details
-
Message
-
Message
-
Message
-
Message
-
Message
public Message(byte[] request) -
Message
-
Message
-
Message
protected Message(ThrowingSupplier<InputStream, Exception> request, @Nonnull MessageContext context, Class<?> requestClass) Constructor for Message using InputStream supplier. It is assumed the InputStream can be supplied multiple times. -
Message
protected Message(SerializableFileReference request, @Nonnull MessageContext context, Class<?> requestClass) Constructor for Message using aSerializableFileReference
.- Parameters:
request
- Request asSerializableFileReference
context
-MessageContext
requestClass
-Class
of the original request from which theSerializableFileReference
request was created
-
Message
-
Message
-
Message
-
Message
-
Message
-
-
Method Details
-
nullMessage
-
nullMessage
-
copyContext
-
getCharset
Representing a charset of binary requests- Returns:
- the charset provided when the message was created
-
computeDecodingCharset
If no charset was provided and the requested charset isauto, try to parse the charset. If unsuccessful return the default;
UTF-8
.- Throws:
IOException
-
preserve
Notify the message object that the request object will be used multiple times. If the request object can only be read one time, it can turn it into a less volatile representation. For instance, it could replace an InputStream with a byte array or String.- Throws:
IOException
- Throws IOException if the Message can not be read or writing fails.
-
asObject
Deprecated.Please avoid the use of the raw object. -
isBinary
public boolean isBinary() -
isRepeatable
public boolean isRepeatable() -
requiresStream
public boolean requiresStream()If true, the Message should preferably be read using a streaming method, i.e. asReader() or asInputStream(), to avoid copying it into memory. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
closeOnCloseOf
-
closeOnCloseOf
-
isScheduledForCloseOnExitOf
-
unscheduleFromCloseOnExitOf
-
asReader
return the request object as aReader
. Should not be called more than once, if request is notpreserved
.- Throws:
IOException
-
asReader
- Throws:
IOException
-
asInputStream
return the request object as aInputStream
. Should not be called more than once, if request is notpreserved
.- Throws:
IOException
-
asInputStream
@Nullable public InputStream asInputStream(@Nullable String defaultEncodingCharset) throws IOException - Parameters:
defaultEncodingCharset
- is only used when the Message object is of character type (String)- Throws:
IOException
-
getMagic
Reads the first 10k of a message. If the message does not support markSupported it is wrapped in a buffer.- Throws:
IOException
-
getMagic
Reads the first N bytes message, specified by parameterreadLimit
. If the message does not support markSupported it is wrapped in a buffer.- Parameters:
readLimit
- amount of bytes to read.- Throws:
IOException
-
asInputSource
return the request object as aInputSource
. Should not be called more than once, if request is notpreserved
.- Throws:
IOException
-
asSource
return the request object as aSource
. Should not be called more than once, if request is notpreserved
.- Throws:
IOException
SAXException
-
asByteArray
return the request object as a byte array. Has the side effect of preserving the input as byte array.- Throws:
IOException
-
asByteArray
- Throws:
IOException
-
asString
return the request object as a String. Has the side effect of preserving the input as a String.- Throws:
IOException
-
asString
- Throws:
IOException
-
isNull
public boolean isNull() -
isRequestOfType
- Returns:
- true if the request is or extends of the specified type at parameter clazz
-
isEmpty
public boolean isEmpty()Check if a message is empty. If message size cannot be determined, returnfalse
to be on the safe side although this might not be strictly correct.- Returns:
true
if the message is empty,false
if message is not empty or if the size cannot be determined up-front.
-
toString
toString can be used to inspect the message. It does not convert the 'request' to a string. -
getObjectId
Returns the message identifier and which resource class it represents- Returns:
- Message[1234abcd:ByteArrayInputStream]
-
asMessage
Please note that this method should only be used when you don't know the type of object. In all other cases, use the constructor ofMessage
or a more applicable subclass likeFileMessage
orUrlMessage
- Returns:
- a Message of the correct type for the given object
-
isEmpty
Check if the message passed is null or empty.- Parameters:
message
- Message to check. Can benull
.- Returns:
- Returns
true
if the message isnull
, otherwise the result ofisEmpty()
.
-
hasDataAvailable
Check if a message has any data available. This will correctly returntrue
orfalse
even when the message size cannot be determined. However, to do so, some I/O may have to be performed on the message thus making this a potentially expensive operation which may throw anIOException
. All I/O is done in such a way that no message data is lost (see alsogetMagic(int)
).- Parameters:
message
- Message to check. May benull
.- Returns:
- Returns
false
if the message isnull
or ofsize()
returns 0. Returnstrue
ifsize()
returns a positive value. Ifsize()
returnsMESSAGE_SIZE_UNKNOWN
then checks if any data can be read viagetMagic(int)
. - Throws:
IOException
- Throws an IOException if checking for data in the message throws an IOException.
-
isNull
-
assertNotClosed
public void assertNotClosed() -
size
public long size()- Returns:
- Message size or -1 if it can't determine the size.
-
captureBinaryStream
Can be called whenrequiresStream()
is true to retrieve a copy of (part of) the stream that is in this message, after the stream has been closed. Primarily for debugging purposes.- Throws:
IOException
-
captureBinaryStream
- Throws:
IOException
-
captureBinaryStream
- Throws:
IOException
-
captureCharacterStream
Can be called whenrequiresStream()
is true to retrieve a copy of (part of) the stream that is in this message, after the stream has been closed. Primarily for debugging purposes.When isBinary() is true the Message's charset is used when present to create a Reader that reads the InputStream. When charset not present
StreamUtil.DEFAULT_INPUT_STREAM_ENCODING
is used.- Throws:
IOException
-
captureCharacterStream
- Throws:
IOException
-
captureCharacterStream
- Throws:
IOException
-
copyMessage
Creates a copy of this Message object.NB: To copy the underlying value of the message object, the message may be preserved if it was not repeatable.
- Returns:
- A new Message object that is a copy of this Message.
- Throws:
IOException
- If an I/O error occurs during the copying process.
-
getRequestClass
-
getContext
-
isClosed
public boolean isClosed()
-