Example usage for weka.core Utils Utils

List of usage examples for weka.core Utils Utils

Introduction

In this page you can find the example usage for weka.core Utils Utils.

Prototype

Utils

Source Link

Usage

From source file:net.sf.jclal.gui.view.xml.GUIXmlConfig.java

License:Open Source License

/**
 * Returns an entry stream from a file of configuration that is in the.jar.
 *
 * @param objective The objective//  w w  w  . j a  v  a2 s.com
 * @return A list of entry stream
 * @throws IOException The exception that will be launched.
 */
public static List<InputStream> readyLoadConfiguration(String objective) throws IOException {
    Utils utils = new Utils();
    Enumeration<URL> urls = utils.getClass().getClassLoader().getResources(objective);

    LinkedList<InputStream> dev = new LinkedList<InputStream>();

    while (urls.hasMoreElements()) {
        dev.add(urls.nextElement().openStream());
    }

    return dev;
}

From source file:net.sf.jclal.util.file.FileUtil.java

License:Open Source License

/**
 * Method that allows to load a file to be read that is located inside the
 * source code of a program, ej: config/util.props, if the file cannot be
 * taken to URI format, a copy of his content is created in the temporary
 * folder of the system and the above mentioned file it is returned
 *
 * @param fileSourcePath The path to the source
 * @return The file//w w w  .j a v a  2s.c  o m
 * @throws URISyntaxException The exceptions to launch
 * @throws IOException The exceptions to launch
 */
public static File loadFileSourceCode(String fileSourcePath) throws URISyntaxException, IOException {
    Utils util = new Utils();
    URL url = util.getClass().getClassLoader().getResource(fileSourcePath);
    File x;
    try {
        x = new File(url.toURI());
    } catch (Exception e) {

        InputStream input = url.openStream();

        File temp = new File(fileSourcePath);
        x = File.createTempFile(temp.getName(), ".temp");

        Files.copy(input, x.toPath(), StandardCopyOption.REPLACE_EXISTING);

        input.close();
        input = null;
    }

    //clean
    util = null;
    url = null;

    return x;
}

From source file:tr.gov.ulakbim.jDenetX.core.PropertiesReader.java

License:Open Source License

/**
 * Reads properties that inherit from three locations. Properties
 * are first defined in the system resource location (i.e. in the
 * CLASSPATH).  These default properties must exist. Properties
 * defined in the users home directory (optional) override default
 * settings. Properties defined in the current directory (optional)
 * override all these settings./*from   ww  w  .  j a v a 2 s  . co  m*/
 *
 * @param resourceName the location of the resource that should be
 *                     loaded.  e.g.: "weka/core/Utils.props". (The use of hardcoded
 *                     forward slashes here is OK - see
 *                     jdk1.1/docs/guide/misc/resources.html) This routine will also
 *                     look for the file (in this case) "Utils.props" in the users home
 *                     directory and the current directory.
 * @return the Properties
 * @throws Exception if no default properties are defined, or if
 *                   an error occurs reading the properties files.
 */
public static Properties readProperties(String resourceName) throws Exception {

    Properties defaultProps = new Properties();
    try {
        // Apparently hardcoded slashes are OK here
        // jdk1.1/docs/guide/misc/resources.html
        //      defaultProps.load(ClassLoader.getSystemResourceAsStream(resourceName));
        defaultProps.load((new Utils()).getClass().getClassLoader().getResourceAsStream(resourceName));
    } catch (Exception ex) {
        /*      throw new Exception("Problem reading default properties: "
           + ex.getMessage()); */
        System.err.println("Warning, unable to load properties file from " + "system resource (Utils.java)");
    }

    // Hardcoded slash is OK here
    // eg: see jdk1.1/docs/guide/misc/resources.html
    int slInd = resourceName.lastIndexOf('/');
    if (slInd != -1) {
        resourceName = resourceName.substring(slInd + 1);
    }

    // Allow a properties file in the home directory to override
    Properties userProps = new Properties(defaultProps);
    File propFile = new File(
            System.getProperties().getProperty("user.home") + File.separatorChar + resourceName);
    if (propFile.exists()) {
        try {
            userProps.load(new FileInputStream(propFile));
        } catch (Exception ex) {
            throw new Exception("Problem reading user properties: " + propFile);
        }
    }

    // Allow a properties file in the current directory to override
    Properties localProps = new Properties(userProps);
    propFile = new File(resourceName);
    if (propFile.exists()) {
        try {
            localProps.load(new FileInputStream(propFile));
        } catch (Exception ex) {
            throw new Exception("Problem reading local properties: " + propFile);
        }
    }

    return localProps;
}