public class

ByteArrayResource

extends AbstractResource
java.lang.Object
   ↳ org.springframework.core.io.AbstractResource
     ↳ org.springframework.core.io.ByteArrayResource

Class Overview

Resource implementation for a given byte array. Creates a ByteArrayInputStreams 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.

Summary

Public Constructors
ByteArrayResource(byte[] byteArray)
Create a new ByteArrayResource.
ByteArrayResource(byte[] byteArray, String description)
Create a new ByteArrayResource.
Public Methods
boolean equals(Object obj)
This implementation compares the underlying byte array.
boolean exists()
This implementation always returns true.
final byte[] getByteArray()
Return the underlying byte array.
String getDescription()
This implementation returns 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.
[Expand]
Inherited Methods
From class org.springframework.core.io.AbstractResource
From class java.lang.Object
From interface org.springframework.core.io.InputStreamSource
From interface org.springframework.core.io.Resource

Public Constructors

public ByteArrayResource (byte[] byteArray)

Also: SpringCore

Create a new ByteArrayResource.

Parameters
byteArray the byte array to wrap

public ByteArrayResource (byte[] byteArray, String description)

Also: SpringCore

Create a new ByteArrayResource.

Parameters
byteArray the byte array to wrap
description where the byte array comes from

Public Methods

public boolean equals (Object obj)

This implementation compares the underlying byte array.

public boolean exists ()

Also: SpringCore

This implementation always returns true.

public final byte[] getByteArray ()

Also: SpringCore

Return the underlying byte array.

public String getDescription ()

Also: SpringCore

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

public InputStream getInputStream ()

Also: SpringCore

This implementation returns a ByteArrayInputStream for the underlying byte array.

Throws
IOException
See Also
  • java.io.ByteArrayInputStream

public int hashCode ()

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