All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.coherentlogic.coherent.data.adapter.application.ExampleFactory Maven / Gradle / Ivy

The newest version!
package com.coherentlogic.coherent.data.adapter.application;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import com.coherentlogic.coherent.data.adapter.core.factories.TypedFactory;

/**
 * A class that is used to load examples from a file which is embedded in a jar.
 *
 * @author Support
 */
public class ExampleFactory implements TypedFactory {

    private final String value;

    public ExampleFactory (ClassPathResource resource) throws IOException {
        this (resource.getInputStream());
    }

    public ExampleFactory (InputStream inputStream) throws IOException {
        this(newStringWriter(inputStream));
    }

    public ExampleFactory (StringWriter writer) {
        this (writer.toString());
    }

    public ExampleFactory (String value) {
        this.value = value;
    }

    @Override
    public String getInstance () {
        return value;
    }

    static StringWriter newStringWriter (InputStream inputStream)
        throws IOException {

        StringWriter result = new StringWriter ();

        IOUtils.copy(inputStream, result, Charset.defaultCharset());

        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy