类 ByteArrayResource

  • 所有已实现的接口:
    InputStreamSource, Resource

    public class ByteArrayResource
    extends AbstractResource
    Copy from https://github.com/spring-projects/spring-framework.git, with less modifications 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.

    从以下版本开始:
    1.2.3
    作者:
    Juergen Hoeller, Sam Brannen
    另请参阅:
    ByteArrayInputStream, InputStreamResource
    • 字段详细资料

      • byteArray

        private final byte[] byteArray
      • description

        private final java.lang.String description
    • 构造器详细资料

      • ByteArrayResource

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

        public ByteArrayResource​(byte[] byteArray,
                                 java.lang.String description)
        Create a new ByteArrayResource with a description.
        参数:
        byteArray - the byte array to wrap
        description - where the byte array comes from
    • 方法详细资料

      • getByteArray

        public final byte[] getByteArray()
        Return the underlying byte array.
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        This implementation returns a ByteArrayInputStream for the underlying byte array.
        返回:
        the input stream for the underlying resource (must not be null)
        抛出:
        java.io.FileNotFoundException - if the underlying resource does not exist
        java.io.IOException - if the content stream could not be opened
        另请参阅:
        ByteArrayInputStream
      • getDescription

        public java.lang.String getDescription()
        This implementation returns a description that includes the passed-in description, if any.
        另请参阅:
        Object.toString()
      • equals

        public boolean equals​(java.lang.Object other)
        This implementation compares the underlying byte array.
        覆盖:
        equals 在类中 AbstractResource
        另请参阅:
        Arrays.equals(byte[], byte[])