spring-framework / org.springframework.core.io / ByteArrayResource

ByteArrayResource

open class ByteArrayResource : AbstractResource

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.

Author
Juergen Hoeller

Author
Sam Brannen

Since
1.2.3

See Also
java.io.ByteArrayInputStreamInputStreamResourceorg.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)

Constructors

<init>

ByteArrayResource(byteArray: ByteArray)

Create a new ByteArrayResource.

ByteArrayResource(byteArray: ByteArray, description: String)

Create a new ByteArrayResource with a description.

Functions

contentLength

open fun contentLength(): Long

This implementation returns the length of the underlying byte array.

equals

open fun equals(other: Any?): Boolean

This implementation compares the underlying byte array.

exists

open fun exists(): Boolean

This implementation always returns true.

getByteArray

fun getByteArray(): ByteArray

Return the underlying byte array.

getDescription

open fun getDescription(): String

This implementation returns a description that includes the passed-in description, if any.

getInputStream

open fun getInputStream(): InputStream

This implementation returns a ByteArrayInputStream for the underlying byte array.

hashCode

open fun hashCode(): Int

This implementation returns the hash code based on the underlying byte array.

Inheritors

TransformedResource

open class TransformedResource : ByteArrayResource

An extension of ByteArrayResource that a ResourceTransformer can use to represent an original resource preserving all other information except the content.

TransformedResource

open class TransformedResource : ByteArrayResource

An extension of ByteArrayResource that a ResourceTransformer can use to represent an original resource preserving all other information except the content.