org.springframework.core.io.support

## Class EncodedResource

- java.lang.Object
- - org.springframework.core.io.support.EncodedResource

-     public class EncodedResource
      extends Object

  Holder that combines a `Resource` with a specific encoding to be used for reading from the resource.

  Used as argument for operations that support to read content with a specific encoding (usually through a `java.io.Reader`.

  Since:
    1.2.6
  Author:
    Juergen Hoeller
  See Also:
    `Reader`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EncodedResource(Resource resource)` Create a new EncodedResource for the given Resource, not specifying a specific encoding.
    `EncodedResource(Resource resource, Charset charset)` Create a new EncodedResource for the given Resource, using the specified encoding.
    `EncodedResource(Resource resource, String encoding)` Create a new EncodedResource for the given Resource, using the specified encoding.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object obj)`
    `Charset` | `getCharset()` Return the charset to use for reading from the resource, or `null` if none specified.
    `String` | `getEncoding()` Return the encoding to use for reading from the resource, or `null` if none specified.
    `InputStream` | `getInputStream()` Open an `java.io.InputStream` for the specified resource, typically assuming that there is no specific encoding to use.
    `Reader` | `getReader()` Open a `java.io.Reader` for the specified resource, using the specified encoding (if any).
    `Resource` | `getResource()` Return the Resource held.
    `int` | `hashCode()`
    `boolean` | `requiresReader()` Determine whether a `Reader` is required as opposed to an `InputStream`, i.e.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### EncodedResource

          public EncodedResource(Resource resource)

      Create a new EncodedResource for the given Resource, not specifying a specific encoding.
      Parameters:
        `resource` - the Resource to hold

    - #### EncodedResource

          public EncodedResource(Resource resource,
                         String encoding)

      Create a new EncodedResource for the given Resource, using the specified encoding.
      Parameters:
        `resource` - the Resource to hold
        `encoding` - the encoding to use for reading from the resource

    - #### EncodedResource

          public EncodedResource(Resource resource,
                         Charset charset)

      Create a new EncodedResource for the given Resource, using the specified encoding.
      Parameters:
        `resource` - the Resource to hold
        `charset` - the charset to use for reading from the resource

  - ### Method Detail

    - #### getResource

          public final Resource getResource()

      Return the Resource held.

    - #### getEncoding

          public final String getEncoding()

      Return the encoding to use for reading from the resource, or `null` if none specified.

    - #### getCharset

          public final Charset getCharset()

      Return the charset to use for reading from the resource, or `null` if none specified.

    - #### requiresReader

          public boolean requiresReader()

      Determine whether a `Reader` is required as opposed to an `InputStream`, i.e. whether an encoding or a charset has been specified.
      See Also:
        `getReader()`, `getInputStream()`

    - #### getReader

          public Reader getReader()
                           throws IOException

      Open a `java.io.Reader` for the specified resource, using the specified encoding (if any).
      Throws:
        `IOException` - if opening the Reader failed
      See Also:
        `requiresReader()`

    - #### getInputStream

          public InputStream getInputStream()
                                     throws IOException

      Open an `java.io.InputStream` for the specified resource, typically assuming that there is no specific encoding to use.
      Throws:
        `IOException` - if opening the InputStream failed
      See Also:
        `requiresReader()`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`