Example usage for java.net URI getSchemeSpecificPart

List of usage examples for java.net URI getSchemeSpecificPart

Introduction

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

Prototype

public String getSchemeSpecificPart() 

Source Link

Document

Returns the decoded scheme-specific part of this URI.

Usage

From source file:gov.nih.nci.caarray.dataStorage.database.DatabaseMultipartBlobDataStorage.java

/**
 * {@inheritDoc}//from  ww w . j  a v a2s  .  c  o  m
 */
public StorageMetadata finalizeChunkedFile(URI handle) {
    MultiPartBlob multiPartBlob = searchDao.retrieve(MultiPartBlob.class,
            Long.valueOf(handle.getSchemeSpecificPart()));
    try {
        InputStream is = multiPartBlob.readCompressedContents();
        return add(is, false);
    } catch (IOException e) {
        throw new DataStoreException("Could not add data", e);
    }
}

From source file:com.mirth.connect.connectors.file.FileConnector.java

/**
 * URI.getPath() does not retrieve the desired result for relative paths. The first directory
 * would be omitted and the second directory would be used with the system's root as the base.
 * Thus for connectors using the FILE scheme, we retrieve the path using an alternate method.
 *///  w  w w  .  j  a v  a2  s. com
protected String getPathPart(URI uri) {
    if (scheme == FileScheme.FILE) {
        // In //xyz, return xyz.
        return uri.getSchemeSpecificPart().substring(2);
    } else {
        // For the remaining cases, getPath seems to do the right thing.
        return uri.getPath();
    }
}

From source file:gov.nih.nci.caarray.application.fileaccess.FileAccessServiceStub.java

@Override
public File openFile(URI handle, boolean compressed) throws DataStoreException {
    checkScheme(handle);/* w  w  w  .  j av a2s .co  m*/
    return this.nameToFile.get(handle.getSchemeSpecificPart());
}

From source file:gov.nih.nci.caarray.dataStorage.database.DatabaseMultipartBlobDataStorage.java

/**
 * {@inheritDoc}/*www.  j  av a2  s  .co m*/
 */
@Override
public File openFile(URI handle, boolean compressed) throws DataStoreException {
    checkScheme(handle);
    final String tempFileName = fileName(handle.getSchemeSpecificPart(), compressed);
    final TemporaryFileCache tempFileCache = this.tempFileCacheSource.get();
    File tempFile = tempFileCache.getFile(tempFileName);
    if (tempFile != null) {
        return tempFile;
    } else {
        tempFile = tempFileCache.createFile(tempFileName);
        final MultiPartBlob blob = this.searchDao.retrieve(MultiPartBlob.class,
                Long.valueOf(handle.getSchemeSpecificPart()));
        if (blob == null) {
            throw new DataStoreException("No data found for handle " + handle);
        }
        try {
            final OutputStream os = FileUtils.openOutputStream(tempFile);
            copyContentsToStream(blob, !compressed, os);
            IOUtils.closeQuietly(os);
        } catch (final IOException e) {
            throw new DataStoreException("Could not write out file ", e);
        }
        return tempFile;
    }
}

From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java

protected final Archive createArchive() {
    try {/*  w ww.  j a  v a 2s  .  c  om*/
        ProtectionDomain protectionDomain = getClass().getProtectionDomain();
        CodeSource codeSource = protectionDomain.getCodeSource();
        URI location;
        location = (codeSource == null ? null : codeSource.getLocation().toURI());
        String path = (location == null ? null : location.getSchemeSpecificPart());
        if (path == null) {
            throw new IllegalStateException("Unable to determine code source archive");
        }
        File root = new File(path);
        if (!root.exists()) {
            throw new IllegalStateException("Unable to determine code source archive from " + root);
        }
        return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
    } catch (Exception e) {
        throw new IllegalStateException("Cannt create local archive", e);
    }
}

From source file:ru.histone.resourceloaders.DefaultResourceLoader.java

private Resource loadDataResource(String location) {

    Resource resource = null;//from www . ja  va2 s .c o  m

    if (!location.matches("data:(.*);base64,(.*)")) {
        return null;
    }
    URI uri = makeFullLocation(location, "");
    String[] stringUri = uri.getSchemeSpecificPart().split(",");

    if (stringUri.length > 1) {
        String toEncode = stringUri[1];
        if (stringUri[0].contains("base64")) {
            InputStream stream = new ByteArrayInputStream(Base64.decodeBase64(toEncode.getBytes()));
            resource = new StreamResource(stream, location.toString(), ContentType.TEXT);
        } else {
            resource = new StringResource(toEncode, location.toString(), ContentType.TEXT);
        }
    } else {
        resource = new StringResource("", location.toString(), ContentType.TEXT);
    }

    return resource;
}

From source file:de.betterform.connector.http.HTTPSubmissionHandlerXI.java

