List of usage examples for java.net URI getScheme
public String getScheme()
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
public static void validateFile(URI fileLocation, String token, boolean validateLevel) throws Exception { BufferedReader reader = null; int lineNo = 1; if (token == null) { token = token_;/*from w ww . ja v a 2 s. c o m*/ } // test MRCUI.RRF URI mrCUIFile = fileLocation.resolve("MRCUI.RRF"); if (mrCUIFile == null) { throw new ConnectionFailure("Did not find the expected MRCUI.RRF file in the location provided."); } if (mrCUIFile.getScheme().equals("file")) { new FileReader(new File(mrCUIFile)).close(); } else { new InputStreamReader(mrCUIFile.toURL().openConnection().getInputStream()).close(); } try { reader = getReader(mrCUIFile); String line = reader.readLine(); lineNo = 1; boolean notAMonth = false; while (line != null) { if (line.startsWith("#") || line.length() == 0) { line = reader.readLine(); continue; } if (validateLevel && lineNo > 10) { break; } List<String> elements = deTokenizeString(line, token_); if (elements.size() != 7) { throw new Exception( "MRCUI.RRF " + "(" + "Line:" + lineNo + ")" + " is not in the required format."); } if (!elements.get(0).toLowerCase().startsWith("c")) { throw new Exception("MRCUI.RRF " + "(" + "Line:" + lineNo + "): " + "The concept(" + elements.get(0) + ") is not in the required format."); } try { String month = elements.get(1).substring(4); int i = Integer.parseInt(month); if (i < 0 || i > 12) { throw new Exception(); } else { notAMonth = false; } } catch (Exception e) { notAMonth = true; } if (!elements.get(1).endsWith("AA") && !elements.get(1).endsWith("AB") && !elements.get(1).endsWith("AC") && !elements.get(1).endsWith("AD") && notAMonth) { throw new Exception("MRCUI.RRF " + "(" + "Line:" + lineNo + "): " + "The Release id (" + elements.get(1) + ") is not in the required format."); } lineNo++; line = reader.readLine(); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { reader.close(); } // test MRCONSO.RRF URI mrCONSOFile = fileLocation.resolve("MRCONSO.RRF"); if (mrCONSOFile == null) { throw new ConnectionFailure("Did not find the expected MRCONSO.RRF file in the location provided."); } if (mrCONSOFile.getScheme().equals("file")) { new FileReader(new File(mrCONSOFile)).close(); } else { new InputStreamReader(mrCONSOFile.toURL().openConnection().getInputStream()).close(); } try { reader = getReader(mrCONSOFile); String line = reader.readLine(); lineNo = 1; while (line != null) { if (line.startsWith("#") || line.length() == 0) { line = reader.readLine(); continue; } if (validateLevel && lineNo > 10) { break; } List<String> elements = deTokenizeString(line, token_); if (elements.size() != 18) { throw new Exception( "MRCONSO.RRF " + "(" + "Line:" + lineNo + ")" + " is not in the required format."); } lineNo++; line = reader.readLine(); } } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } finally { reader.close(); } }
From source file:com.ibm.jaggr.core.test.TestUtils.java
public static IAggregator createMockAggregator(Ref<IConfig> configRef, File workingDirectory, List<InitParam> initParams, Class<?> aggregatorProxyClass, IHttpTransport transport) throws Exception { final IAggregator mockAggregator = EasyMock.createNiceMock(IAggregator.class); IOptions options = new OptionsImpl(false, null); options.setOption(IOptions.DELETE_DELAY, "0"); if (initParams == null) { initParams = new LinkedList<InitParam>(); }//from w w w .j a v a 2 s . com final InitParams aggInitParams = new InitParams(initParams); boolean createConfig = (configRef == null); if (workingDirectory == null) { workingDirectory = new File(System.getProperty("java.io.tmpdir")); } final Ref<ICacheManager> cacheMgrRef = new Ref<ICacheManager>(null); final Ref<IHttpTransport> transportRef = new Ref<IHttpTransport>( transport == null ? new TestDojoHttpTransport() : transport); final Ref<IExecutors> executorsRef = new Ref<IExecutors>(new ExecutorsImpl(new SynchronousExecutor(), null, new SynchronousScheduledExecutor(), new SynchronousScheduledExecutor())); final File workdir = workingDirectory; EasyMock.expect(mockAggregator.getWorkingDirectory()).andReturn(workingDirectory).anyTimes(); EasyMock.expect(mockAggregator.getName()).andReturn("test").anyTimes(); EasyMock.expect(mockAggregator.getOptions()).andReturn(options).anyTimes(); EasyMock.expect(mockAggregator.getExecutors()).andAnswer(new IAnswer<IExecutors>() { public IExecutors answer() throws Throwable { return executorsRef.get(); } }).anyTimes(); if (createConfig) { configRef = new Ref<IConfig>(null); // ConfigImpl constructor calls IAggregator.newResource() EasyMock.expect(mockAggregator.newResource((URI) EasyMock.anyObject())) .andAnswer(new IAnswer<IResource>() { public IResource answer() throws Throwable { return mockAggregatorNewResource((URI) EasyMock.getCurrentArguments()[0], workdir); } }).anyTimes(); } EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject())) .andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return (String) EasyMock.getCurrentArguments()[0]; } }).anyTimes(); EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject(), (IAggregator.SubstitutionTransformer) EasyMock.anyObject())).andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return (String) EasyMock.getCurrentArguments()[0]; } }).anyTimes(); EasyMock.expect(mockAggregator.newLayerCache()).andAnswer(new IAnswer<ILayerCache>() { public ILayerCache answer() throws Throwable { return new LayerCacheImpl(mockAggregator); } }).anyTimes(); EasyMock.expect(mockAggregator.newModuleCache()).andAnswer(new IAnswer<IModuleCache>() { public IModuleCache answer() throws Throwable { return new ModuleCacheImpl(); } }).anyTimes(); EasyMock.expect(mockAggregator.newGzipCache()).andAnswer(new IAnswer<IGzipCache>() { public IGzipCache answer() throws Throwable { return new GzipCacheImpl(); } }).anyTimes(); EasyMock.expect(mockAggregator.getInitParams()).andAnswer(new IAnswer<InitParams>() { public InitParams answer() throws Throwable { return aggInitParams; } }).anyTimes(); EasyMock.replay(mockAggregator); IAggregator mockAggregatorProxy = mockAggregator; if (aggregatorProxyClass != null) { mockAggregatorProxy = (IAggregator) aggregatorProxyClass .getConstructor(new Class[] { IAggregator.class }).newInstance(mockAggregator); } TestCacheManager cacheMgr = new TestCacheManager(mockAggregatorProxy, 1); cacheMgrRef.set(cacheMgr); //((IOptionsListener)cacheMgrRef.get()).optionsUpdated(options, 1); if (createConfig) { configRef.set(new ConfigImpl(mockAggregatorProxy, workingDirectory.toURI(), "{}")); } EasyMock.reset(mockAggregator); EasyMock.expect(mockAggregator.getWorkingDirectory()).andReturn(workingDirectory).anyTimes(); EasyMock.expect(mockAggregator.getOptions()).andReturn(options).anyTimes(); EasyMock.expect(mockAggregator.getName()).andReturn("test").anyTimes(); EasyMock.expect(mockAggregator.getTransport()).andAnswer(new IAnswer<IHttpTransport>() { public IHttpTransport answer() throws Throwable { return transportRef.get(); } }).anyTimes(); EasyMock.expect(mockAggregator.newResource((URI) EasyMock.anyObject())).andAnswer(new IAnswer<IResource>() { public IResource answer() throws Throwable { return mockAggregatorNewResource((URI) EasyMock.getCurrentArguments()[0], workdir); } }).anyTimes(); EasyMock.expect(mockAggregator.getResourceFactory(EasyMock.isA(Mutable.class))) .andAnswer(new IAnswer<IResourceFactory>() { public IResourceFactory answer() throws Throwable { Mutable<URI> uriRef = (Mutable<URI>) EasyMock.getCurrentArguments()[0]; URI uri = uriRef.getValue(); if (!uri.isAbsolute() && uri.getPath().startsWith("/")) return null; return ("file".equals(uri.getScheme())) ? new FileResourceFactory() : null; } }).anyTimes(); EasyMock.expect( mockAggregator.getModuleBuilder((String) EasyMock.anyObject(), (IResource) EasyMock.anyObject())) .andAnswer(new IAnswer<IModuleBuilder>() { public IModuleBuilder answer() throws Throwable { String mid = (String) EasyMock.getCurrentArguments()[0]; return mid.contains(".") ? new TextModuleBuilder() : new JavaScriptModuleBuilder(); } }).anyTimes(); final Ref<IConfig> cfgRef = configRef; EasyMock.expect(mockAggregator.getConfig()).andAnswer(new IAnswer<IConfig>() { public IConfig answer() throws Throwable { return cfgRef.get(); } }).anyTimes(); EasyMock.expect(mockAggregator.getCacheManager()).andAnswer(new IAnswer<ICacheManager>() { public ICacheManager answer() throws Throwable { return cacheMgrRef.get(); } }).anyTimes(); EasyMock.expect(mockAggregator.newModule((String) EasyMock.anyObject(), (URI) EasyMock.anyObject())) .andAnswer(new IAnswer<IModule>() { public IModule answer() throws Throwable { String mid = (String) EasyMock.getCurrentArguments()[0]; URI uri = (URI) EasyMock.getCurrentArguments()[1]; return new ModuleImpl(mid, uri); } }).anyTimes(); EasyMock.expect(mockAggregator.getExecutors()).andAnswer(new IAnswer<IExecutors>() { public IExecutors answer() throws Throwable { return executorsRef.get(); } }).anyTimes(); EasyMock.expect(mockAggregator.newLayerCache()).andAnswer(new IAnswer<ILayerCache>() { public ILayerCache answer() throws Throwable { return new LayerCacheImpl(mockAggregator); } }).anyTimes(); EasyMock.expect(mockAggregator.newModuleCache()).andAnswer(new IAnswer<IModuleCache>() { public IModuleCache answer() throws Throwable { return new ModuleCacheImpl(); } }).anyTimes(); EasyMock.expect(mockAggregator.newGzipCache()).andAnswer(new IAnswer<IGzipCache>() { public IGzipCache answer() throws Throwable { return new GzipCacheImpl(); } }).anyTimes(); EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject())) .andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return (String) EasyMock.getCurrentArguments()[0]; } }).anyTimes(); EasyMock.expect(mockAggregator.substituteProps((String) EasyMock.anyObject(), (IAggregator.SubstitutionTransformer) EasyMock.anyObject())).andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return (String) EasyMock.getCurrentArguments()[0]; } }).anyTimes(); EasyMock.expect(mockAggregator.getInitParams()).andAnswer(new IAnswer<InitParams>() { public InitParams answer() throws Throwable { return aggInitParams; } }).anyTimes(); EasyMock.expect( mockAggregator.buildAsync(EasyMock.isA(Callable.class), EasyMock.isA(HttpServletRequest.class))) .andAnswer((IAnswer) new IAnswer<Future<?>>() { @Override public Future<?> answer() throws Throwable { Callable<?> builder = (Callable<?>) EasyMock.getCurrentArguments()[0]; return executorsRef.get().getBuildExecutor().submit(builder); } }).anyTimes(); return mockAggregator; }
From source file:cascading.flow.hadoop.util.HadoopUtil.java
public static void resolvePaths(Configuration config, Collection<String> classpath, String remoteRoot, String resourceSubPath, Map<String, Path> localPaths, Map<String, Path> remotePaths) { FileSystem defaultFS = getDefaultFS(config); FileSystem localFS = getLocalFS(config); Path remoteRootPath = new Path(remoteRoot == null ? "./.staging" : remoteRoot); if (resourceSubPath != null) remoteRootPath = new Path(remoteRootPath, resourceSubPath); remoteRootPath = defaultFS.makeQualified(remoteRootPath); boolean defaultIsLocal = defaultFS.equals(localFS); for (String stringPath : classpath) { Path path = new Path(stringPath); URI uri = path.toUri(); if (uri.getScheme() == null && !defaultIsLocal) // we want to sync {//from www .j a v a2 s . co m Path localPath = localFS.makeQualified(path); if (!exists(localFS, localPath)) throw new FlowException("path not found: " + localPath); String name = localPath.getName(); if (resourceSubPath != null) name = resourceSubPath + "/" + name; localPaths.put(name, localPath); remotePaths.put(name, defaultFS.makeQualified(new Path(remoteRootPath, path.getName()))); } else if (localFS.equals(getFileSystem(config, path))) { if (!exists(localFS, path)) throw new FlowException("path not found: " + path); Path localPath = localFS.makeQualified(path); String name = localPath.getName(); if (resourceSubPath != null) name = resourceSubPath + "/" + name; localPaths.put(name, localPath); } else { if (!exists(defaultFS, path)) throw new FlowException("path not found: " + path); Path defaultPath = defaultFS.makeQualified(path); String name = defaultPath.getName(); if (resourceSubPath != null) name = resourceSubPath + "/" + name; remotePaths.put(name, defaultPath); } } }
From source file:com.sworddance.util.UriFactoryImpl.java
/** * Utility method to calculate port based on defaults for different schemas. * * @param uri uri to calculate port for/* w ww. jav a2 s .c o m*/ * @return integer port presentation */ public static int getPort(URI uri) { int port = uri.getPort(); if (port == -1) { String scheme = uri.getScheme(); if (HTTPS_SCHEME.equalsIgnoreCase(scheme)) { port = DEFAULT_HTTPS_PORT; } else { port = DEFAULT_HTTP_PORT; } } return port; }
From source file:com.microsoft.tfs.core.util.URIUtils.java
/** * <p>/*from ww w.ja v a2 s .co m*/ * Ensures that all the components of the {@link URI} are in lower-case. * </p> * * <p> * If the specified {@link URI} is opaque, it is returned. Otherwise, a new * {@link URI} is returned that is identical to the specified {@link URI} * except that the components (scheme, hostname, path) are converted to * their lower case equivalents (in a generic locale.) * </p> * * @param uri * a {@link URI} to check (must not be <code>null</code>) * @return a {@link URI} as described above (never <code>null</code>) */ public static URI toLowerCase(final URI uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ if (uri.isOpaque()) { return uri; } final String scheme = uri.getScheme() != null ? uri.getScheme().toLowerCase(LocaleUtil.ROOT) : null; final String authority = uri.getAuthority() != null ? uri.getAuthority().toLowerCase(LocaleUtil.ROOT) : null; final String path = uri.getPath() != null ? uri.getPath().toLowerCase(LocaleUtil.ROOT) : null; final String query = uri.getQuery() != null ? uri.getQuery().toLowerCase(LocaleUtil.ROOT) : null; final String fragment = uri.getFragment() != null ? uri.getFragment().toLowerCase(LocaleUtil.ROOT) : null; return newURI(scheme, authority, path, query, fragment); }
From source file:com.sangupta.jerry.oauth.OAuthUtils.java
/** * Return the signing base URL that is appended after the HTTP VERB in OAuth * header./* w w w . ja va 2 s .c om*/ * * @param uri * the {@link URI} instance from which the signing base is * extracted * * @return the extracted signing base from the {@link URI} instance */ public static String getSigningBaseURL(URI uri) { if (uri == null) { throw new IllegalArgumentException("URI cannot be null"); } StringBuilder builder = new StringBuilder(); builder.append(uri.getScheme().toLowerCase()); builder.append("://"); builder.append(uri.getHost().toLowerCase()); int port = uri.getPort(); if (!(port == 80 || port == -1)) { builder.append(':'); builder.append(String.valueOf(port)); } builder.append(uri.getPath()); return builder.toString(); }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Append the URL encoded OpenID message parameters to the query string of the provided URI. * //w w w .j a v a 2 s .c o m * @param uri URI to append OpenID message parameter to * @param message URL encoded OpenID message parameters * @return URI with message parameters appended */ public static URI appendMessageParameters(URI uri, String message) { if (uri == null || message == null) { return uri; } // build new query string StringBuffer queryBuffer = new StringBuffer(); if (uri.getRawQuery() != null) { queryBuffer.append(uri.getRawQuery()); } if (queryBuffer.length() > 0 && queryBuffer.charAt(queryBuffer.length() - 1) != '&') { queryBuffer.append('&'); } queryBuffer.append(message); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuffer.toString(), uri.getFragment()); } catch (URISyntaxException e) { log.error("Unable to append message parameters to URI: {}", e); } return null; }
From source file:com.vmware.thinapp.common.util.AfUtil.java
/** * Checks whether the given URL string begins with a protocol (http://, * ftp://, etc.) If it does, the string is returned unchanged. If it does * not, full URL is returned and is constructed as parentUrl "/" url. * * @param url input URL string in absolute or relative form * @param parentUrl base URL to use if the given URL is in relative form * @return an absolute URL//from ww w . j av a2s . c om */ public static URI relToAbs(String url, URI parentUrl) throws URISyntaxException { if (!StringUtils.hasLength(url)) { throw new URISyntaxException(url, "The input url was empty!"); } URI parent2 = new URI(parentUrl.getScheme(), parentUrl.getUserInfo(), parentUrl.getAuthority(), parentUrl.getPort(), parentUrl.getPath() + "/", // Parent URL path must end with "/" for // this to work. resolve() removes any // duplicates. parentUrl.getQuery(), parentUrl.getFragment()); return parent2.resolve(url.trim()); }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Remove the query part from URI./* ww w. ja v a 2 s . c o m*/ * * @param uri * @return URI after remove the query part. */ public static URI removeQueryPart(URI uri) { try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); } catch (URISyntaxException e) { Logger.error("Remove query part from uri failed.", e); return uri; } }
From source file:org.soyatec.windowsazure.authenticate.HttpRequestAccessor.java
/** * Given the host suffix part, service name and account name, this method * constructs the account Uri// w w w . j a v a2s . c o m * * @param hostSuffix * @param accountName * @return URI */ private static URI constructHostStyleAccountUri(URI hostSuffix, String accountName) { URI serviceUri = hostSuffix; String hostString = hostSuffix.toString(); if (!hostString.startsWith(HttpHost.DEFAULT_SCHEME_NAME)) { hostString = HttpHost.DEFAULT_SCHEME_NAME + "://" + hostString; serviceUri = URI.create(hostString); } // Example: // Input: serviceEndpoint="http://blob.windows.net/", // accountName="youraccount" // Output: accountUri="http://youraccount.blob.windows.net/" // serviceUri in our example would be "http://blob.windows.net/" String accountUriString = null; if (serviceUri.getPort() == -1) { accountUriString = MessageFormat.format("{0}{1}{2}.{3}/", Utilities.isNullOrEmpty(serviceUri.getScheme()) ? HttpHost.DEFAULT_SCHEME_NAME : serviceUri.getScheme(), SCHEME_DELIMITER, accountName, serviceUri.getHost()); } else { accountUriString = MessageFormat.format("{0}{1}{2}.{3}:{4}/", Utilities.isNullOrEmpty(serviceUri.getScheme()) ? HttpHost.DEFAULT_SCHEME_NAME : serviceUri.getScheme(), SCHEME_DELIMITER, accountName, serviceUri.getHost(), serviceUri.getPort()); } return URI.create(accountUriString); }