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
,
MimeMessageHelper.addAttachment(String, InputStreamSource)
Modifier and Type | Field and Description |
---|---|
private byte[] |
byteArray |
private java.lang.String |
description |
Constructor and Description |
---|
ByteArrayResource(byte[] byteArray)
Create a new ByteArrayResource.
|
ByteArrayResource(byte[] byteArray,
java.lang.String description)
Create a new ByteArrayResource.
|
Modifier and Type | Method and Description |
---|---|
long |
contentLength()
This implementation returns the length of the underlying byte array.
|
boolean |
equals(java.lang.Object obj)
This implementation compares the underlying byte array.
|
boolean |
exists()
This implementation always returns
true . |
byte[] |
getByteArray()
Return the underlying byte array.
|
java.lang.String |
getDescription()
This implementation returns a description that includes the passed-in
description , if any. |
java.io.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, isOpen, isReadable, lastModified, toString
private final byte[] byteArray
private final java.lang.String description
public ByteArrayResource(byte[] byteArray)
byteArray
- the byte array to wrappublic ByteArrayResource(byte[] byteArray, java.lang.String description)
byteArray
- the byte array to wrapdescription
- where the byte array comes frompublic final byte[] getByteArray()
public boolean exists()
true
.exists
in interface Resource
exists
in class AbstractResource
public long contentLength()
contentLength
in interface Resource
contentLength
in class AbstractResource
InputStreamSource.getInputStream()
public java.io.InputStream getInputStream() throws java.io.IOException
null
)java.io.IOException
- if the stream could not be openedByteArrayInputStream
public java.lang.String getDescription()
description
, if any.Object.toString()
public boolean equals(java.lang.Object obj)
equals
in class AbstractResource
Arrays.equals(byte[], byte[])
public int hashCode()
hashCode
in class AbstractResource
Resource.getDescription()