Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.apache.beam.runners.apex.ApexRunner.java

@Override
public ApexRunnerResult run(final Pipeline pipeline) {
    pipeline.replaceAll(getOverrides());

    final ApexPipelineTranslator translator = new ApexPipelineTranslator(options);
    final AtomicReference<DAG> apexDAG = new AtomicReference<>();
    final AtomicReference<File> tempDir = new AtomicReference<>();

    StreamingApplication apexApp = (dag, conf) -> {
        apexDAG.set(dag);//from ww  w . j  ava 2 s . c o  m
        dag.setAttribute(DAGContext.APPLICATION_NAME, options.getApplicationName());
        if (options.isEmbeddedExecution()) {
            // set unique path for application state to allow for parallel execution of unit tests
            // (the embedded cluster would set it to a fixed location under ./target)
            tempDir.set(Files.createTempDir());
            dag.setAttribute(DAGContext.APPLICATION_PATH, tempDir.get().toURI().toString());
        }
        translator.translate(pipeline, dag);
    };

    Properties configProperties = new Properties();
    try {
        if (options.getConfigFile() != null) {
            URI configURL = new URI(options.getConfigFile());
            if (CLASSPATH_SCHEME.equals(configURL.getScheme())) {
                InputStream is = this.getClass().getResourceAsStream(configURL.getPath());
                if (is != null) {
                    configProperties.load(is);
                    is.close();
                }
            } else {
                if (!configURL.isAbsolute()) {
                    // resolve as local file name
                    File f = new File(options.getConfigFile());
                    configURL = f.toURI();
                }
                try (InputStream is = configURL.toURL().openStream()) {
                    configProperties.load(is);
                }
            }
        }
    } catch (IOException | URISyntaxException ex) {
        throw new RuntimeException("Error loading properties", ex);
    }

    if (options.isEmbeddedExecution()) {
        EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
        Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
        launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
        if (options.isEmbeddedExecutionDebugMode()) {
            // turns off timeout checking for operator progress
            launchAttributes.put(EmbeddedAppLauncher.HEARTBEAT_MONITORING, false);
        }
        Configuration conf = new Configuration(false);
        ApexYarnLauncher.addProperties(conf, configProperties);
        try {
            if (translateOnly) {
                launcher.prepareDAG(apexApp, conf);
                return new ApexRunnerResult(launcher.getDAG(), null);
            }
            ApexRunner.ASSERTION_ERROR.set(null);
            AppHandle apexAppResult = launcher.launchApp(apexApp, conf, launchAttributes);
            return new ApexRunnerResult(apexDAG.get(), apexAppResult) {
                @Override
                protected void cleanupOnCancelOrFinish() {
                    if (tempDir.get() != null) {
                        FileUtils.deleteQuietly(tempDir.get());
                    }
                }
            };
        } catch (Exception e) {
            Throwables.throwIfUnchecked(e);
            throw new RuntimeException(e);
        }
    } else {
        try {
            ApexYarnLauncher yarnLauncher = new ApexYarnLauncher();
            AppHandle apexAppResult = yarnLauncher.launchApp(apexApp, configProperties);
            return new ApexRunnerResult(apexDAG.get(), apexAppResult);
        } catch (IOException e) {
            throw new RuntimeException("Failed to launch the application on YARN.", e);
        }
    }
}

From source file:com.codesourcery.installer.Installer.java

/**
 * Resolves an install file.//from www .  j  a  v a 2 s . c  o  m
 * 
 * @param site File URI or <code>null</code>.
 * @param filename File name
 * @return File URI
 * @throws URISyntaxException on invalid syntax
 */
