Class ByteArrayResource

java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.ByteArrayResource
All Implemented Interfaces:
InputStreamSource, Resource
Direct Known Subclasses:
TransformedResource, TransformedResource

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.

Since:
1.2.3
Author:
Juergen Hoeller, Sam Brannen
See Also:
  • Constructor Details

    • ByteArrayResource

      public ByteArrayResource(byte[] byteArray)
      Create a new ByteArrayResource.
      Parameters:
      byteArray - the byte array to wrap
    • ByteArrayResource

      public ByteArrayResource(byte[] byteArray, @Nullable String description)
      Create a new ByteArrayResource with a description.
      Parameters:
      byteArray - the byte array to wrap
      description - where the byte array comes from
  • Method Details