Resource implementation for a given byte array.
Creates a ByteArrayInputStream for the given byte array.
Useful for loading content from any given byte array,
without having to resort to a single-use InputStreamResource.
Particularly useful for creating mail attachments from local content,
where JavaMail needs to be able to read the stream multiple times.
java.io.ByteArrayInputStream , InputStreamResource, org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
| Modifier and Type | Field and Description |
|---|---|
| private final byte[] | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ByteArrayResource(byte[]
the byte array to wrap byteArray, String where the byte array comes from description)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public long | contentLength()
Overrides org. Implements org. This implementation returns the length of the underlying byte array. |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides org. This implementation compares the underlying byte array. |
| public boolean | exists()
Overrides org. Implements org. This implementation always returns |
| public final byte[] | |
| public byte[] | getContentAsByteArray()
Overrides default org. Return the contents of this resource as a byte array. |
| public String | getContentAsString(Charset
the charset to use for decoding charset)Overrides default org. Return the contents of this resource as a string, using the specified charset. |
| public String | getDescription()
Implements org. This implementation returns a description that includes the passed-in
|
| public InputStream | getInputStream()
Implements org. This implementation returns a ByteArrayInputStream for the underlying byte array. |
| public int | hashCode()
Overrides org. This implementation returns the hash code based on the underlying byte array. |
| byteArray | back to summary |
|---|---|
| private final byte[] byteArray | |
| description | back to summary |
|---|---|
| private final String description | |
| ByteArrayResource | back to summary |
|---|---|
| public ByteArrayResource(byte[] byteArray) Create a new
| |
| ByteArrayResource | back to summary |
|---|---|
| public ByteArrayResource(byte[] byteArray, String description) Create a new
| |
| contentLength | back to summary |
|---|---|
| public long contentLength() Overrides org. Implements org. This implementation returns the length of the underlying byte array.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides org. This implementation compares the underlying byte array.
| |
| exists | back to summary |
|---|---|
| public boolean exists() Overrides org. Implements org. This implementation always returns
| |
| getByteArray | back to summary |
|---|---|
| public final byte[] getByteArray() Return the underlying byte array. | |
| getContentAsByteArray | back to summary |
|---|---|
| public byte[] getContentAsByteArray() throws IOException Overrides default org. Doc from org. Return the contents of this resource as a byte array.
| |
| getContentAsString | back to summary |
|---|---|
| public String getContentAsString(Charset charset) throws IOException Overrides default org. Doc from org. Return the contents of this resource as a string, using the specified charset.
| |
| getDescription | back to summary |
|---|---|
| public String getDescription() Implements org. This implementation returns a description that includes the passed-in
| |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Implements org. This implementation returns a ByteArrayInputStream for the underlying byte array.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. This implementation returns the hash code based on the underlying byte array.
| |