Class EncodedResource
- java.lang.Object
- org.springframework.core.io.support.EncodedResource
- All Implemented Interfaces:
InputStreamSource
public class EncodedResource extends Object implements InputStreamSource
Holder that combines aResource
descriptor with a specific encoding orCharset
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
- See Also:
InputStreamSource.getInputStream()
,Reader
,Charset
Constructor Summary
Constructors Constructor Description EncodedResource(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object other)
Charset
getCharset()
String
getEncoding()
Return the encoding to use for reading from the resource, ornull
if none specified.InputStream
getInputStream()
Reader
getReader()
Resource
getResource()
Return theResource
held by thisEncodedResource
.int
hashCode()
boolean
requiresReader()
Determine whether aReader
is required as opposed to anInputStream
, i.e.String
toString()
Constructor Detail
EncodedResource
public EncodedResource(Resource resource)
Create a newEncodedResource
for the givenResource
, not specifying an explicit encoding orCharset
.- Parameters:
resource
- theResource
to hold (nevernull
)
EncodedResource
public EncodedResource(Resource resource, @Nullable String encoding)
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
public EncodedResource(Resource resource, @Nullable Charset charset)
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 Detail
getResource
public final Resource getResource()
Return theResource
held by thisEncodedResource
.
getEncoding
@Nullable public final String getEncoding()
Return the encoding to use for reading from the resource, ornull
if none specified.
getCharset
@Nullable public final Charset 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()
,getInputStream()
getReader
public Reader getReader() throws IOException
- Throws:
IOException
- if opening the Reader failed- See Also:
requiresReader()
,getInputStream()
getInputStream
public InputStream getInputStream() throws IOException
- 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:
requiresReader()
,getReader()