org.springframework.core.io

## 类 ByteArrayResource

- java.lang.Object
- - org.springframework.core.io.AbstractResource
  - - org.springframework.core.io.ByteArrayResource

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

      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.

  从以下版本开始:
    1.2.3
  作者:
    Juergen Hoeller, Sam Brannen
  另请参阅:
    `ByteArrayInputStream`, `InputStreamResource`, `org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)`

- - ### 构造器概要

    构造器
    构造器和说明
    `ByteArrayResource(byte[] byteArray)` Create a new `ByteArrayResource`.
    `ByteArrayResource(byte[] byteArray, String description)` Create a new `ByteArrayResource` with a 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.

    - ### 从类继承的方法 org.springframework.core.io.AbstractResource

      `createRelative, getFile, getFileForLastModifiedCheck, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel, toString`

    - ### 从类继承的方法 java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### 构造器详细资料

    - #### ByteArrayResource

          public ByteArrayResource(byte[] byteArray)

      Create a new `ByteArrayResource`.
      参数:
        `byteArray` - the byte array to wrap

    - #### ByteArrayResource

          public ByteArrayResource(byte[] byteArray,
                                   @Nullable
                                   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.

    - #### exists

          public boolean exists()

      This implementation always returns `true`.
      指定者:
        `exists` 在接口中 `Resource`
      覆盖:
        `exists` 在类中 `AbstractResource`

    - #### contentLength

          public long contentLength()

      This implementation returns the length of the underlying byte array.
      指定者:
        `contentLength` 在接口中 `Resource`
      覆盖:
        `contentLength` 在类中 `AbstractResource`
      另请参阅:
        `InputStreamSource.getInputStream()`

    - #### getInputStream

          public InputStream getInputStream()
                                     throws IOException

      This implementation returns a ByteArrayInputStream for the underlying byte array.
      返回:
        the input stream for the underlying resource (must not be `null`)
      抛出:
        `FileNotFoundException` - if the underlying resource doesn't exist
        `IOException` - if the content stream could not be opened
      另请参阅:
        `ByteArrayInputStream`

    - #### getDescription

          public String getDescription()

      This implementation returns a description that includes the passed-in `description`, if any.
      另请参阅:
        `Object.toString()`

    - #### equals

          public boolean equals(Object other)

      This implementation compares the underlying byte array.
      覆盖:
        `equals` 在类中 `AbstractResource`
      另请参阅:
        `Arrays.equals(byte[], byte[])`

    - #### hashCode

          public int hashCode()

      This implementation returns the hash code based on the underlying byte array.
      覆盖:
        `hashCode` 在类中 `AbstractResource`
      另请参阅:
        `Resource.getDescription()`