Example usage for org.springframework.core.io ByteArrayResource getInputStream

List of usage examples for org.springframework.core.io ByteArrayResource getInputStream

Introduction

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

Prototype

@Override
public InputStream getInputStream() throws IOException 

Source Link

Document

This implementation returns a ByteArrayInputStream for the underlying byte array.

Usage

From source file:com.flipkart.phantom.runtime.impl.spring.utils.ConfigFileUtils.java

/**
 * Gets the task handler names from Config file
 * @param configFile job config file contents as a <code> ByteArrayResource </code>
 * @return List of task handler names, null if unable to find a TaskHandler name.
 *//*ww  w.  j  av  a  2 s . c o  m*/
public static List<String> getHandlerNames(ByteArrayResource configFile) {
    List<String> jobNameList = new LinkedList<String>();
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document dom = db.parse(configFile.getInputStream());
        Element docEle = dom.getDocumentElement();
        //get a nodelist of nodes with the name "ConfigFileUtils.BATCH_JOB_TAG" 
        NodeList nl = docEle.getElementsByTagName(ConfigFileUtils.BATCH_JOB_TAG);
        //Loop over all found nodes
        if (nl != null && nl.getLength() > 0) {
            for (int i = 0; i < nl.getLength(); i++) {
                //get the element
                Element el = (Element) nl.item(i);
                if (el.hasAttribute(ConfigFileUtils.ID_PROP)) {
                    jobNameList.add(el.getAttribute(ConfigFileUtils.ID_PROP));
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unable to get the job name from the given Spring Batch configuration file", e);
        throw new PlatformException(e);
    }
    return jobNameList;
}

From source file:org.trpr.platform.batch.common.utils.ConfigFileUtils.java

/**
 * Gets the job names from Config file/*from   w ww  .j  a va  2s  .  c  o m*/
 * @param configFile job config file contents as a <code> ByteArrayResource </code>
 * @return List of job names, null if unable to find a job name.
 */
public static List<String> getJobName(ByteArrayResource configFile) {
    List<String> jobNameList = new LinkedList<String>();
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document dom = db.parse(configFile.getInputStream());
        Element docEle = dom.getDocumentElement();
        //get a nodelist of nodes with the name "ConfigFileUtils.BATCH_JOB_TAG" 
        NodeList nl = docEle.getElementsByTagName(ConfigFileUtils.BATCH_JOB_TAG);
        //Loop over all found nodes
        if (nl != null && nl.getLength() > 0) {
            for (int i = 0; i < nl.getLength(); i++) {
                //get the element
                Element el = (Element) nl.item(i);
                if (el.hasAttribute(ConfigFileUtils.ID_PROP)) {
                    jobNameList.add(el.getAttribute(ConfigFileUtils.ID_PROP));
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unable to get the job name from the given Spring Batch configuration file", e);
        throw new PlatformException(e);
    }
    return jobNameList;
}