public class Attachment
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
Attachment(java.lang.String content,
MediaType mediaType)
Convenience constructor, where title is set to
null |
protected |
Attachment(java.lang.String content,
MediaType mediaType,
java.lang.String title)
Creates a new instance of this Attachment
|
Modifier and Type | Method and Description |
---|---|
static Attachment |
fromBase64(java.lang.String base64encodedContent,
MediaType mediaType)
Equivalent to
Attachment(String, MediaType) |
static Attachment |
fromBinaryBytes(byte[] bytes,
MediaType mediaType)
Creates an attachment from a given array of bytes.
|
static Attachment |
fromBinaryFile(java.io.File file,
MediaType mediaType)
Creates an attachment from the given binary file
file . |
static Attachment |
fromBinaryInputStream(java.io.InputStream inputStream,
MediaType mediaType)
Creates an attachment from a binary input stream.
|
static Attachment |
fromText(java.lang.String content,
MediaType mediaType)
Equivalent to
Attachment(String, MediaType) |
static Attachment |
fromTextFile(java.io.File file,
MediaType mediaType)
Creates a non-binary attachment from the given file.
|
static Attachment |
fromTextInputStream(java.io.InputStream inputStream,
MediaType mediaType)
Creates a non-binary attachment from the given file.
|
java.lang.String |
getContent()
The content of the attachment represented as a string.
|
java.lang.String |
getFileName()
An optional filename for the attachment.
|
MediaType |
getMediaType()
The type of the attachment.
|
boolean |
getShowDirectly()
Whether this attachment is shown showDirectly or not
|
java.lang.String |
getTitle()
An optional title of the attachment.
|
static Attachment |
json(java.lang.String content)
Creates a text attachment with the given content with media type application/json.
|
static Attachment |
plainText(java.lang.String content)
Creates a text attachment with the given content with media type text/plain.
|
Attachment |
showDirectly()
Directly shows this attachment in the report.
|
Attachment |
withFileName(java.lang.String fileName)
An optional filename for the attachment without the file type suffix.
|
Attachment |
withTitle(java.lang.String title)
Sets the title and returns
this |
static Attachment |
xml(java.lang.String content)
Creates a text attachment with the given content with media type text/xml.
|
protected Attachment(java.lang.String content, MediaType mediaType)
null
protected Attachment(java.lang.String content, MediaType mediaType, java.lang.String title)
content
- the content of this attachment. In case of a binary attachment, this must be
Base64 encoded. Must not be null
mediaType
- the mediaType. Must not be null
title
- an optional title, may be null
public java.lang.String getContent()
public MediaType getMediaType()
public java.lang.String getTitle()
null
.public java.lang.String getFileName()
null
.public Attachment withFileName(java.lang.String fileName)
public Attachment withTitle(java.lang.String title)
this
public Attachment showDirectly()
Note: This currently works only for images!
this
JGivenWrongUsageException
- if the attachment is not an imagepublic static Attachment fromBinaryBytes(byte[] bytes, MediaType mediaType)
java.lang.IllegalArgumentException
- if mediaType is not binarypublic static Attachment fromBinaryInputStream(java.io.InputStream inputStream, MediaType mediaType) throws java.io.IOException
java.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if mediaType is not binarypublic static Attachment fromBinaryFile(java.io.File file, MediaType mediaType) throws java.io.IOException
file
.
The content of the file will be transformed into a Base64 encoded string.java.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if mediaType is not binarypublic static Attachment fromTextFile(java.io.File file, MediaType mediaType) throws java.io.IOException
java.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if mediaType is either binary or has no specified charsetpublic static Attachment fromTextInputStream(java.io.InputStream inputStream, MediaType mediaType) throws java.io.IOException
java.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if mediaType is either binary or has no specified charsetpublic static Attachment fromText(java.lang.String content, MediaType mediaType)
Attachment(String, MediaType)
java.lang.IllegalArgumentException
- if mediaType is binarypublic static Attachment plainText(java.lang.String content)
content
- the content of the attachmentpublic static Attachment xml(java.lang.String content)
content
- the content of the attachmentpublic static Attachment json(java.lang.String content)
content
- the content of the attachmentpublic static Attachment fromBase64(java.lang.String base64encodedContent, MediaType mediaType)
Attachment(String, MediaType)
java.lang.IllegalArgumentException
- if mediaType is not binarypublic boolean getShowDirectly()
showDirectly