private URI resolveFile(String site, String filename) throws URISyntaxException {
    // If no URL was given from the outside, look for file 
    // relative to where the installer is running.  This allows the installer to be self-contained
    if (site == null)
        site = filename;

    URI propsURI = URIUtil.fromString(site);
    if (!propsURI.isAbsolute()) {
        String installerInstallArea = System.getProperty(IInstallConstants.OSGI_INSTALL_AREA);
        if (installerInstallArea == null)
            throw new IllegalStateException(InstallMessages.Error_NoInstallArea);

        // Get the locale
        String locale = Platform.getNL();
        // Check for locale installer description
        propsURI = URIUtil.append(URIUtil.fromString(installerInstallArea), locale);
        propsURI = URIUtil.append(propsURI, site);
        File installerDescription = URIUtil.toFile(propsURI);
        // If not found, use default install description
        if (!installerDescription.exists()) {
            propsURI = URIUtil.append(URIUtil.fromString(installerInstallArea), site);
            installerDescription = URIUtil.toFile(propsURI);
            if (!installerDescription.exists()) {
                propsURI = null;
            }
        }
    }

    return propsURI;
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * Add the given file the wait list if it has not been parsed.
 *
 * @param ref reference to absolute system path
 *///from   www . j  av a  2s .c o  m
void addToWaitList(final Reference ref) {
    final URI file = ref.filename;
    assert file.isAbsolute() && file.getFragment() == null;
    if (doneList.contains(file) || waitList.contains(ref) || file.equals(currentFile)) {
        return;
    }

    waitList.add(ref);
}

From source file:de.betterform.xml.xforms.XFormsProcessorImpl.java

private String resolve(URI relative) throws XFormsException {
    if (relative.isAbsolute() || relative.isOpaque()) {
        return relative.toString();
    }/*from   w w  w  . ja  v a 2s .c o  m*/

    if (this.baseURI == null) {
        throw new XFormsException("base uri not present");
    }

    try {
        return new URI(this.baseURI).resolve(relative).toString();
    } catch (URISyntaxException e) {
        throw new XFormsException(e);
    }
}

From source file:org.apache.cxf.maven_plugin.AbstractCodegenMoho.java

/**
 * Try to find a file matching the wsdl path (either absolutely, relatively to the current dir or to
 * the project base dir)/*w  w  w. j av a  2  s.c  o  m*/
 *
 * @return wsdl file
 */
public File getWsdlFile(GenericWsdlOption option, File baseDir) {
    if (option.getUri() == null) {
        return null;
    }
    File file = null;
    try {
        URI uri = new URI(option.getUri());
        if (uri.isAbsolute()) {
            file = new File(uri);
        }
    } catch (Exception e) {
        // ignore
    }
    if (file == null || !file.exists()) {
        file = new File(option.getUri());
    }
    if (!file.exists()) {
        file = new File(baseDir, option.getUri());
    }
    return file;
}

From source file:com.reprezen.swagedit.json.references.JsonReferenceFactory.java

protected JsonReference doCreate(String value, Object source) {
    String notNull = Strings.nullToEmpty(value);

    URI uri;
    try {/*from   w  w  w .  j  av a  2 s  .c om*/
        uri = URI.create(notNull);
    } catch (NullPointerException | IllegalArgumentException e) {
        // try to encode illegal characters, e.g. curly braces
        try {
            uri = URI.create(URLUtils.encodeURL(notNull));
        } catch (NullPointerException | IllegalArgumentException e2) {
            return new JsonReference(null, null, false, false, false, source);
        }
    }

    String fragment = uri.getFragment();
    JsonPointer pointer = null;
    try {
        pointer = JsonPointer.compile(Strings.emptyToNull(fragment));
    } catch (IllegalArgumentException e) {
        // let the pointer be null
    }

    uri = uri.normalize();
    boolean absolute = uri.isAbsolute();
    boolean local = !absolute && uri.getPath().isEmpty();
    // should warn when using curly braces
    boolean warnings = notNull.contains("{") || uri.toString().contains("}");

    return new JsonReference(uri, pointer, absolute, local, warnings, source);
}

From source file:org.killbill.billing.client.KillBillHttpClient.java

private String getKBServerUrl(final String uri) throws KillBillClientException {
    try {/*from   w w  w .j  a  v a  2 s  . c o  m*/
        final URI u = new URI(uri);
        if (u.isAbsolute()) {
            return uri;
        } else {
            return String.format("%s%s", kbServerUrl, uri);
        }
    } catch (final URISyntaxException e) {
        throw new KillBillClientException(e);
    }
}

From source file:org.apache.tez.client.TezClient.java

private Map<String, LocalResource> setupTezJarsLocalResources() throws IOException {
    Map<String, LocalResource> tezJarResources = new TreeMap<String, LocalResource>();
    if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) {
        return tezJarResources;
    }//ww  w  .  j a v  a  2s  . c om

    // Add tez jars to local resource
    String[] tezJarUris = conf.getStrings(TezConfiguration.TEZ_LIB_URIS);
    if (tezJarUris == null || tezJarUris.length == 0) {
        throw new TezUncheckedException("Invalid configuration of tez jars" + ", "
                + TezConfiguration.TEZ_LIB_URIS + " is not defined in the configurartion");
    }

    for (String tezJarUri : tezJarUris) {
        URI uri;
        try {
            uri = new URI(tezJarUri.trim());
        } catch (URISyntaxException e) {
            String message = "Invalid URI defined in configuration for" + " location of TEZ jars. providedURI="
                    + tezJarUri;
            LOG.error(message);
            throw new TezUncheckedException(message, e);
        }
        if (!uri.isAbsolute()) {
            String message = "Non-absolute URI defined in configuration for"
                    + " location of TEZ jars. providedURI=" + tezJarUri;
            LOG.error(message);
            throw new TezUncheckedException(message);
        }
        Path p = new Path(uri);
        FileSystem pathfs = p.getFileSystem(conf);
        RemoteIterator<LocatedFileStatus> iter = pathfs.listFiles(p, false);
        while (iter.hasNext()) {
            LocatedFileStatus fStatus = iter.next();
            String rsrcName = fStatus.getPath().getName();
            // FIXME currently not checking for duplicates due to quirks
            // in assembly generation
            if (tezJarResources.containsKey(rsrcName)) {
                String message = "Duplicate resource found" + ", resourceName=" + rsrcName + ", existingPath="
                        + tezJarResources.get(rsrcName).getResource().toString() + ", newPath="
                        + fStatus.getPath();
                LOG.warn(message);
                // throw new TezUncheckedException(message);
            }
            tezJarResources.put(rsrcName,
                    LocalResource.newInstance(ConverterUtils.getYarnUrlFromPath(fStatus.getPath()),
                            LocalResourceType.FILE, LocalResourceVisibility.PUBLIC, fStatus.getLen(),
                            fStatus.getModificationTime()));
        }
    }
    if (tezJarResources.isEmpty()) {
        LOG.warn("No tez jars found in configured locations" + ". Ignoring for now. Errors may occur");
    }
    return tezJarResources;
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * add FlagImangesSet to Properties, which needn't to change the dir level,
 * just ouput to the ouput dir./*from  w w w  .j  a  v  a  2 s  .c o  m*/
 *
 * @param prop job configuration
 * @param set absolute flag image files
 */
private void addFlagImagesSetToProperties(final Job prop, final Set<URI> set) {
    final Set<URI> newSet = new LinkedHashSet<>(128);
    for (final URI file : set) {
        //            assert file.isAbsolute();
        if (file.isAbsolute()) {
            // no need to append relative path before absolute paths
            newSet.add(file.normalize());
        } else {
            // In ant, all the file separator should be slash, so we need to
            // replace all the back slash with slash.
            newSet.add(file.normalize());
        }
    }

    // write list attribute to file
    final String fileKey = Constants.REL_FLAGIMAGE_LIST.substring(0,
            Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey,
            Constants.REL_FLAGIMAGE_LIST.substring(0, Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list"))
                    + ".list");
    final File list = new File(job.tempDir, prop.getProperty(fileKey));
    try (Writer bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)))) {
        for (URI aNewSet : newSet) {
            bufferedWriter.write(aNewSet.getPath());
            bufferedWriter.write('\n');
        }
        bufferedWriter.flush();
    } catch (final IOException e) {
        logger.error(e.getMessage(), e);
    }

    prop.setProperty(Constants.REL_FLAGIMAGE_LIST, StringUtils.join(newSet, COMMA));
}

From source file:org.gridgain.grid.ggfs.hadoop.v2.GridGgfsHadoopFileSystem.java

/** {@inheritDoc} */
@Override/*from w  w w .j a v  a2 s  .  c  o m*/
public void checkPath(Path path) {
    URI uri = path.toUri();

    if (uri.isAbsolute()) {
        if (!F.eq(uri.getScheme(), GGFS_SCHEME))
            throw new InvalidPathException(
                    "Wrong path scheme [expected=" + GGFS_SCHEME + ", actual=" + uri.getAuthority() + ']');

        if (!F.eq(uri.getAuthority(), uriAuthority))
            throw new InvalidPathException(
                    "Wrong path authority [expected=" + uriAuthority + ", actual=" + uri.getAuthority() + ']');
    }
}