/**
 * Serializes and submits the specified instance data over the <code>http</code> protocol.
 *
 * @param submission the submission issuing the request.
 * @param instance   the instance data to be serialized and submitted.
 * @return a map holding the response mime-type and the response stream.
 * @throws de.betterform.xml.xforms.exception.XFormsException if any error occurred during submission.
 *//* w w  w.j  a  v a 2s  .c om*/
public Map submit(Submission submission, Node instance) throws XFormsException {
    Map result = super.submit(submission, instance);
    InputStream inputStream = (InputStream) result.get(XFormsProcessor.SUBMISSION_RESPONSE_STREAM);

    if ((submission.getReplace().equals("instance"))) {
        String xsltPath = Config.getInstance().getProperty("resource.dir.name") + "xslt";

        CachingTransformerService transformerService = (CachingTransformerService) getContext()
                .get(TransformerService.TRANSFORMER_SERVICE);
        URI webappRealpath = null;
        try {
            webappRealpath = new URI((String) getContext().get("webapp.realpath"));
        } catch (URISyntaxException e) {
            throw new XFormsException("URISyntaxException for getContext().get('webapp.realpath')", e);
        }
        String styleSheetURIPath = webappRealpath.getSchemeSpecificPart() + xsltPath;
        URI styleSheetUri = new File(styleSheetURIPath, "include.xsl").toURI();

        XSLTGenerator generator = new XSLTGenerator();
        generator.setTransformerService(transformerService);
        generator.setStylesheetURI(styleSheetUri);

        ConnectorFactory connectorFactory = submission.getContainerObject().getConnectorFactory();
        String baseURI = connectorFactory.getAbsoluteURI(getURI(), submission.getElement()).toString();
        String uri = baseURI.substring(0, baseURI.lastIndexOf("/") + 1);

        generator.setParameter("root", uri);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        generator.setInput(inputStream);
        generator.setOutput(outputStream);
        generator.generate();

        // create input stream from result
        inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    }
    Map response = new HashMap();
    response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, inputStream);

    return response;

}

From source file:com.quantil.http.HttpProcessor.java

private HttpHost hostFromURI(String strUri) throws URISyntaxException {

    URI uri = new URI(strUri);
    //    HttpHost host = new HttpHost(uri.getHost(), uri.getScheme().equals("https") ? 443 : 80, uri.getScheme());
    int port;/*  w ww  .j a  v a2  s  . co m*/
    if (uri.getSchemeSpecificPart().contains("hdt"))
        port = 7443;
    else if (uri.getScheme().equals("https") && !uri.getSchemeSpecificPart().contains("hdt"))
        port = 443;
    else
        port = 80;
    HttpHost host = new HttpHost(uri.getSchemeSpecificPart().substring(2, uri.getSchemeSpecificPart().length()),
            port, uri.getScheme());

    return host;
}

From source file:org.apache.camel.impl.DefaultComponent.java

public Endpoint createEndpoint(String uri) throws Exception {
    ObjectHelper.notNull(getCamelContext(), "camelContext");
    //encode URI string to the unsafe URI characters
    URI u = new URI(UnsafeUriCharactersEncoder.encode(uri));
    String path = u.getSchemeSpecificPart();

    // lets trim off any query arguments
    if (path.startsWith("//")) {
        path = path.substring(2);//from   www  .  j av a2s.  com
    }
    int idx = path.indexOf('?');
    if (idx > 0) {
        path = path.substring(0, idx);
    }
    Map<String, Object> parameters = URISupport.parseParameters(u);

    validateURI(uri, path, parameters);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating endpoint uri=[" + uri + "], path=[" + path + "], parameters=[" + parameters + "]");
    }
    Endpoint endpoint = createEndpoint(uri, path, parameters);
    if (endpoint == null) {
        return null;
    }

    if (parameters != null && !parameters.isEmpty()) {
        endpoint.configureProperties(parameters);
        if (useIntrospectionOnEndpoint()) {
            setProperties(endpoint, parameters);
        }

        // if endpoint is strict (not lenient) and we have unknown parameters configured then
        // fail if there are parameters that could not be set, then they are probably misspell or not supported at all
        if (!endpoint.isLenientProperties()) {
            validateParameters(uri, parameters, null);
        }
    }

    afterConfiguration(uri, path, endpoint, parameters);
    return endpoint;
}

From source file:pl.psnc.synat.wrdz.zmd.download.DownloadManagerBean.java

/**
 * Checks weather the resource is already locally cached/stored on the server that runs the app.
 * /* w w w .j  av  a  2 s .  com*/
 * @param uri
 *            resource's URI
 * @return <code>true</code>, if item is stored on local machine, else <code>false</code>
 */
private boolean isLocallyCached(URI uri) {
    logger.debug("uri of the resource: " + uri);
    String protocol = uri.getScheme();
    if (protocol.toLowerCase().startsWith("file")) {
        // any resource accessible by the file protocol is cached (locally also means by mounted network drives)
        if ((new File(uri.getSchemeSpecificPart())).exists()) {
            return true;
        }
    }
    return false;
}