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

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

Introduction

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

Prototype

public boolean requiresReader() 

Source Link

Document

Determine whether a Reader is required as opposed to an InputStream , i.e.

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
 *///from  w  w  w  . j  a  v a 2 s.  co  m
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();
        }
    }
}