Example usage for java.net URL toURI

List of usage examples for java.net URL toURI

Introduction

In this page you can find the example usage for java.net URL toURI.

Prototype

public URI toURI() throws URISyntaxException 

Source Link

Document

Returns a java.net.URI equivalent to this URL.

Usage

From source file:io.cloudslang.lang.compiler.modeller.transformers.PublishTransformerTest.java

@Before
public void init() throws URISyntaxException {
    URL resource = getClass().getResource("/flow_with_multiple_steps.yaml");
    ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI())));
    List<Map<String, Map>> flow = (List<Map<String, Map>>) file.getFlow().get(SlangTextualKeys.WORKFLOW_KEY);
    for (Map<String, Map> task : flow) {
        if (task.keySet().iterator().next().equals("RealRealCheckWeather")) {
            publishMap = (List) task.values().iterator().next().get(SlangTextualKeys.PUBLISH_KEY);
            break;
        }//from w w  w.  j  a v a 2 s.c o m
    }
}

From source file:ca.phon.query.script.QueryScript.java

/**
 * Setup library folders for 'require'//from  w  ww .j  a v  a2s .  c om
 */
private void setupLibraryFolders() {
    final ClassLoader cl = PluginManager.getInstance();
    Enumeration<URL> libUrls;
    try {
        libUrls = cl.getResources("ca/phon/query/script/");
        while (libUrls.hasMoreElements()) {
            final URL url = libUrls.nextElement();
            try {
                final URI uri = url.toURI();
                super.addRequirePath(uri);
            } catch (URISyntaxException e) {
                LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
            }
        }
    } catch (IOException e1) {
        LOGGER.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
    }

    super.addPackageImport("Packages.ca.phon.orthography");
    super.addPackageImport("Packages.ca.phon.ipa");
    super.addPackageImport("Packages.ca.phon.ipa.features");
    super.addPackageImport("Packages.ca.phon.phonex");
    super.addPackageImport("Packages.ca.phon.syllable");
    super.addPackageImport("Packages.ca.phon.util");
    super.addPackageImport("Packages.ca.phon.project");
    super.addPackageImport("Packages.ca.phon.session");

    super.addClassImport("Packages.org.apache.commons.lang3.StringUtils");
}

From source file:co.cask.cdap.internal.app.runtime.webapp.JarExploderTest.java

@Test
public void testExplodeA() throws Exception {
    URL jarUrl = getClass().getResource("/test_explode.jar");
    Assert.assertNotNull(jarUrl);/*from   w  ww  .  ja  v a 2s. com*/

    File dest = TEMP_FOLDER.newFolder();

    int numFiles = JarExploder.explode(new File(jarUrl.toURI()), dest, new Predicate<JarEntry>() {
        @Override
        public boolean apply(JarEntry input) {
            return input.getName().startsWith("test_explode/a");
        }
    });

    Assert.assertEquals(aFileContentMap.size(), numFiles);

    verifyA(dest);
}

From source file:org.openscore.lang.compiler.CompileOperationTest.java

@Test
public void testCompileOperationMissingImport() throws Exception {
    URL resource = getClass().getResource("/operation_with_missing_sys_props_imports.sl");
    compiler.compile(SlangSource.fromFile(resource.toURI()), null).getExecutionPlan();
}

From source file:org.opendaylight.sfc.sbrest.json.RspExporterTest.java

private String gatherRenderedServicePathJsonStringFromFile(String testFileName) {
    String jsonString = null;//from www .j ava 2  s .  co  m

    try {
        URL fileURL = getClass().getResource(testFileName);
        jsonString = TestUtil.readFile(fileURL.toURI(), StandardCharsets.UTF_8);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }

    for (RspTestValues rspTestValue : RspTestValues.values()) {
        jsonString = jsonString != null
                ? jsonString.replaceAll("\\b" + rspTestValue.name() + "\\b", rspTestValue.getValue())
                : null;
    }

    return jsonString;
}

From source file:com.anrisoftware.globalpom.textmatch.match.DefaultMatchText.java

/**
 * @see DefaultMatchTextFactory#create(URL, Pattern, Charset)
 *///from  w w  w  .  ja  v a 2s . com
@AssistedInject
DefaultMatchText(@Assisted URL resource, @Assisted Pattern pattern, @Assisted Charset charset)
        throws URISyntaxException {
    this(resource.toURI(), pattern, charset);
}

From source file:com.puppycrawl.tools.checkstyle.utils.CommonUtilsTest.java

@Test
@PrepareForTest({ CommonUtils.class, CommonUtilsTest.class })
@SuppressWarnings("unchecked")
public void testLoadSuppressionsURISyntaxException() throws Exception {
    URL configUrl = mock(URL.class);

    when(configUrl.toURI()).thenThrow(URISyntaxException.class);
    mockStatic(CommonUtils.class, Mockito.CALLS_REAL_METHODS);
    String fileName = "suppressions_none.xml";
    when(CommonUtils.class.getResource(fileName)).thenReturn(configUrl);

    try {// w  w  w. j av a  2 s .c o m
        CommonUtils.getUriByFilename(fileName);
        fail("Exception is expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getCause() instanceof URISyntaxException);
        assertEquals("Unable to find: " + fileName, ex.getMessage());
    }
}

From source file:com.runwaysdk.dataaccess.schemamanager.xml.XSDConstraintsManager.java

public XSDConstraintsManager(String xsdLocation) {
    this.logger = new ParseLogger();
    this.tagToConstraints = new HashMap<XSType, ContentPriorityIF>();

    try {//from w  w  w  . j  a  va2 s . c o  m
        XSOMParser parser = new XSOMParser();
        parser.setEntityResolver(new RunwayClasspathEntityResolver());
        parser.setErrorHandler(logger);

        if (xsdLocation.startsWith("classpath:")) {
            // For some reason this parser isn't handling the entity resolver
            // properly. That's fine, we'll do it ourselves.
            parser.parse(new RunwayClasspathEntityResolver().resolveEntity("", xsdLocation));
        } else {
            boolean isURL = false;
            URL url = null;
            try {
                url = new URL(xsdLocation);
                url.toURI(); // Performs extra validation on the URL
                isURL = true;
            } catch (Exception e) {
            }

            if (isURL && url != null) {
                parser.parse(url);
            } else {
                parser.parse(new File(xsdLocation));
            }
        }

        schemaSet = parser.getResult();

        if (schemaSet == null) {
            throw new XMLParseException(
                    "The parser returned a null result when parsing XSD [" + xsdLocation + "].");
        }
    } catch (SAXException e) {
        this.logger.fatal(e);
        throw new XMLParseException(e);
    } catch (IOException e) {
        this.logger.fatal(e);
        throw new XMLParseException(e);
    }
}

From source file:org.openscore.lang.compiler.modeller.transformers.OutputsTransformerTest.java

@Test(timeout = DEFAULT_TIMEOUT)
public void testInvalidOutputType() throws Exception {
    URL resource = getClass().getResource("/operation_with_invalid_outputs.sl");
    ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI())));
    Map op = file.getOperation();
    List<Object> outputsMap = (List<Object>) op.get(SlangTextualKeys.OUTPUTS_KEY);
    exception.expect(RuntimeException.class);
    exception.expectMessage("output1");
    exception.expectMessage("3");
    outputTransformer.transform(outputsMap);
}

From source file:de.tudarmstadt.ukp.dkpro.tc.examples.io.ReutersCorpusReader.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    goldLabelMap = new HashMap<String, List<String>>();

    try {//from w  w w . j a  va2  s  . c  o m
        URL resourceUrl = ResourceUtils.resolveLocation(goldLabelFile, this, context);

        for (String line : FileUtils.readLines(new File(resourceUrl.toURI()))) {
            String[] parts = line.split(" ");

            if (parts.length < 2) {
                throw new IOException("Wrong file format in line: " + line);
            }
            String fileId = parts[0].split("/")[1];

            List<String> labels = new ArrayList<String>();
            for (int i = 1; i < parts.length; i++) {
                labels.add(parts[i]);
            }

            goldLabelMap.put(fileId, labels);
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    } catch (URISyntaxException ex) {
        throw new ResourceInitializationException(ex);
    }
}