Class EncodedResource
java.lang.Object
org.springframework.core.io.support.EncodedResource
- All Implemented Interfaces:
InputStreamSource
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
.
- Since:
- 1.2.6
- Author:
- Juergen Hoeller, Sam Brannen, Arjen Poutsma
- See Also:
-
Constructor Summary
ConstructorDescriptionEncodedResource
(Resource resource) Create a newEncodedResource
for the givenResource
, not specifying an explicit encoding orCharset
.EncodedResource
(Resource resource, String encoding) Create a newEncodedResource
for the givenResource
, using the specifiedencoding
.EncodedResource
(Resource resource, Charset charset) Create a newEncodedResource
for the givenResource
, using the specifiedCharset
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
final Charset
final String
Return the encoding to use for reading from the resource, ornull
if none specified.final Resource
Return theResource
held by thisEncodedResource
.int
hashCode()
boolean
Determine whether aReader
is required as opposed to anInputStream
, i.e.toString()
-
Constructor Details
-
EncodedResource
Create a newEncodedResource
for the givenResource
, not specifying an explicit encoding orCharset
.- Parameters:
resource
- theResource
to hold (nevernull
)
-
EncodedResource
Create a newEncodedResource
for the givenResource
, using the specifiedencoding
.- Parameters:
resource
- theResource
to hold (nevernull
)encoding
- the encoding to use for reading from the resource
-
EncodedResource
Create a newEncodedResource
for the givenResource
, using the specifiedCharset
.- Parameters:
resource
- theResource
to hold (nevernull
)charset
- theCharset
to use for reading from the resource
-
-
Method Details
-
getResource
Return theResource
held by thisEncodedResource
. -
getEncoding
Return the encoding to use for reading from the resource, ornull
if none specified. -
getCharset
-
requiresReader
public boolean requiresReader()Determine whether aReader
is required as opposed to anInputStream
, i.e. whether an encoding or aCharset
has been specified.- See Also:
-
getReader
- Throws:
IOException
- if opening the Reader failed- See Also:
-
getInputStream
- Specified by:
getInputStream
in interfaceInputStreamSource
- Returns:
- the input stream for the underlying resource (must not be
null
) - Throws:
IOException
- if opening the InputStream failed- See Also:
-
getContentAsString
Returns the contents of the specified resource as a string, using the specifiedCharset
or encoding (if any).- Throws:
IOException
- if opening the resource failed- Since:
- 6.0.5
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-