Example usage for java.net URI toURL

List of usage examples for java.net URI toURL

Introduction

In this page you can find the example usage for java.net URI toURL.

Prototype

public URL toURL() throws MalformedURLException 

Source Link

Document

Constructs a URL from this URI.

Usage

From source file:org.cohorte.ecf.provider.jabsorb.host.JabsorbHttpSession.java

/**
 * Sets up the HTTP session/*from  w  w  w . ja  v a  2 s .  com*/
 * 
 * @param aUri
 *            The URI to use for communication
 * @throws MalformedURLException
 *             The given URI is malformed
 */
public JabsorbHttpSession(final URI aUri) throws MalformedURLException {

    super(aUri);
    pUrl = aUri.toURL();
}

From source file:com.netflix.curator.ensemble.exhibitor.DefaultExhibitorRestClient.java

@Override
public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception {
    URI uri = new URI(useSsl ? "https" : "http", null, hostname, port, uriPath, null, null);
    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
    connection.addRequestProperty("Accept", mimeType);
    StringBuilder str = new StringBuilder();
    InputStream in = new BufferedInputStream(connection.getInputStream());
    try {/* w  ww  .ja va 2 s .c o m*/
        for (;;) {
            int b = in.read();
            if (b < 0) {
                break;
            }
            str.append((char) (b & 0xff));
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
    return str.toString();
}

From source file:org.kalypso.zml.ui.chart.grafik.OpenDiagramInGrafikExeOperation.java

private IFolder getTempFolder(final String href) throws CoreException {
    try {/*ww  w .  ja  v a  2 s . co  m*/
        final IPath grafikPath = Path.fromOSString("grafik"); //$NON-NLS-1$

        final URI uri = URIUtil.fromString(href);
        final URL url = uri.toURL();

        final IFile eclipseFile = ResourceUtilities.findFileFromURL(url);
        if (eclipseFile != null)
            return eclipseFile.getParent().getFolder(grafikPath);

        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        final IFile[] files = root.findFilesForLocationURI(uri);
        for (final IFile file : files) {
            final IFolder folder = (IFolder) file.getParent();
            return folder.getFolder(grafikPath);
        }

        return null;
    } catch (final Exception e) {
        final IStatus status = new Status(IStatus.ERROR, KalypsoZmlUI.PLUGIN_ID,
                Messages.OpenDiagramInGrafikExeOperation_2, e);
        throw new CoreException(status);
    }
}

From source file:org.coffeebreaks.validators.jsonlint.JsonlintValidator.java

public ValidationResult validateUri(URI uri, ValidationRequest request) throws IOException {
    return validateUri(uri.toURL(), request);
}

From source file:eu.project.ttc.resources.DictionaryResource.java

@Override
public void load(URI resourceIdentifier) throws Exception {
    URLConnection connection = resourceIdentifier.toURL().openConnection();
    this.load(resourceIdentifier.getPath(), connection.getInputStream());
}

From source file:com.liferay.maven.arquillian.internal.tasks.ToolsClasspathTask.java

@Override
public URLClassLoader execute(MavenWorkingSession session) {

    final Logger log = LoggerFactory.getLogger(ToolsClasspathTask.class);

    final ParsedPomFile pomFile = session.getParsedPomFile();

    LiferayPluginConfiguration configuration = new LiferayPluginConfiguration(pomFile);

    System.setProperty("liferayVersion", configuration.getLiferayVersion());

    File appServerLibGlobalDir = new File(configuration.getAppServerLibGlobalDir());

    File appServerLibPortalDir = new File(configuration.getAppServerLibPortalDir());

    List<URI> liferayToolArchives = new ArrayList<URI>();

    if (appServerLibGlobalDir != null && appServerLibGlobalDir.exists()) {

        // app server global libraries
        Collection<File> appServerLibs = FileUtils.listFiles(appServerLibGlobalDir, new String[] { "jar" },
                true);//  w w w.  ja  v  a  2s.co m

        for (File file : appServerLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // All Liferay Portal Lib jars
        Collection<File> liferayPortalLibs = FileUtils.listFiles(appServerLibPortalDir, new String[] { "jar" },
                true);

        for (File file : liferayPortalLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // Util jars
        File[] utilJars = Maven.resolver().loadPomFromClassLoaderResource("liferay-tool-deps.xml")
                .importCompileAndRuntimeDependencies().resolve().using(AcceptAllStrategy.INSTANCE).asFile();

        for (int i = 0; i < utilJars.length; i++) {
            liferayToolArchives.add(utilJars[i].toURI());
        }

    }

    log.trace("Jars count in Tools classpath Archive:" + liferayToolArchives.size());

    List<URL> classpathUrls = new ArrayList<URL>();

    try {
        if (!liferayToolArchives.isEmpty()) {

            ListIterator<URI> toolsJarItr = liferayToolArchives.listIterator();
            while (toolsJarItr.hasNext()) {
                URI jarURI = toolsJarItr.next();
                classpathUrls.add(jarURI.toURL());
            }

        }
    } catch (MalformedURLException e) {
        log.error("Error building Tools classpath", e);
    }

    return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), null);
}

From source file:com.zotoh.maedr.device.FeedIO.java

@Override
protected void onOneLoop() throws Exception {
    SyndFeedInput input = new SyndFeedInput(_validate);
    //        SyndFeed feed;
    for (URI u : _urls) {
        dispatch(new FeedEvent(this, u.toASCIIString(), input.build(new XmlReader(u.toURL()))));
    }/*  ww w.j  a v  a 2  s . c  om*/
}

From source file:com.liferay.arquillian.maven.internal.tasks.ToolsClasspathTask.java

/**
 * (non-Javadoc)/*from w  ww  .  j av a 2s.c  om*/
 * @see
 * org.jboss.shrinkwrap.resolver.impl.maven.task.MavenWorkingSessionTask
 * #execute(org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession)
 */
@Override
public URLClassLoader execute(MavenWorkingSession session) {
    final ParsedPomFile pomFile = session.getParsedPomFile();

    LiferayPluginConfiguration configuration = new LiferayPluginConfiguration(pomFile);

    System.setProperty("liferayVersion", configuration.getLiferayVersion());

    File appServerLibGlobalDir = new File(configuration.getAppServerLibGlobalDir());

    File appServerLibPortalDir = new File(configuration.getAppServerLibPortalDir());

    List<URI> liferayToolArchives = new ArrayList<>();

    if ((appServerLibGlobalDir != null) && appServerLibGlobalDir.exists()) {

        // app server global libraries

        Collection<File> appServerLibs = FileUtils.listFiles(appServerLibGlobalDir, new String[] { "jar" },
                true);

        for (File file : appServerLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // All Liferay Portal Lib jars

        Collection<File> liferayPortalLibs = FileUtils.listFiles(appServerLibPortalDir, new String[] { "jar" },
                true);

        for (File file : liferayPortalLibs) {
            liferayToolArchives.add(file.toURI());
        }

        // Util jars

        File[] utilJars = Maven.resolver().loadPomFromClassLoaderResource("liferay-tool-deps.xml")
                .importCompileAndRuntimeDependencies().resolve().using(AcceptAllStrategy.INSTANCE).asFile();

        for (int i = 0; i < utilJars.length; i++) {
            liferayToolArchives.add(utilJars[i].toURI());
        }
    }

    if (_log.isTraceEnabled()) {
        _log.trace("Jars count in Tools classpath Archive:" + liferayToolArchives.size());
    }

    List<URL> classpathUrls = new ArrayList<>();

    try {
        if (!liferayToolArchives.isEmpty()) {
            ListIterator<URI> toolsJarItr = liferayToolArchives.listIterator();
            while (toolsJarItr.hasNext()) {
                URI jarURI = toolsJarItr.next();
                classpathUrls.add(jarURI.toURL());
            }
        }
    } catch (MalformedURLException e) {
        _log.error("Error building Tools classpath", e);
    }

    return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), null);
}

From source file:org.ldp4j.tutorial.client.AbstractLdpCommandProcessor.java

private String loadConstraintReport(URI constraintReport) throws IOException {
    URL url = constraintReport.toURL();
    InputStream is = null;/*from  w  w  w. ja v a2s .com*/
    try {
        is = url.openStream();
        return IOUtils.toString(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:org.jboss.pnc.termdbuilddriver.transfer.TermdFileTranser.java

public void uploadScript(String script, Path remoteFilePath) throws TransferException {
    logger.debug("Uploading build script to remote path {}, build script {}", remoteFilePath, script);
    String scriptPath = UPLOAD_PATH + remoteFilePath.toAbsolutePath().toString();
    logger.debug("Resolving script path {} to base uri {}", scriptPath, baseServerUri);
    URI uploadUri = baseServerUri.resolve(scriptPath);
    try {//from w  w  w. j a  v a  2 s.  co m
        HttpURLConnection connection = (HttpURLConnection) uploadUri.toURL().openConnection();
        connection.setRequestMethod("PUT");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        byte[] fileContent = script.getBytes();
        connection.setRequestProperty("Content-Length", "" + Integer.toString(fileContent.length));

        try (OutputStream outputStream = connection.getOutputStream()) {
            outputStream.write(fileContent);
        }

        if (200 != connection.getResponseCode()) {
            throw new TransferException("Could not upload script to Build Agent at url " + connection.getURL()
                    + " - Returned status code " + connection.getResponseCode());
        }
        logger.debug("Uploaded successfully");
    } catch (IOException e) {
        throw new TransferException("Could not upload build script: " + uploadUri.toString(), e);
    }
}