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
ConstructorsConstructorDescriptionEncodedResource(Resource resource) Create a newEncodedResourcefor the givenResource, not specifying an explicit encoding orCharset.EncodedResource(Resource resource, @Nullable String encoding) Create a newEncodedResourcefor the givenResource, using the specifiedencoding.EncodedResource(Resource resource, @Nullable Charset charset) Create a newEncodedResourcefor the givenResource, using the specifiedCharset. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn the encoding to use for reading from the resource, ornullif none specified.final ResourceReturn theResourceheld by thisEncodedResource.inthashCode()booleanDetermine whether aReaderis required as opposed to anInputStream, i.e.toString()
-
Constructor Details
-
EncodedResource
Create a newEncodedResourcefor the givenResource, not specifying an explicit encoding orCharset.- Parameters:
resource- theResourceto hold (nevernull)
-
EncodedResource
-
EncodedResource
-
-
Method Details
-
getResource
Return theResourceheld by thisEncodedResource. -
getEncoding
-
getCharset
-
requiresReader
public boolean requiresReader()Determine whether aReaderis required as opposed to anInputStream, i.e. whether an encoding or aCharsethas been specified.- See Also:
-
getReader
- Throws:
IOException- if opening the Reader failed- See Also:
-
getInputStream
- Specified by:
getInputStreamin 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 specifiedCharsetor encoding (if any).- Throws:
IOException- if opening the resource failed- Since:
- 6.0.5
- See Also:
-
equals
-
hashCode
-
toString
-