Example usage for org.springframework.core.io.support EncodedResource getInputStream

List of usage examples for org.springframework.core.io.support EncodedResource getInputStream

Introduction

In this page you can find the example usage for org.springframework.core.io.support EncodedResource getInputStream.

Prototype

@Override
public InputStream getInputStream() throws IOException 

Source Link

Document

Open an InputStream for the specified resource, ignoring any specified #getCharset() Charset or #getEncoding() encoding .

Usage

From source file:com.sfxie.extension.spring4.properties.PropertiesLoaderUtils.java

/**
 * Actually load properties from the given EncodedResource into the given Properties instance.
 * @param props the Properties instance to load into
 * @param resource the resource to load from
 * @param persister the PropertiesPersister to use
 * @throws IOException in case of I/O errors
 *//*  ww w . ja v  a2  s.c om*/
static void fillProperties(Properties props, EncodedResource resource, PropertiesPersister persister)
        throws IOException {

    InputStream stream = null;
    Reader reader = null;
    try {
        String filename = resource.getResource().getFilename();
        if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
            stream = resource.getInputStream();
            persister.loadFromXml(props, stream);
        } else if (resource.requiresReader()) {
            reader = resource.getReader();
            persister.load(props, reader);
        } else {
            stream = resource.getInputStream();
            persister.load(props, stream);
        }
    } finally {
        if (stream != null) {
            stream.close();
        }
        if (reader != null) {
            reader.close();
        }
    }
}