Package com.helger.phase4.attachment
Class WSS4JAttachment
java.lang.Object
org.apache.wss4j.common.ext.Attachment
com.helger.phase4.attachment.WSS4JAttachment
- All Implemented Interfaces:
IAS4Attachment
@NotThreadSafe
public class WSS4JAttachment
extends org.apache.wss4j.common.ext.Attachment
implements IAS4Attachment
Special WSS4J attachment with an InputStream provider instead of a fixed InputStream
Note: cannot be serializable because base class is not serializable and because we're dealing with
Note: cannot be serializable because base class is not serializable and because we're dealing with
InputStreams.- Author:
- bayerlma, Philip Helger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWSS4JAttachment(@NonNull AS4ResourceHelper aResHelper, @Nullable String sMimeType) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidvoidaddToMimeMultipart(@NonNull jakarta.mail.internet.MimeMultipart aMimeMultipart) static booleancanBeKeptInMemory(long nBytes) Check if an incoming attachment can be kept in memory, or if a temporary file is needed.static @NonNull WSS4JAttachmentcreateIncomingFileAttachment(@NonNull jakarta.mail.internet.MimeBodyPart aBodyPart, @NonNull AS4ResourceHelper aResHelper) static @NonNull WSS4JAttachmentcreateOutgoingFileAttachment(byte @NonNull [] aSrcData, @Nullable String sContentID, @Nullable String sFilename, @NonNull com.helger.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @NonNull AS4ResourceHelper aResHelper) Quasi constructor.static @NonNull WSS4JAttachmentcreateOutgoingFileAttachment(@NonNull AS4OutgoingAttachment aAttachment, @NonNull AS4ResourceHelper aResHelper) static @NonNull WSS4JAttachmentcreateOutgoingFileAttachment(@NonNull File aSrcFile, @Nullable String sContentID, @Nullable String sFilename, @NonNull com.helger.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @NonNull AS4ResourceHelper aResHelper) Quasi constructor.final @Nullable CharsetgetCharsetOrDefault(@Nullable Charset aDefault) Get the specified character set or the provided default value.final @Nullable EAS4CompressionModefinal @NonNull com.helger.mail.cte.EContentTransferEncoding@Nullable com.helger.base.io.iface.IHasInputStreamThis is primarily an internal method.final @NonNull AS4ResourceHelper@NonNull InputStreamGet the source stream of the attachment using the default resource helper.@NonNull InputStreamgetSourceStream(@NonNull AS4ResourceHelper aResourceHelper) Get the source stream of the attachment using the provided resource helper, to automatically close the stream at the end of the message.@Nullable Stringfinal booleanfinal voidoverwriteMimeType(@Nullable String sMimeType) final @NonNull WSS4JAttachmentsetCharset(@Nullable Charset aCharset) final @NonNull WSS4JAttachmentsetCompressionMode(@NonNull EAS4CompressionMode eCompressionMode) final @NonNull WSS4JAttachmentsetContentTransferEncoding(@NonNull com.helger.mail.cte.EContentTransferEncoding eCTE) final voidsetMimeType(@Nullable String sMimeType) Deprecated.Do not use this.voidsetSourceStream(InputStream sourceStream) Deprecated.Do not use this, because it can be opened only once.voidsetSourceStreamProvider(@NonNull com.helger.base.io.iface.IHasInputStream aISP) voidCreate a random UUID based ID and callAttachment.setId(String)toString()Methods inherited from class org.apache.wss4j.common.ext.Attachment
addHeaders, getHeaders, getId, getMimeType, setIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.phase4.attachment.IAS4Attachment
getCharset, getId, getMimeType, hasCompressionMode, isRepeatable
-
Field Details
-
CONTENT_DESCRIPTION_ATTACHMENT
- See Also:
-
CONTENT_ID_PREFIX
- See Also:
-
CONTENT_ID_SUFFIX
- See Also:
-
-
Constructor Details
-
WSS4JAttachment
public WSS4JAttachment(@WillNotClose @NonNull AS4ResourceHelper aResHelper, @Nullable String sMimeType)
-
-
Method Details
-
getResHelper
- Returns:
- The resource helper provided in the constructor. Never
null.
-
setUniqueID
public void setUniqueID()Create a random UUID based ID and callAttachment.setId(String) -
setMimeType
@Deprecated(forRemoval=false) @UnsupportedOperation public final void setMimeType(@Nullable String sMimeType) Deprecated.Do not use this. If you need to use this, useoverwriteMimeType(String)- Overrides:
setMimeTypein classorg.apache.wss4j.common.ext.Attachment
-
overwriteMimeType
-
addHeader
- Overrides:
addHeaderin classorg.apache.wss4j.common.ext.Attachment
-
getUncompressedMimeType
- Specified by:
getUncompressedMimeTypein interfaceIAS4Attachment- Returns:
- The MIME type of the uncompressed attachment. May be
null. This is only set, if compression was active. Otherwise useIAS4Attachment.getMimeType(). - See Also:
-
getSourceStream
Description copied from interface:IAS4AttachmentGet the source stream of the attachment using the default resource helper. The streams retrieved by this method are automatically closed when the respective resource helper goes out of scope.- Specified by:
getSourceStreamin interfaceIAS4Attachment- Overrides:
getSourceStreamin classorg.apache.wss4j.common.ext.Attachment- Returns:
- A non-
nullInputStream on the source.
-
getSourceStream
Description copied from interface:IAS4AttachmentGet the source stream of the attachment using the provided resource helper, to automatically close the stream at the end of the message. This can be helpful, if the source helper is already out of scope.- Specified by:
getSourceStreamin interfaceIAS4Attachment- Parameters:
aResourceHelper- The resource helper to use. May not benull.- Returns:
- A non-
nullInputStream on the source.
-
setSourceStream
@Deprecated(forRemoval=false) @UnsupportedOperation public void setSourceStream(InputStream sourceStream) Deprecated.Do not use this, because it can be opened only once. UsesetSourceStreamProvider(IHasInputStream)instead.- Overrides:
setSourceStreamin classorg.apache.wss4j.common.ext.Attachment
-
getInputStreamProvider
public @Nullable com.helger.base.io.iface.IHasInputStream getInputStreamProvider()Description copied from interface:IAS4AttachmentThis is primarily an internal method. If you use it, you need to make sure to close the streams yourself if you open them.- Specified by:
getInputStreamProviderin interfaceIAS4Attachment- Returns:
- The internal input stream provider. May be
null.
-
setSourceStreamProvider
public void setSourceStreamProvider(@NonNull com.helger.base.io.iface.IHasInputStream aISP) -
getContentTransferEncoding
public final @NonNull com.helger.mail.cte.EContentTransferEncoding getContentTransferEncoding()- Specified by:
getContentTransferEncodingin interfaceIAS4Attachment- Returns:
- The content transfer encoding to be used. Required for MIME multipart handling only.
May not be
null.
-
setContentTransferEncoding
public final @NonNull WSS4JAttachment setContentTransferEncoding(@NonNull com.helger.mail.cte.EContentTransferEncoding eCTE) -
getCompressionMode
- Specified by:
getCompressionModein interfaceIAS4Attachment- Returns:
- The compression mode to use or
nullif the attachment is not compressed.
-
setCompressionMode
public final @NonNull WSS4JAttachment setCompressionMode(@NonNull EAS4CompressionMode eCompressionMode) -
getCharsetOrDefault
Description copied from interface:IAS4AttachmentGet the specified character set or the provided default value.- Specified by:
getCharsetOrDefaultin interfaceIAS4Attachment- Parameters:
aDefault- The default value to be returned, if no character set is provided. May benull.- Returns:
- Only
nullif no character set is defined and the provided default value isnull.
-
hasCharset
public final boolean hasCharset()- Specified by:
hasCharsetin interfaceIAS4Attachment- Returns:
trueif a character set is defined,falseif not.
-
setCharset
-
addToMimeMultipart
public void addToMimeMultipart(@NonNull jakarta.mail.internet.MimeMultipart aMimeMultipart) throws jakarta.mail.MessagingException - Throws:
jakarta.mail.MessagingException
-
customPartProperties
@ReturnsMutableObject public @NonNull com.helger.collection.commons.ICommonsOrderedMap<String,String> customPartProperties()- Specified by:
customPartPropertiesin interfaceIAS4Attachment- Returns:
- A non-
nullbut maybe empty map of custom PartInfo/PartProperties for the UserMessage.
-
toString
-
createOutgoingFileAttachment
public static @NonNull WSS4JAttachment createOutgoingFileAttachment(@NonNull AS4OutgoingAttachment aAttachment, @WillNotClose @NonNull AS4ResourceHelper aResHelper) throws IOException - Throws:
IOException
-
createOutgoingFileAttachment
public static @NonNull WSS4JAttachment createOutgoingFileAttachment(@NonNull File aSrcFile, @Nullable String sContentID, @Nullable String sFilename, @NonNull com.helger.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @WillNotClose @NonNull AS4ResourceHelper aResHelper) throws IOException Quasi constructor. Performs compression internally if necessary.- Parameters:
aSrcFile- Source, uncompressed, unencrypted file.sContentID- Content-ID of the attachment. Ifnulla random ID is created.sFilename- Filename of the attachment. May benullin which case noContent-Dispositionheader is created.aMimeType- Original mime type of the file.eCompressionMode- Optional compression mode to use. May benull.aCharset- The character set to use. May benull(since 0.14.0)aResHelper- The resource manager to use. May not benull.- Returns:
- The newly created attachment instance. Never
null. - Throws:
IOException- In case something goes wrong during compression
-
createOutgoingFileAttachment
public static @NonNull WSS4JAttachment createOutgoingFileAttachment(byte @NonNull [] aSrcData, @Nullable String sContentID, @Nullable String sFilename, @NonNull com.helger.mime.IMimeType aMimeType, @Nullable EAS4CompressionMode eCompressionMode, @Nullable Charset aCharset, @NonNull AS4ResourceHelper aResHelper) throws IOException Quasi constructor. Performs compression internally.- Parameters:
aSrcData- Source in-memory data, uncompressed, unencrypted.sContentID- Optional content ID ornullto create a random one. Filename of the attachment. May benullin which case noContent-Dispositionheader is created.sFilename- Optional filename to use in the "Content-Disposition" headers. May benull.aMimeType- Original mime type of the file. May not benull.eCompressionMode- Optional compression mode to use. May benull.aCharset- The character set to use. May benull(since 0.14.0)aResHelper- The resource manager to use. May not benull.- Returns:
- The newly created attachment instance. Never
null. - Throws:
IOException- In case something goes wrong during compression
-
canBeKeptInMemory
public static boolean canBeKeptInMemory(long nBytes) Check if an incoming attachment can be kept in memory, or if a temporary file is needed.- Parameters:
nBytes- File size.- Returns:
trueif the size is ≤ than 64 Kilobytes
-
createIncomingFileAttachment
public static @NonNull WSS4JAttachment createIncomingFileAttachment(@NonNull jakarta.mail.internet.MimeBodyPart aBodyPart, @NonNull AS4ResourceHelper aResHelper) throws jakarta.mail.MessagingException, IOException - Throws:
jakarta.mail.MessagingExceptionIOException
-