List of usage examples for java.net URI getSchemeSpecificPart
public String getSchemeSpecificPart()
From source file:com.dianping.resource.io.util.ResourceUtils.java
/** * Resolve the given resource URI to a {@code java.io.File}, * i.e. to a file in the file system./*ww w.j a v a2s . com*/ * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws java.io.FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException(description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
From source file:cn.org.rapid_framework.generator.util.ResourceHelper.java
/** * Resolve the given resource URI to a <code>java.io.File</code>, * i.e. to a file in the file system.//from w w w. j a v a 2 s . com * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { if (resourceUri == null) throw new IllegalArgumentException("Resource URL must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException(description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
From source file:org.apache.hadoop.security.ProviderUtils.java
/** * Mangle given local java keystore file URI to allow use as a * LocalJavaKeyStoreProvider.// w w w. ja va 2s.c o m * @param localFile absolute URI with file scheme and no authority component. * i.e. return of File.toURI, * e.g. file:///home/larry/creds.jceks * @return URI of the form localjceks://file/home/larry/creds.jceks * @throws IllegalArgumentException if localFile isn't not a file uri or if it * has an authority component. * @throws URISyntaxException if the wrapping process violates RFC 2396 */ public static URI nestURIForLocalJavaKeyStoreProvider(final URI localFile) throws URISyntaxException { if (!("file".equals(localFile.getScheme()))) { throw new IllegalArgumentException("passed URI had a scheme other than " + "file."); } if (localFile.getAuthority() != null) { throw new IllegalArgumentException( "passed URI must not have an " + "authority component. For non-local keystores, please use " + JavaKeyStoreProvider.class.getName()); } return new URI(LocalJavaKeyStoreProvider.SCHEME_NAME, "//file" + localFile.getSchemeSpecificPart(), localFile.getFragment()); }
From source file:org.orbisgis.commons.utils.FileUtils.java
/** * Gets a convenient name from an URI.//from w w w . j a v a 2s . c o m * * The URI scheme can be file or anything with a 'tablename' querystring parameter. * Anything else is unsupported. * * @param u an URI * @return a name for it * @throws UnsupportedOperationException if the URI is unsupported. */ public static String getNameFromURI(URI u) { if ("file".equalsIgnoreCase(u.getScheme())) { return FilenameUtils.removeExtension(new File(u.getPath()).getName()); } else { if ("jdbc".equalsIgnoreCase(u.getScheme())) { try { u = URI.create(u.getSchemeSpecificPart()); } catch (IllegalArgumentException ex) { //Ignore } } String q = u.getQuery(); if (q != null && !q.isEmpty()) { // With & parameters String[] pat = q.split("&"); for (String aPat : pat) { if (aPat.toLowerCase().startsWith(TABLE_PARAM)) { // Extract Table name return aPat.substring(TABLE_PARAM.length()); } else if (aPat.toLowerCase().startsWith(TABLE_PARAM_JDBC)) { // Extract Table name return aPat.substring(TABLE_PARAM_JDBC.length()); } } } String path = u.getPath(); if (path != null && !path.isEmpty()) { String[] paths = path.split("/"); if (paths.length >= 1) { if (!paths[paths.length - 1].isEmpty()) { return paths[paths.length - 1]; } } } } throw new UnsupportedOperationException(); }
From source file:com.ibm.amc.FileManager.java
/** * If the URI represents a temporary file, attempt to delete the corresponding file. * //from www . ja v a 2s . c o m * @param uri */ public static void deleteIfTemporaryFile(URI uri) { if (uri != null && uri.getScheme().equals(SCHEME)) { if (getFileForUri(uri).delete()) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary file " + uri.toString()); } else { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary file " + uri.toString()); } // Check for unzip directory final File unzipDirectory = new File(getDownloadDirectory(), uri.getSchemeSpecificPart()); if (unzipDirectory.exists()) { try { FileUtils.deleteDirectory(unzipDirectory); if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary directory " + unzipDirectory); } catch (final IOException e) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary directory " + unzipDirectory); } } } }
From source file:org.totschnig.myexpenses.Utils.java
static void share(Context context, File file, String target) { URI uri = null; try {/*from w w w.j av a 2 s . co m*/ uri = new URI(target); } catch (URISyntaxException e1) { Toast.makeText(context, context.getString(R.string.ftp_uri_malformed, target), Toast.LENGTH_LONG) .show(); return; } String scheme = uri.getScheme(); if (scheme.equals("ftp")) { new Utils.FtpAsyncTask(context, file, uri).execute(); return; } else if (scheme.equals("mailto")) { final PackageManager packageManager = context.getPackageManager(); final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("text/qif"); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { uri.getSchemeSpecificPart() }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My Expenses export"); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); if (packageManager.queryIntentActivities(emailIntent, 0).size() == 0) { Toast.makeText(context, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show(); return; } context.startActivity(emailIntent); } else { Toast.makeText(context, context.getString(R.string.share_scheme_not_supported, target), Toast.LENGTH_LONG).show(); } }
From source file:Main.java
public InputSource resolveEntity(String publicId, String systemId) { try {// w w w.j av a 2 s .c om URI uri = new URI(systemId); if ("file".equals(uri.getScheme())) { String filename = uri.getSchemeSpecificPart(); return new InputSource(new FileReader(filename)); } } catch (Exception e) { } return null; }
From source file:org.gradle.messaging.remote.internal.HandshakeOutgoingConnector.java
private URI toConnectionAddress(URI destinationAddress) { String content = destinationAddress.getSchemeSpecificPart(); URI connectionAddress;//from w w w .j a va2 s.com try { connectionAddress = new URI(StringUtils.substringBeforeLast(content, "!")); } catch (URISyntaxException e) { throw new UncheckedException(e); } return connectionAddress; }
From source file:org.apache.juddi.config.ApplicationConfigurationTest.java
@Test public void testURLFormats() throws MalformedURLException, URISyntaxException { URI file = new URI("file:/tmp/"); String path = file.getSchemeSpecificPart(); Assert.assertEquals("/tmp/", path); URI fileInJar = new URI("jar:file:/tmp/my.jar!/"); String path1 = fileInJar.getSchemeSpecificPart(); Assert.assertEquals("file:/tmp/my.jar!/", path1); URI fileInZip = new URI("zip:D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!"); String path2 = fileInZip.getSchemeSpecificPart(); Assert.assertEquals("D:/bea/tmp/_WL_user/JuddiEAR/nk4cwv/war/WEB-INF/lib/juddi-core-3.0.1.jar!", path2); URI fileInVfszip = new URI( "vfsfile:/tmp/SOA%20Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml"); String path3 = fileInVfszip.getSchemeSpecificPart(); Assert.assertEquals("/tmp/SOA Platform/jbossesb-registry.sar/juddi_custom_install_data/root_Publisher.xml", path3);//from ww w.jav a 2s . c o m }
From source file:org.codehaus.groovy.grails.io.support.GrailsResourceUtils.java
/** * Resolve the given resource URI to a <code>java.io.File</code>, * i.e. to a file in the file system./*ww w . j a v a2 s . c om*/ * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException(description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }