public class Message extends Object implements Serializable, Closeable
Modifier and Type | Field and Description |
---|---|
static long |
MESSAGE_MAX_IN_MEMORY_DEFAULT |
static long |
MESSAGE_SIZE_UNKNOWN |
Modifier | Constructor and Description |
---|---|
|
Message(byte[] request) |
|
Message(byte[] request,
MessageContext context) |
|
Message(byte[] request,
String charset) |
|
Message(InputStream request) |
|
Message(InputStream request,
MessageContext context) |
|
Message(InputStream request,
String charset) |
|
Message(Node request) |
|
Message(Node request,
MessageContext context) |
|
Message(Reader request) |
|
Message(Reader request,
MessageContext context) |
protected |
Message(SerializableFileReference request,
MessageContext context,
Class<?> requestClass)
Constructor for Message using a
SerializableFileReference . |
|
Message(String request) |
|
Message(String request,
MessageContext context) |
protected |
Message(ThrowingSupplier<InputStream,Exception> request,
MessageContext 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 . |
InputStream |
asInputStream(String defaultEncodingCharset) |
static Message |
asMessage(Object object) |
Object |
asObject()
Deprecated.
Please avoid the use of the raw object.
|
Reader |
asReader()
return the request object as a
Reader . |
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 |
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() |
Message |
copyMessage()
Creates a copy of this Message object.
|
String |
getCharset()
Representing a charset of binary requests
|
byte[] |
getMagic()
Reads the first 10k of a message.
|
byte[] |
getMagic(int readLimit)
Reads the first N bytes message, specified by parameter
readLimit . |
String |
getObjectId()
Returns the message identifier and which resource class it represents
|
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() |
String |
toString()
toString can be used to inspect the message.
|
void |
unscheduleFromCloseOnExitOf(PipeLineSession session) |
public static final long MESSAGE_SIZE_UNKNOWN
public static final long MESSAGE_MAX_IN_MEMORY_DEFAULT
public Message(String request, @Nonnull MessageContext context)
public Message(String request)
public Message(byte[] request, String charset)
public Message(byte[] request, @Nonnull MessageContext context)
public Message(byte[] request)
public Message(Reader request, @Nonnull MessageContext context)
public Message(Reader request)
protected Message(ThrowingSupplier<InputStream,Exception> request, @Nonnull MessageContext context, Class<?> requestClass)
protected Message(SerializableFileReference request, @Nonnull MessageContext context, Class<?> requestClass)
SerializableFileReference
.request
- Request as SerializableFileReference
context
- MessageContext
requestClass
- Class
of the original request from which the SerializableFileReference
request was createdpublic Message(InputStream request, String charset)
public Message(InputStream request, @Nonnull MessageContext context)
public Message(InputStream request)
public Message(Node request, @Nonnull MessageContext context)
public Message(Node request)
@Nonnull public static Message nullMessage(@Nonnull MessageContext context)
@Nonnull public MessageContext copyContext()
@Nullable public String getCharset()
@Nonnull 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
- Throws IOException if the Message can not be read or writing fails.@Deprecated @Nullable public Object asObject()
public boolean isBinary()
public boolean isRepeatable()
public boolean requiresStream()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void closeOnCloseOf(@Nonnull PipeLineSession session, INamedObject requester)
public void closeOnCloseOf(@Nonnull PipeLineSession session, String requester)
public boolean isScheduledForCloseOnExitOf(@Nonnull PipeLineSession session)
public void unscheduleFromCloseOnExitOf(@Nonnull PipeLineSession session)
@Nullable public Reader asReader() throws IOException
Reader
. Should not be called more than once, if request is not preserved
.IOException
@Nullable public Reader asReader(@Nullable String defaultDecodingCharset) throws IOException
IOException
@Nullable public InputStream asInputStream() throws IOException
InputStream
. Should not be called more than once, if request is not preserved
.IOException
@Nullable public InputStream asInputStream(@Nullable 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
@Nullable public InputSource asInputSource() throws IOException
InputSource
. Should not be called more than once, if request is not preserved
.IOException
@Nullable public Source asSource() throws IOException, SAXException
Source
. Should not be called more than once, if request is not preserved
.IOException
SAXException
@Nullable public byte[] asByteArray() throws IOException
IOException
@Nullable public byte[] asByteArray(@Nullable String defaultEncodingCharset) throws IOException
IOException
@Nullable public String asString() throws IOException
IOException
@Nullable public String asString(@Nullable 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 String toString()
public String getObjectId()
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
@Nonnull public Message copyMessage() throws IOException
NB: To copy the underlying value of the message object, the message may be preserved if it was not repeatable.
IOException
- If an I/O error occurs during the copying process.Copyright © 2023 Frank!Framework. All rights reserved.