Example usage for java.io File toURI

List of usage examples for java.io File toURI

Introduction

In this page you can find the example usage for java.io File toURI.

Prototype

public URI toURI() 

Source Link

Document

Constructs a file: URI that represents this abstract pathname.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.io.reuters.Reuters21578TxtReader.java

private void initCas(CAS aCas, File aFile) throws IOException, CASException {
    Map<String, String> doc = readFile(aFile);
    DocumentMetaData docMetaData = DocumentMetaData.create(aCas);
    docMetaData.setDocumentTitle(doc.get("title"));
    docMetaData.setDocumentUri(aFile.toURI().toString());
    docMetaData/*from  www  .ja v a 2s  . c om*/
            .setDocumentId(aFile.getParentFile().getName() + "_" + FilenameUtils.getBaseName(aFile.getName()));
    docMetaData.setDocumentBaseUri(aFile.getParent());
    docMetaData.setCollectionId(getSourceLocation());

    aCas.setDocumentLanguage(getLanguage());
    aCas.setDocumentText(doc.get("text"));
}

From source file:de.xaniox.heavyspleef.addon.java.AddOnClassLoader.java

public AddOnClassLoader(File file, ClassLoader parent, AddOnProperties properties, AddOnManager manager,
        SharedClassContext ctx, File dataFolder) throws InvalidAddOnException, MalformedURLException {
    super(new URL[] { file.toURI().toURL() }, parent);

    this.file = file;
    this.dataFolder = dataFolder;
    this.properties = properties;
    this.classContext = ctx;
    this.manager = manager;

    String mainClassName = properties.getMainClass();
    Class<?> mainClass;//from   w  w w.  j ava2  s  .c om

    try {
        mainClass = Class.forName(mainClassName, true, this);
    } catch (ClassNotFoundException e) {
        throw new InvalidAddOnException("Cannot find main class \"" + mainClassName + "\"", e);
    }

    Class<? extends BasicAddOn> addOnClass;

    try {
        addOnClass = mainClass.asSubclass(BasicAddOn.class);
    } catch (ClassCastException e) {
        throw new InvalidAddOnException("Main class \"" + mainClassName + "\" does not extend AddOn", e);
    }

    try {
        addOn = addOnClass.newInstance();
    } catch (IllegalAccessException e) {
        throw new InvalidAddOnException(
                "Main class \"" + mainClassName + "\" does not declare an public empty constructor", e);
    } catch (InstantiationException e) {
        throw new InvalidAddOnException("Main class \"" + mainClassName + "\" could not be instantiated", e);
    }
}

From source file:com.lohika.alp.reporter.ResultsXML2HTML.java

protected void transformResults(String outputDirectory) throws IOException, TransformerException {
    // HTML data output directory
    File logsData = new File(outputDirectory, logsDataDir);
    // XSL file (extracted to logs-data)
    File xsl = new File(logsData, resultsHtmlXslName);
    // XML file (created xml log file)
    File xml = new File(outputDirectory, resultsName);
    // XML file (created html log file)
    File html = new File(outputDirectory, resultsHtmlName);

    HTMLLogTransformer transformer = new HTMLLogTransformer(xsl, null);
    transformer.transform(xml, html);//from  w  w w .ja  va  2  s  .  com

    logger.info("Suite results: " + html.toURI().toURL());
}

From source file:eu.interedition.collatex.cli.Engine.java

URL argumentToResource(String arg) throws ParseException {
    try {/*from w ww.  j  a v a2  s.c om*/
        final File witnessFile = new File(arg);
        if (witnessFile.exists()) {
            return witnessFile.toURI().normalize().toURL();
        } else {
            return new URL(arg);
        }
    } catch (MalformedURLException urlEx) {
        throw new ParseException("Invalid resource: " + arg);
    }
}

From source file:com.splunk.shuttl.archiver.model.Bucket.java

/**
 * Bucket with an index and format<br/>
 * //from  w w  w .  j a va  2 s . com
 * @param indexName
 *          The name of the index that this bucket belongs to.
 * @param directory
 *          that is the bucket
 * @throws FileNotFoundException
 *           if the file doesn't exist
 * @throws FileNotDirectoryException
 *           if the file is not a directory
 */
public Bucket(String indexName, File directory, BucketFormat format)
        throws FileNotFoundException, FileNotDirectoryException {
    this(directory.toURI(), directory, indexName, directory.getName(), format, null);
}

From source file:czlab.wabbit.CljPodLoader.java

/**
 *//*ww w.  j a v a2s  .co m*/
private CljPodLoader addUrl(File f) {
    if (f.exists())
        try {
            addURL(f.toURI().toURL());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    return this;
}

From source file:com.eviware.soapui.plugins.JarClassLoader.java

private void addLibrariesIn(JarFile jarFile) throws IOException {
    if (containsLibraries(jarFile)) {
        File libDirectory = Tools.createTemporaryDirectory();
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            if (isLibrary(jarEntry)) {
                String fileName = jarEntry.getName().substring(LIB_PREFIX.length());
                File outputFile = new File(libDirectory, fileName);
                FileUtils.copyInputStreamToFile(jarFile.getInputStream(jarEntry), outputFile);
                this.addURL(outputFile.toURI().toURL());
            }//from   w w w.  j a va2s . co m
        }
    }
}

From source file:eu.ggnet.dwoss.util.ImageFinder.java

public ImageFinder(String filePath) {
    this.path = filePath == null ? null : new File(filePath);

    //Setup the error URL
    try {//  w w w  .  ja  v a 2 s . c o m
        File errorFile = File.createTempFile("error", ".png");
        errorFile.deleteOnExit();
        FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("error.png"), errorFile);
        errorUrl = errorFile.toURI().toURL();
    } catch (IOException ex) {
        throw new RuntimeException("Error in activating Fallback mode.", ex);
    }

    // The No Image.
    try {
        File noimageFile = File.createTempFile("noimage", ".png");
        noimageFile.deleteOnExit();
        FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("noimage.png"), noimageFile);
        noimageUrl = noimageFile.toURI().toURL();
    } catch (IOException ex) {
        throw new RuntimeException("Error in creating the noimgae", ex);
    }

}

From source file:org.apache.servicemix.platform.testing.support.AbstractIntegrationTest.java

protected Bundle installBundle(String groupId, String artifactId, String classifier, String type)
        throws Exception {
    String version = getBundleVersion(groupId, artifactId);
    File loc = localMavenBundle(groupId, artifactId, version, classifier, type);
    Bundle bundle = bundleContext.installBundle(loc.toURI().toString());
    bundle.start();/*from   w ww  .j  av a  2s  . co  m*/
    return bundle;
}

From source file:org.motechproject.server.osgi.OsgiFrameworkService.java

/**
 * Find external/optional bundles//from  w  w  w.j  av a 2s. c  o  m
 * 
 * @return
 * @throws Exception
 */
private List<URL> findExternalBundles() throws Exception {
    List<URL> list = new ArrayList<URL>();
    if (StringUtils.isNotBlank(externalBundleFolder)) {
        File folder = new File(externalBundleFolder);

        if (!folder.exists()) {
            folder.mkdirs();
        }

        File[] files = folder.listFiles();
        for (File file : files) {
            if (file.getAbsolutePath().endsWith(".jar")) {
                URL url = file.toURI().toURL();
                if (url != null) {
                    list.add(url);
                }
            }
        }
    }
    return list;
}