Example usage for org.springframework.util PropertiesPersister load

List of usage examples for org.springframework.util PropertiesPersister load

Introduction

In this page you can find the example usage for org.springframework.util PropertiesPersister load.

Prototype

void load(Properties props, Reader reader) throws IOException;

Source Link

Document

Load properties from the given Reader into the given Properties object.

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
 *//*  w ww  . ja v a 2  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();
        }
    }
}