public class ByteArrayResource extends 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.
ByteArrayInputStream, 
InputStreamResource, 
org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)| Constructor and Description | 
|---|
| ByteArrayResource(byte[] byteArray)Create a new  ByteArrayResource. | 
| ByteArrayResource(byte[] byteArray,
                 String description)Create a new  ByteArrayResourcewith a description. | 
| Modifier and Type | Method and Description | 
|---|---|
| long | contentLength()This implementation returns the length of the underlying byte array. | 
| boolean | equals(Object other)This implementation compares the underlying byte array. | 
| boolean | exists()This implementation always returns  true. | 
| byte[] | getByteArray()Return the underlying byte array. | 
| String | getDescription()This implementation returns a description that includes the passed-in
  description, if any. | 
| InputStream | getInputStream()This implementation returns a ByteArrayInputStream for the
 underlying byte array. | 
| int | hashCode()This implementation returns the hash code based on the
 underlying byte array. | 
createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel, toStringpublic ByteArrayResource(byte[] byteArray)
ByteArrayResource.byteArray - the byte array to wrappublic final byte[] getByteArray()
public boolean exists()
true.exists in interface Resourceexists in class AbstractResourcepublic long contentLength()
contentLength in interface ResourcecontentLength in class AbstractResourceInputStreamSource.getInputStream()public InputStream getInputStream() throws IOException
null)FileNotFoundException - if the underlying resource doesn't existIOException - if the content stream could not be openedByteArrayInputStreampublic String getDescription()
description, if any.Object.toString()public boolean equals(@Nullable Object other)
equals in class AbstractResourceArrays.equals(byte[], byte[])public int hashCode()
hashCode in class AbstractResourceResource.getDescription()