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:eu.esdihumboldt.hale.io.haleconnect.HaleConnectUrnBuilder.java

private static String[] splitProjectUrn(URI urn) {
    if (urn == null) {
        throw new NullPointerException("URN must not be null");
    } else if (!SCHEME_HALECONNECT.equals(urn.getScheme().toLowerCase())) {
        throw new IllegalArgumentException(
                MessageFormat.format("URN must have scheme \"{0}\"", SCHEME_HALECONNECT));
    }//from  ww w  . jav a 2 s. com

    if (StringUtils.isEmpty(urn.getSchemeSpecificPart())) {
        throw new IllegalArgumentException(MessageFormat.format("Malformed URN: {0}", urn.toString()));
    }

    String[] parts = urn.getSchemeSpecificPart().split(":");
    if (parts.length != 4) {
        throw new IllegalArgumentException(MessageFormat.format("Malformed URN: {0}", urn.toString()));
    } else if (!"project".equals(parts[0])) {
        throw new IllegalArgumentException(MessageFormat.format("No a project URN: {0}", urn.toString()));
    }
    return parts;
}

From source file:com.aaasec.sigserv.cscommon.xmldsig.OfflineResolver.java

private static URI getNewURI(String uri, String baseURI) throws URISyntaxException {
    URI newUri = null;
    if (baseURI == null || "".equals(baseURI)) {
        newUri = new URI(uri);
    } else {//from ww  w . j ava  2 s  . co  m
        newUri = new URI(baseURI).resolve(uri);
    }

    // if the URI contains a fragment, ignore it
    if (newUri.getFragment() != null) {
        URI uriNewNoFrag = new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
        return uriNewNoFrag;
    }
    return newUri;
}

From source file:com.ibm.amc.FileManager.java

private static File getFileForUri(URI uri) {
    return new File(getUploadDirectory(), FILE_PREFIX + uri.getSchemeSpecificPart() + FILE_SUFFIX);
}

From source file:com.microsoft.alm.plugin.context.ServerContext.java

/**
 * Use this static method to convert a server URI into an appropriate unique key for a serverContext object
 *//* ww  w .j a v  a2 s  .  c  om*/
public static String getKey(URI uri) {
    // Ignore case, scheme, and any fragments or queries
    final String key;
    if (uri != null) {
        key = uri.getSchemeSpecificPart().toLowerCase();
    } else {
        key = "";
    }

    return key;
}

From source file:Main.java

/** Obtiene el flujo de entrada de un fichero (para su lectura) a partir de su URI.
 * @param uri URI del fichero a leer/*from w  ww . ja va  2s . c  o  m*/
 * @return Flujo de entrada hacia el contenido del fichero
 * @throws IOException Cuando no se ha podido abrir el fichero de datos. */
public static InputStream loadFile(final URI uri) throws IOException {

    if (uri == null) {
        throw new IllegalArgumentException("Se ha pedido el contenido de una URI nula"); //$NON-NLS-1$
    }

    if (uri.getScheme().equals("file")) { //$NON-NLS-1$
        // Es un fichero en disco. Las URL de Java no soportan file://, con
        // lo que hay que diferenciarlo a mano

        // Retiramos el "file://" de la uri
        String path = uri.getSchemeSpecificPart();
        if (path.startsWith("//")) { //$NON-NLS-1$
            path = path.substring(2);
        }
        return new FileInputStream(new File(path));
    }

    // Es una URL
    final InputStream tmpStream = new BufferedInputStream(uri.toURL().openStream());

    // Las firmas via URL fallan en la descarga por temas de Sun, asi que
    // descargamos primero
    // y devolvemos un Stream contra un array de bytes
    final byte[] tmpBuffer = getDataFromInputStream(tmpStream);

    return new java.io.ByteArrayInputStream(tmpBuffer);
}

From source file:me.footlights.core.crypto.Fingerprint.java

public static Fingerprint decode(URI uri) throws FormatException, NoSuchAlgorithmException, URISyntaxException {
    if ((uri.getScheme() == null) || !uri.getScheme().equals("urn"))
        throw new FormatException("Fingerprint must start with 'urn:'");

    // Recurse down into scheme-specific part, which is also a URI.
    URI data = new URI(uri.getSchemeSpecificPart());
    return decode(data.getScheme(), data.getSchemeSpecificPart());
}

From source file:com.ibm.amc.FileManager.java

public static File decompress(URI temporaryFileUri) {
    final File destination = new File(getUploadDirectory(), temporaryFileUri.getSchemeSpecificPart());
    if (!destination.mkdirs()) {
        throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR, "CWZBA2001E_DIRECTORY_CREATION_FAILED",
                destination.getPath());//from ww  w. j  a  v a  2s .  co  m
    }

    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(getFileForUri(temporaryFileUri));

        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            File newDirOrFile = new File(destination, entry.getName());
            if (newDirOrFile.getParentFile() != null && !newDirOrFile.getParentFile().exists()) {
                if (!newDirOrFile.getParentFile().mkdirs()) {
                    throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR,
                            "CWZBA2001E_DIRECTORY_CREATION_FAILED", newDirOrFile.getParentFile().getPath());
                }
            }
            if (entry.isDirectory()) {
                if (!newDirOrFile.mkdir()) {
                    throw new AmcRuntimeException(Status.INTERNAL_SERVER_ERROR,
                            "CWZBA2001E_DIRECTORY_CREATION_FAILED", newDirOrFile.getPath());
                }
            } else {
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
                int size;
                byte[] buffer = new byte[ZIP_BUFFER];
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newDirOrFile),
                        ZIP_BUFFER);
                while ((size = bis.read(buffer, 0, ZIP_BUFFER)) != -1) {
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
                bis.close();
            }
        }
    } catch (Exception e) {
        throw new AmcRuntimeException(e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e) {
                logger.debug("decompress", "close failed with " + e);
            }
        }
    }

    return destination;
}

From source file:fedora.server.storage.lowlevel.akubra.AkubraLowlevelStorage.java

/**
 * Converts a token-as-blobId back to a token.
 *
 * @param blobId the blobId to convert.//from   w w  w . j a  v a  2s.co m
 * @return the resulting object or datastream token.
 */
private static String getToken(URI blobId) {
    String[] parts = blobId.getSchemeSpecificPart().split("/");
    if (parts.length == 2) {
        return parts[1];
    } else if (parts.length == 4) {
        return parts[1] + "+" + uriDecode(parts[2]) + "+" + uriDecode(parts[3]);
    } else {
        throw new IllegalArgumentException("Malformed token-as-blobId: " + blobId);
    }
}

From source file:com.google.caja.precajole.StaticPrecajoleMap.java

public static String normalizeUri(String uri) {
    try {/*from  w w  w. j  a va 2  s .  c  o m*/
        URI u = new URI(uri).normalize();
        if (u.getHost() != null) {
            u = new URI(lowercase(u.getScheme()), u.getUserInfo(), lowercase(u.getHost()), u.getPort(),
                    u.getPath(), u.getQuery(), u.getFragment());
        } else if (u.getScheme() != null) {
            u = new URI(lowercase(u.getScheme()), u.getSchemeSpecificPart(), u.getFragment());
        }
        return u.toString();
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:com.aol.advertising.qiao.util.CommonUtils.java

/**
 * Extends scheme to include 'classpath'.
 *
 * @param uriString/*from  w ww.  ja v  a  2 s. c  o  m*/
 * @return
 * @throws URISyntaxException
 * @throws IOException
 */
public static URL uriToURL(String uriString) throws URISyntaxException, IOException {
    URI uri = new URI(uriString);
    String scheme = uri.getScheme();
    if (scheme == null)
        throw new URISyntaxException(uriString, "Invalid URI syntax: missing scheme => " + uriString);

    if (scheme.equals("classpath")) {
        ClassPathResource res = new ClassPathResource(uri.getSchemeSpecificPart());
        return res.getURL();
    } else {
        return uri.toURL();
    }
}