public class Message extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected org.apache.logging.log4j.Logger |
log |
static long |
MESSAGE_SIZE_UNKNOWN |
Modifier | Constructor and Description |
---|---|
|
Message(byte[] request) |
|
Message(byte[] request,
Map<String,Object> context) |
|
Message(byte[] request,
String charset) |
|
Message(InputStream request) |
|
Message(InputStream request,
Map<String,Object> context) |
|
Message(InputStream request,
String charset) |
|
Message(Node request) |
|
Message(Node request,
Map<String,Object> context) |
|
Message(Reader request) |
|
Message(Reader request,
Map<String,Object> context) |
|
Message(String request) |
|
Message(String request,
Map<String,Object> context) |
protected |
Message(ThrowingSupplier<InputStream,Exception> request,
Map<String,Object> context,
Class<?> requestClass)
Constructor for Message using InputStream supplier.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
asByteArray()
return the request object as a byte array.
|
static byte[] |
asByteArray(Object object) |
static byte[] |
asByteArray(Object object,
String defaultCharset) |
byte[] |
asByteArray(String defaultEncodingCharset) |
InputSource |
asInputSource()
return the request object as a
InputSource . |
static InputSource |
asInputSource(Object object) |
InputStream |
asInputStream()
return the request object as a
InputStream . |
static InputStream |
asInputStream(Object object) |
static InputStream |
asInputStream(Object object,
String defaultCharset) |
InputStream |
asInputStream(String defaultEncodingCharset) |
static Message |
asMessage(Object object) |
Object |
asObject()
Deprecated.
Please avoid the use of the raw object.
|
static Object |
asObject(Object object)
Deprecated.
|
Reader |
asReader()
return the request object as a
Reader . |
static Reader |
asReader(Object object) |
static Reader |
asReader(Object object,
String defaultCharset) |
Reader |
asReader(String defaultDecodingCharset) |
Source |
asSource()
return the request object as a
Source . |
static Source |
asSource(Object object) |
String |
asString()
return the request object as a String.
|
static String |
asString(Object object) |
static String |
asString(Object object,
String defaultCharset) |
String |
asString(String decodingCharset) |
ByteArrayOutputStream |
captureBinaryStream()
Can be called when
requiresStream() 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) |
StringWriter |
captureCharacterStream()
Can be called when
requiresStream() 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 |
closeOnClose(AutoCloseable resource) |
void |
closeOnCloseOf(PipeLineSession session,
INamedObject requester) |
void |
closeOnCloseOf(PipeLineSession session,
String requester) |
protected String |
computeDecodingCharset(String defaultDecodingCharset)
If no charset was provided and the requested charset is
auto, try to parse the charset. |
MessageContext |
copyContext() |
String |
getCharset()
Representing a charset of binary requests
|
protected String |
getId() |
byte[] |
getMagic()
Reads the first 10k of a message.
|
byte[] |
getMagic(int readLimit)
Reads the first N bytes message, specified by parameter
readLimit . |
static boolean |
hasDataAvailable(Message message)
Check if a message has any data available.
|
boolean |
isBinary() |
boolean |
isEmpty()
Check if a message is empty.
|
static boolean |
isEmpty(Message message)
Check if the message passed is null or empty.
|
boolean |
isNull() |
static boolean |
isNull(Message message) |
boolean |
isRepeatable() |
boolean |
isScheduledForCloseOnExitOf(PipeLineSession session) |
static Message |
nullMessage() |
static Message |
nullMessage(MessageContext context) |
void |
preserve()
Notify the message object that the request object will be used multiple times.
|
boolean |
requiresStream()
If true, the Message should preferably be read using a streaming method, i.e.
|
long |
size()
Note that the size may not be an exact measure of the content size and may or may not account for any encoding of the content.
|
String |
toString()
toString can be used to inspect the message.
|
String |
toStringPrefix() |
void |
toStringPrefix(Writer writer) |
void |
unscheduleFromCloseOnExitOf(PipeLineSession session) |
public static final long MESSAGE_SIZE_UNKNOWN
protected transient org.apache.logging.log4j.Logger log
public Message(String request)
public Message(byte[] request, String charset)
public Message(byte[] request)
public Message(Reader request)
protected Message(ThrowingSupplier<InputStream,Exception> request, Map<String,Object> context, Class<?> requestClass)
public Message(InputStream request, String charset)
public Message(InputStream request, Map<String,Object> context)
public Message(InputStream request)
public Message(Node request)
public static Message nullMessage()
public static Message nullMessage(MessageContext context)
public MessageContext copyContext()
public String getCharset()
protected String computeDecodingCharset(String defaultDecodingCharset) throws IOException
auto, try to parse the charset.
If unsuccessful return the default; UTF-8
.
IOException
public void preserve() throws IOException
IOException
@Deprecated public Object asObject()
public boolean isBinary()
public boolean isRepeatable()
public boolean requiresStream()
public void closeOnClose(AutoCloseable resource)
public void closeOnCloseOf(PipeLineSession session, INamedObject requester)
public void closeOnCloseOf(PipeLineSession session, String requester)
public boolean isScheduledForCloseOnExitOf(PipeLineSession session)
public void unscheduleFromCloseOnExitOf(PipeLineSession session)
public Reader asReader() throws IOException
Reader
. Should not be called more than once, if request is not preserved
.IOException
public Reader asReader(String defaultDecodingCharset) throws IOException
IOException
public InputStream asInputStream() throws IOException
InputStream
. Should not be called more than once, if request is not preserved
.IOException
public InputStream asInputStream(String defaultEncodingCharset) throws IOException
defaultEncodingCharset
- is only used when the Message object is of character type (String)IOException
@Nonnull public byte[] getMagic() throws IOException
IOException
@Nonnull public byte[] getMagic(int readLimit) throws IOException
readLimit
. If the message does not support markSupported it is wrapped in a buffer.readLimit
- amount of bytes to read.IOException
public InputSource asInputSource() throws IOException
InputSource
. Should not be called more than once, if request is not preserved
.IOException
public Source asSource() throws IOException, SAXException
Source
. Should not be called more than once, if request is not preserved
.IOException
SAXException
public byte[] asByteArray() throws IOException
IOException
public byte[] asByteArray(String defaultEncodingCharset) throws IOException
IOException
public String asString() throws IOException
IOException
public String asString(String decodingCharset) throws IOException
IOException
public boolean isNull()
public boolean isEmpty()
false
to be on the safe side although this
might not be strictly correct.true
if the message is empty, if message is not empty or if the size cannot be determined up-front.public void toStringPrefix(Writer writer) throws IOException
IOException
public String toStringPrefix()
public String toString()
protected String getId()
@Deprecated public static Object asObject(Object object)
public static Reader asReader(Object object) throws IOException
IOException
public static Reader asReader(Object object, String defaultCharset) throws IOException
IOException
public static InputStream asInputStream(Object object) throws IOException
IOException
public static InputStream asInputStream(Object object, String defaultCharset) throws IOException
IOException
public static InputSource asInputSource(Object object) throws IOException
IOException
public static Source asSource(Object object) throws IOException, SAXException
IOException
SAXException
public static String asString(Object object) throws IOException
IOException
public static String asString(Object object, String defaultCharset) throws IOException
IOException
public static byte[] asByteArray(Object object) throws IOException
IOException
public static byte[] asByteArray(Object object, String defaultCharset) throws IOException
IOException
public static boolean isEmpty(Message message)
message
- Message to check. Can be null
.true
if the message is null
, otherwise the result of isEmpty()
.public static boolean hasDataAvailable(Message message) throws IOException
true
or false
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 an IOException
.
All I/O is done in such a way that no message data is lost (see also getMagic(int)
).message
- Message to check. May be null
.false
if the message is null
or of size()
returns 0.
Returns true
if size()
returns a positive value.
If size()
returns MESSAGE_SIZE_UNKNOWN
then checks if any data can
be read via getMagic(int)
.IOException
- Throws an IOException if checking for data in the message throws an IOException.public static boolean isNull(Message message)
public long size()
public ByteArrayOutputStream captureBinaryStream() throws IOException
requiresStream()
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.IOException
public void captureBinaryStream(OutputStream outputStream) throws IOException
IOException
public void captureBinaryStream(OutputStream outputStream, int maxSize) throws IOException
IOException
public StringWriter captureCharacterStream() throws IOException
requiresStream()
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.
IOException
public void captureCharacterStream(Writer writer) throws IOException
IOException
public void captureCharacterStream(Writer writer, int maxSize) throws IOException
IOException
Copyright © 2023 Frank!Framework. All rights reserved.