Class Message

java.lang.Object
org.frankframework.stream.Message
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable
Direct Known Subclasses:
FileMessage, PartMessage, PathMessage, UrlMessage

public class Message extends Object implements Serializable, Closeable
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • nullMessage

      @Nonnull public static Message nullMessage()
    • nullMessage

      @Nonnull public static Message nullMessage(@Nonnull MessageContext context)
    • copyContext

      @Nonnull public MessageContext copyContext()
    • getCharset

      @Nullable public String getCharset()
      Representing a charset of binary requests
      Returns:
      the charset provided when the message was created
    • computeDecodingCharset

      @Nonnull protected String computeDecodingCharset(String defaultDecodingCharset) throws IOException
      If no charset was provided and the requested charset is auto, try to parse the charset. If unsuccessful return the default; UTF-8.
      Throws:
      IOException
    • preserve

      public void preserve() throws IOException
      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 @Nullable public Object 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 interface AutoCloseable
      Specified by:
      close in interface Closeable
    • closeOnCloseOf

      public void closeOnCloseOf(@Nonnull PipeLineSession session, INamedObject requester)
    • closeOnCloseOf

      public void closeOnCloseOf(@Nonnull PipeLineSession session, String requester)
    • isScheduledForCloseOnExitOf

      public boolean isScheduledForCloseOnExitOf(@Nonnull PipeLineSession session)
    • unscheduleFromCloseOnExitOf

      public void unscheduleFromCloseOnExitOf(@Nonnull PipeLineSession session)
    • asReader

      @Nullable public Reader asReader() throws IOException
      return the request object as a Reader. Should not be called more than once, if request is not preserved.
      Throws:
      IOException
    • asReader

      @Nullable public Reader asReader(@Nullable String defaultDecodingCharset) throws IOException
      Throws:
      IOException
    • asInputStream

      @Nullable public InputStream asInputStream() throws IOException
      return the request object as a InputStream. Should not be called more than once, if request is not preserved.
      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

      @Nonnull public byte[] getMagic() throws IOException
      Reads the first 10k of a message. If the message does not support markSupported it is wrapped in a buffer.
      Throws:
      IOException
    • getMagic

      @Nonnull public byte[] getMagic(int readLimit) throws IOException
      Reads the first N bytes message, specified by parameter readLimit. If the message does not support markSupported it is wrapped in a buffer.
      Parameters:
      readLimit - amount of bytes to read.
      Throws:
      IOException
    • asInputSource

      @Nullable public InputSource asInputSource() throws IOException
      return the request object as a InputSource. Should not be called more than once, if request is not preserved.
      Throws:
      IOException
    • asSource

      @Nullable public Source asSource() throws IOException, SAXException
      return the request object as a Source. Should not be called more than once, if request is not preserved.
      Throws:
      IOException
      SAXException
    • asByteArray

      @Nullable public byte[] asByteArray() throws IOException
      return the request object as a byte array. Has the side effect of preserving the input as byte array.
      Throws:
      IOException
    • asByteArray

      @Nullable public byte[] asByteArray(@Nullable String defaultEncodingCharset) throws IOException
      Throws:
      IOException
    • asString

      @Nullable public String asString() throws IOException
      return the request object as a String. Has the side effect of preserving the input as a String.
      Throws:
      IOException
    • asString

      @Nullable public String asString(@Nullable String decodingCharset) throws IOException
      Throws:
      IOException
    • isNull

      public boolean isNull()
    • isRequestOfType

      public boolean isRequestOfType(Class<?> clazz)
      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, return false 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

      public String toString()
      toString can be used to inspect the message. It does not convert the 'request' to a string.
      Overrides:
      toString in class Object
    • getObjectId

      public String getObjectId()
      Returns the message identifier and which resource class it represents
      Returns:
      Message[1234abcd:ByteArrayInputStream]
    • asMessage

      public static Message asMessage(Object object)
      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 of Message or a more applicable subclass like FileMessage or UrlMessage
      Returns:
      a Message of the correct type for the given object
    • isEmpty

      public static boolean isEmpty(Message message)
      Check if the message passed is null or empty.
      Parameters:
      message - Message to check. Can be null.
      Returns:
      Returns true if the message is null, otherwise the result of isEmpty().
    • hasDataAvailable

      public static boolean hasDataAvailable(Message message) throws IOException
      Check if a message has any data available. This will correctly return 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)).

      Parameters:
      message - Message to check. May be null.
      Returns:
      Returns 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).
      Throws:
      IOException - Throws an IOException if checking for data in the message throws an IOException.
    • isNull

      public static boolean isNull(Message message)
    • assertNotClosed

      public void assertNotClosed()
    • size

      public long size()
      Returns:
      Message size or -1 if it can't determine the size.
    • captureBinaryStream

      public ByteArrayOutputStream captureBinaryStream() throws IOException
      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. Primarily for debugging purposes.
      Throws:
      IOException
    • captureBinaryStream

      public void captureBinaryStream(OutputStream outputStream) throws IOException
      Throws:
      IOException
    • captureBinaryStream

      public void captureBinaryStream(OutputStream outputStream, int maxSize) throws IOException
      Throws:
      IOException
    • captureCharacterStream

      public StringWriter captureCharacterStream() throws IOException
      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. 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

      public void captureCharacterStream(Writer writer) throws IOException
      Throws:
      IOException
    • captureCharacterStream

      public void captureCharacterStream(Writer writer, int maxSize) throws IOException
      Throws:
      IOException
    • copyMessage

      @Nonnull public Message copyMessage() throws IOException
      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

      @Nonnull public String getRequestClass()
    • getContext

      @Nonnull public MessageContext getContext()
    • isClosed

      public boolean isClosed()