List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:io.cloudslang.lang.compiler.CompileOperationTest.java
@Test public void testCompileOperationBasic() throws Exception { URL resource = getClass().getResource("/test_op.sl"); ExecutionPlan executionPlan = compiler.compile(SlangSource.fromFile(resource.toURI()), null) .getExecutionPlan();//from www. j a va2s . c o m Assert.assertNotNull("execution plan is null", executionPlan); Assert.assertEquals("there is a different number of steps than expected", 3, executionPlan.getSteps().size()); }
From source file:com.garyclayburg.attributes.AttributeServiceConnectedUserTest.java
@Before public void setUp() throws IOException, URISyntaxException { log.debug("Running test setUp: " + testName.getMethodName()); URL groovyURL = this.getClass().getClassLoader().getResource("groovies/emptyscript.groovy"); assert groovyURL != null; String scriptRoot = new File(groovyURL.toURI()).getParentFile().getPath(); scriptRunner.setRoot(new String[] { scriptRoot }); attributeService.setScriptRunner(scriptRunner); }
From source file:br.com.uol.runas.classloader.JarClassLoader.java
private void addUrlsFromDir(URL url) throws IOException, URISyntaxException { addURL(url);/*from w w w . j a v a 2 s . com*/ Files.walkFileTree(Paths.get(url.toURI()), new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { addURL(dir.toUri().toURL()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { addURL(file.toUri().toURL()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); }
From source file:org.castor.jaxb.resolver.JAXBPackageResolverCommand.java
/** * The one and only purpose resolver commands are good for ;-) . It can be * called with className and clazz set, so the command decides which suites * it best or at least one of the two arguments set. * /*from w w w . j a v a 2s.c om*/ * @param packageName * the name of the package to resolve * @param properties * the Properties to be used at resolve * * @return a Map of className and XMLClassDescriptor * * @throws ResolverException * in case that resolving fails fatally */ public Map<String, XMLClassDescriptor> resolve(final String packageName, final Map properties) throws ResolverException { String className; String fileName; String dirName; String packageToken; Class clazz; Enumeration<URL> resources; Map<String, XMLClassDescriptor> result = new HashMap<String, XMLClassDescriptor>(); if ((packageName == null) || (packageName.length() == 0)) { if (LOG.isDebugEnabled()) { LOG.debug("Package to load descriptors from is null or empty - nothing done."); } return result; } try { StringTokenizer packages = new StringTokenizer(packageName, ":"); ClassLoader classLoader = getClass().getClassLoader(); while (packages.hasMoreTokens()) { packageToken = packages.nextToken(); dirName = packageToken.replace('.', '/'); resources = classLoader.getResources(dirName); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resourceUrl = resources.nextElement(); dirs.add(new File(resourceUrl.toURI())); } for (File dir : dirs) { for (File file : dir.listFiles()) { if (file.getName().endsWith(".class")) { fileName = file.getName(); className = new StringBuffer().append(packageName).append('.') .append(fileName.substring(0, fileName.length() - 6)).toString(); clazz = Class.forName(className); XMLClassDescriptor descriptor = classDescriptorBuilder .buildClassDescriptor(classInfoBuilder.buildClassInfo(clazz), false); result.put(className, descriptor); } } } } return result; } catch (IOException e) { throw new ResolverException("Exception occurred when resolving package: " + packageName, e); } catch (URISyntaxException e) { throw new ResolverException("Exception occurred when resolving package: " + packageName, e); } catch (ClassNotFoundException e) { throw new ResolverException("Exception occurred when resolving package: " + packageName, e); } }
From source file:org.opendaylight.sfc.sbrest.json.SfgExporterTest.java
private String gatherServiceFunctionGroupJsonStringFromFile(String testFileName) { String jsonString = null;/*w w w . j a v a2 s. co m*/ try { URL fileURL = getClass().getResource(testFileName); jsonString = TestUtil.readFile(fileURL.toURI(), StandardCharsets.UTF_8); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } for (SfgTestValues sfgTestValue : SfgTestValues.values()) { if (jsonString != null) { jsonString = jsonString.replaceAll("\\b" + sfgTestValue.name() + "\\b", sfgTestValue.getValue()); } } return jsonString; }
From source file:com.google.appengine.tck.endpoints.support.EndPointClient.java
public String doGet(URL url) throws Exception { return doRequest(new HttpGet(url.toURI())); }
From source file:com.google.appengine.tck.endpoints.support.EndPointClient.java
public String doPut(URL url) throws Exception { return doRequest(new HttpPut(url.toURI())); }
From source file:org.red5.logging.ContextLoggingListener.java
public void contextInitialized(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); String contextName = servletContext.getContextPath().replaceAll("/", ""); if ("".equals(contextName)) { contextName = "root"; }//from w w w. j av a 2 s. c o m System.out.printf("Context init: %s%n", contextName); ConfigurableWebApplicationContext appctx = (ConfigurableWebApplicationContext) servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (appctx != null) { System.out.printf( "ConfigurableWebApplicationContext is not null in ContextLoggingListener for: %s, this indicates a misconfiguration or load order problem%n", contextName); } try { // get the selector ContextSelector selector = Red5LoggerFactory.getContextSelector(); // get the logger context for this servlet / app context by name URL url = servletContext.getResource(String.format("/WEB-INF/classes/logback-%s.xml", contextName)); if (url != null && Files.exists(Paths.get(url.toURI()))) { System.out.printf("Context logger config found: %s%n", url.toURI()); } else { url = servletContext.getResource("/WEB-INF/classes/logback.xml"); if (url != null && Files.exists(Paths.get(url.toURI()))) { System.out.printf("Context logger config found: %s%n", url.toURI()); } } // get the logger context for the servlet context LoggerContext loggerContext = url != null ? ((LoggingContextSelector) selector).getLoggerContext(contextName, url) : selector.getLoggerContext(contextName); // set the logger context for use elsewhere in the servlet context servletContext.setAttribute(Red5LoggerFactory.LOGGER_CONTEXT_ATTRIBUTE, loggerContext); // get the root logger for this context Logger logger = Red5LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME, contextName); logger.info("Starting up context: {}", contextName); } catch (Exception e) { System.err.printf("LoggingContextSelector is not the correct type: %s%n", e.getMessage()); e.printStackTrace(); } }
From source file:com.google.appengine.tck.endpoints.support.EndPointClient.java
public String doPost(URL url) throws Exception { return doRequest(new HttpPost(url.toURI())); }
From source file:com.omertron.bgg.tools.HttpTools.java
/** * Execute a DELETE on the URL/*from w w w. j a v a2s .c om*/ * * @param url URL to use in the request * @return String content * @throws BggException Custom exception containing failure code */ public String deleteRequest(final URL url) throws BggException { try { HttpDelete httpDel = new HttpDelete(url.toURI()); return validateResponse(DigestedResponseReader.deleteContent(httpClient, httpDel, CHARSET), url); } catch (URISyntaxException | IOException ex) { throw new BggException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } }