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:com.asakusafw.testdriver.DirectIoUtil.java

private static <T> DataModelSourceFactory load(Configuration configuration, DataModelDefinition<T> definition,
        DataFormat<? super T> format, URL source) throws IOException, InterruptedException {
    checkDataType(definition, format);//w ww  .j  a  va 2s.  co  m
    if (source.getProtocol().equals("file")) { //$NON-NLS-1$
        File file = null;
        try {
            file = new File(source.toURI());
        } catch (URISyntaxException e) {
            LOG.debug("failed to convert URL into local file path: {}", source, e); //$NON-NLS-1$
        }
        if (file != null) {
            return load(configuration, definition, format, file);
        }
    }
    if (format instanceof BinaryStreamFormat<?>) {
        return load0(definition, (BinaryStreamFormat<? super T>) format, source);
    }
    HadoopFileFormat<? super T> hFormat = HadoopDataSourceUtil.toHadoopFileFormat(configuration, format);
    return load0(definition, hFormat, source);
}

From source file:org.cloudifysource.azure.AbstractCliAzureDeploymentTest.java

/**
 * This methods extracts the number of machines running gs-agents using the rest admin api
 *
 * @param machinesRestAdminUrl/*from   www.  j  av  a2 s.co m*/
 * @return number of machines running gs-agents
 * @throws IOException
 * @throws java.net.URISyntaxException
 */
protected static int getNumberOfMachines(URL machinesRestAdminUrl) throws IOException, URISyntaxException {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(machinesRestAdminUrl.toURI());
    try {
        String json = client.execute(httpGet, new BasicResponseHandler());
        Matcher matcher = Pattern.compile("\"Size\":\"([0-9]+)\"").matcher(json);
        if (matcher.find()) {
            String rawSize = matcher.group(1);
            int size = Integer.parseInt(rawSize);
            return size;
        } else {
            return 0;
        }
    } catch (Exception e) {
        return 0;
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.streamsets.pipeline.stage.destination.solr.TestSolrTarget.java

@BeforeClass
public static void beforeTest() throws Exception {
    File solrHomeDir = new File("target", UUID.randomUUID().toString());
    Assert.assertTrue(solrHomeDir.mkdirs());
    URL url = Thread.currentThread().getContextClassLoader().getResource("solr/");
    Assert.assertNotNull(url);//from   w w w.  jav a 2  s.  c o  m
    FileUtils.copyDirectoryToDirectory(new File(url.toURI()), solrHomeDir);
    createJetty(solrHomeDir.getAbsolutePath() + "/solr", null, null);
}

From source file:com.espertech.esper.event.xml.XSDSchemaMapper.java

private static XSModel readSchemaInternal(String schemaResource, String schemaText)
        throws IllegalAccessException, InstantiationException, ClassNotFoundException, ConfigurationException,
        URISyntaxException {/*from  ww w. j  a  v a 2  s .co  m*/
    LSInputImpl input = null;
    String baseURI = null;
    if (schemaResource != null) {
        URL url = ResourceLoader.resolveClassPathOrURLResource("schema", schemaResource);
        baseURI = url.toURI().toString();
    } else {
        input = new LSInputImpl(schemaText);
    }

    // Uses Xerxes internal classes
    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    registry.addSource(new DOMXSImplementationSourceImpl());
    Object xsImplementation = registry.getDOMImplementation("XS-Loader");
    if (xsImplementation == null) {
        throw new ConfigurationException(
                "Failed to retrieve XS-Loader implementation from registry obtained via DOMImplementationRegistry.newInstance, please check that registry.getDOMImplementation(\"XS-Loader\") returns an instance");
    }
    if (!JavaClassHelper.isImplementsInterface(xsImplementation.getClass(), XSImplementation.class)) {
        String message = "The XS-Loader instance returned by the DOM registry class '"
                + xsImplementation.getClass().getName() + "' does not implement the interface '"
                + XSImplementation.class.getName()
                + "'; If you have a another Xerces distribution in your classpath please ensure the classpath order loads the JRE Xerces distribution or set the DOMImplementationRegistry.PROPERTY system property";
        throw new ConfigurationException(message);
    }
    XSImplementation impl = (XSImplementation) xsImplementation;
    XSLoader schemaLoader = impl.createXSLoader(null);
    XSModel xsModel;
    if (input != null) {
        xsModel = schemaLoader.load(input);
    } else {
        xsModel = schemaLoader.loadURI(baseURI);
    }

    if (xsModel == null) {
        throw new ConfigurationException("Failed to read schema via URL '" + schemaResource + '\'');
    }

    return xsModel;
}

From source file:com.qualogy.qafe.web.ContextLoader.java

private static void create(ServletContext servletContext) throws MalformedURLException, URISyntaxException {
    String configLocation = servletContext.getInitParameter(CONFIG_FILE_PARAM);
    String contextPath = getContextPath(servletContext);
    QafeConfigurationManager contextInitialiser = new QafeConfigurationManager(contextPath);
    ApplicationContext springContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(servletContext);
    contextInitialiser.setSpringContext(springContext);
    qafeContext.putInstance(QafeConfigurationManager.class.getName(), contextInitialiser);

    StopWatch watch = new StopWatch();
    watch.start();/* w  w w. j a v a  2s  . c  o m*/
    ApplicationContextLoader.unload();

    // The default way: works on JBoss/Tomcat/Jetty
    String configFileLocation = servletContext.getRealPath("/WEB-INF/");
    if (configFileLocation != null) {
        configFileLocation += File.separator + configLocation;
        logger.log(Level.INFO, "URL to config file on disk :" + configFileLocation + ")");
        ApplicationContextLoader.load(configFileLocation, true);
    } else {
        // This is how a weblogic explicitly wants the fetching of resources.
        URL url = servletContext.getResource("/WEB-INF/" + configLocation);
        logger.log(Level.INFO, "Fallback scenario" + url.toString());
        if (url != null) {
            logger.log(Level.INFO, "URL to config file " + url.toString());
            ApplicationContextLoader.load(url.toURI(), true);
        } else {
            throw new RuntimeException(
                    "Strange Error: /WEB-INF/ cannot be found. Check the appserver or installation directory.");
        }
    }

    watch.stop();
    logger.log(Level.INFO,
            "Root WebApplicationContext: initialization completed in " + watch.getTime() + " ms");
}

From source file:org.unitedinternet.cosmo.dav.caldav.report.MultigetReport.java

private static URL normalizeHref(URL context, String href) throws CosmoDavException {
    URL url = null;/*from  w  ww . j a  v  a  2  s . com*/
    try {
        url = new URL(context, href);
        // check that the URL is escaped. it's questionable whether or
        // not we should all unescaped URLs, but at least as of
        // 10/02/2007, iCal 3.0 generates them
        url.toURI();
        return url;
    } catch (URISyntaxException e) {
        try {
            URI escaped = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(),
                    url.getRef());
            return new URL(escaped.toString());
        } catch (URISyntaxException | MalformedURLException e2) {
            throw new BadRequestException("Malformed unescaped href " + href + ": " + e.getMessage());
        }
    } catch (MalformedURLException e) {
        throw new BadRequestException("Malformed href " + href + ": " + e.getMessage());
    }
}

From source file:com.codebutler.rsp.Util.java

public static String getURL(URL url, String password) throws Exception {
    Log.i("Util.getURL", url.toString());

    DefaultHttpClient client = new DefaultHttpClient();

    if (password != null && password.length() > 0) {
        UsernamePasswordCredentials creds;
        creds = new UsernamePasswordCredentials("user", password);
        client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
    }/* ww  w . j a  va  2s .co  m*/

    HttpGet method = new HttpGet(url.toURI());
    BasicResponseHandler responseHandler = new BasicResponseHandler();
    return client.execute(method, responseHandler);
}

From source file:com.tesora.dve.common.PEFileUtils.java

public static URI convert(final URL url) throws PEException {
    try {/*from   w  ww  . j  a  v a 2 s.c o m*/
        return url.toURI();
    } catch (final URISyntaxException e) {
        throw new PEException("Malformed resource URI '" + url.toString() + "'", e);
    }
}

From source file:com.mpower.daktar.android.utilities.WebUtils.java

public static HttpResponse stringResponseGet(final String urlString, final HttpContext localContext,
        final HttpClient httpclient) throws Exception {

    final URL url = new URL(URLDecoder.decode(urlString, "utf-8"));
    final URI u = url.toURI();

    final HttpGet req = new HttpGet();
    req.setURI(u);/*from   w w w. j  av a  2 s  . co m*/

    HttpResponse response = null;
    response = httpclient.execute(req, localContext);

    return response;
}

From source file:gemlite.core.internal.support.system.ServerConfigHelper.java

public static void initLog4j(String configFile) {
    configFile = "log4j2-server.xml";
    if (getProperty(ITEMS.NODE_TYPE.name()) == null)
        setProperty("NODE_TYPE", "");
    if (getProperty(ITEMS.NODE_NAME.name()) == null)
        setProperty("NODE_NAME", "");
    String resolvedLocation = SystemPropertyUtils.resolvePlaceholders("log4j2-server.xml");

    URL url;
    try {//from w  ww . j av  a2s  .co  m
        url = ServerConfigHelper.class.getClassLoader().getResource(configFile);
        LoggerContext context = (LoggerContext) LogManager.getContext(false);
        context.setConfigLocation(url.toURI());
        LogUtil.init();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    // System.setProperty("log4j.configurationFile", configFile);

    // try
    // {
    // if (!configFile.startsWith("classpath"))
    // configFile = "classpath:" + configFile;
    // Log4jConfigurer.initLogging(configFile);
    // }
    // catch (FileNotFoundException e)
    // {
    // System.err.println("File " + configFile + " not exists!");
    // }
}