Top Description Fields Constructors Methods
org.springframework.core.io.support

public Class EncodedResource

extends Object
implements InputStreamSource
Class Inheritance
All Implemented Interfaces
org.springframework.core.io.InputStreamSource
Imports
java.io.IOException, .InputStream, .InputStreamReader, .Reader, java.nio.charset.Charset, org.springframework.core.io.InputStreamSource, .Resource, org.springframework.lang.Nullable, org.springframework.util.Assert, .ObjectUtils

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

Used as an argument for operations that support reading content with a specific encoding, typically via a java.io.Reader.

Authors
Juergen Hoeller, Sam Brannen, Arjen Poutsma
Since
1.2.6
See Also
Resource#getInputStream(), java.io.Reader, java.nio.charset.Charset

Field Summary

Modifier and TypeField and Description
private final Charset
private final String
private final Resource

Constructor Summary

AccessConstructor and Description
public
EncodedResource(Resource
the Resource to hold (never null)
resource
)

Create a new EncodedResource for the given Resource, not specifying an explicit encoding or Charset.

public
EncodedResource(Resource
the Resource to hold (never null)
resource
,
String
the encoding to use for reading from the resource
encoding
)

Create a new EncodedResource for the given Resource, using the specified encoding.

public
EncodedResource(Resource
the Resource to hold (never null)
resource
,
Charset
the Charset to use for reading from the resource
charset
)

Create a new EncodedResource for the given Resource, using the specified Charset.

private
EncodedResource(Resource resource, String encoding, Charset charset)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final Charset
getCharset()

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

public String
getContentAsString()

Returns the contents of the specified resource as a string, using the specified Charset or encoding (if any).

public final String
getEncoding()

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

public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Open an InputStream for the specified resource, ignoring any specified Charset or encoding.

public Reader
getReader()

Open a java.io.Reader for the specified resource, using the specified Charset or encoding (if any).

public final Resource
getResource()

Return the Resource held by this EncodedResource.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

charsetback to summary
private final Charset charset
Annotations
@Nullable
encodingback to summary
private final String encoding
Annotations
@Nullable
resourceback to summary
private final Resource resource

Constructor Detail

EncodedResourceback to summary
public EncodedResource(Resource resource)

Create a new EncodedResource for the given Resource, not specifying an explicit encoding or Charset.

Parameters
resource:Resource

the Resource to hold (never null)

EncodedResourceback to summary
public EncodedResource(Resource resource, String encoding)

Create a new EncodedResource for the given Resource, using the specified encoding.

Parameters
resource:Resource

the Resource to hold (never null)

encoding:String

the encoding to use for reading from the resource

EncodedResourceback to summary
public EncodedResource(Resource resource, Charset charset)

Create a new EncodedResource for the given Resource, using the specified Charset.

Parameters
resource:Resource

the Resource to hold (never null)

charset:Charset

the Charset to use for reading from the resource

EncodedResourceback to summary
private EncodedResource(Resource resource, String encoding, Charset charset)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCharsetback to summary
public final Charset getCharset()

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

Annotations
@Nullable
getContentAsStringback to summary
public String getContentAsString() throws IOException

Returns the contents of the specified resource as a string, using the specified Charset or encoding (if any).

Exceptions
IOException:
if opening the resource failed
Since
6.0.5
See Also
Resource#getContentAsString(Charset)
getEncodingback to summary
public final String getEncoding()

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

Annotations
@Nullable
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

Open an InputStream for the specified resource, ignoring any specified Charset or encoding.

Returns:InputStream

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:
if opening the InputStream failed
See Also
requiresReader(), getReader()
getReaderback to summary
public Reader getReader() throws IOException

Open a java.io.Reader for the specified resource, using the specified Charset or encoding (if any).

Exceptions
IOException:
if opening the Reader failed
See Also
requiresReader(), getInputStream()
getResourceback to summary
public final Resource getResource()

Return the Resource held by this EncodedResource.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
requiresReaderback to summary
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()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override