List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl.java
private static URI toURI(URL url) throws RuntimeException { try {/*from w ww. j a va2 s. c o m*/ return url.toURI(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.freedomotic.plugin.purl.Purl.java
private static String readPage(URL url) throws Exception { DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url.toURI()); HttpResponse response = client.execute(request); Reader reader = null;//from w w w . j av a 2s .co m try { reader = new InputStreamReader(response.getEntity().getContent()); StringBuilder sb = new StringBuilder(); int read; char[] cbuf = new char[1024]; while ((read = reader.read(cbuf)) != -1) { sb.append(cbuf, 0, read); } return sb.toString(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { //do nothing } } } }
From source file:com.wealdtech.configuration.ConfigurationSource.java
private static BufferedReader getReader(final String filename) { final URL fileurl = ResourceLoader.getResource(filename); if (fileurl == null) { return null; }/*from w ww . jav a2 s . co m*/ try { return Files.newBufferedReader(Paths.get(fileurl.toURI()), Charset.defaultCharset()); } catch (IOException ioe) { LOGGER.warn("IO exception with {}: {}", fileurl, ioe); throw new DataError("Failed to access configuration file \"" + filename + "\"", ioe); } catch (URISyntaxException use) { LOGGER.warn("URI issue with {}: {}", fileurl, use); throw new DataError("Failed to access configuration file \"" + filename + "\"", use); } }
From source file:org.glowroot.common2.repo.util.Compilations.java
private static File getJarFile(String className) throws Exception { CodeSource codeSource = Class.forName(className).getProtectionDomain().getCodeSource(); if (codeSource == null) { throw new IllegalStateException("Code source is null for class: " + className); }/*from w w w .ja va 2 s .c om*/ URL location = codeSource.getLocation(); return new File(location.toURI()); }
From source file:com.ilscipio.scipio.common.FileListener.java
/** * Start a file listener (WatchService) and run a service of a given name and writes the result to the database * Can be used to implements EECAs to auto-update information based on file changes **///from w w w . ja v a2s . c o m public static void startFileListener(String name, String location) { try { if (UtilValidate.isNotEmpty(name) && UtilValidate.isNotEmpty(location)) { if (getThreadByName(name) != null) { Debug.logInfo("Filelistener " + name + " already started. Skipping...", module); } else { URL resLocation = UtilURL.fromResource(location); Path folderLocation = Paths.get(resLocation.toURI()); if (folderLocation == null) { throw new UnsupportedOperationException("Directory not found"); } final WatchService folderWatcher = folderLocation.getFileSystem().newWatchService(); // register all subfolders Files.walkFileTree(folderLocation, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { dir.register(folderWatcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); return FileVisitResult.CONTINUE; } }); // start the file watcher thread below ScipioWatchQueueReader fileListener = new ScipioWatchQueueReader(folderWatcher, name, location); ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor( FILE_LISTENER_THREAD_GROUP, "filelistener-startup", Runtime.getRuntime().availableProcessors(), 0, true); try { executor.submit(fileListener, name); } finally { executor.shutdown(); } Debug.logInfo("Starting FileListener thread for " + name, module); } } } catch (Exception e) { Debug.logError("Could not start FileListener " + name + " for " + location + "\n" + e, module); } }
From source file:com.sunchenbin.store.feilong.core.net.URLUtil.java
/** * {@link URL}? {@link URI}.//from w w w .j av a 2s.c o m * * @param url * the url * @return the uri * @see "org.springframework.util.ResourceUtils#toURI(URL)" * @since 1.2.2 */ public static URI toURI(URL url) { try { return url.toURI(); } catch (URISyntaxException e) { throw new URIParseException(e); } }
From source file:com.meltmedia.rodimus.DocumentTransformationTest.java
@Parameters public static Collection<Object[]> parameters() throws URISyntaxException { List<Object[]> fileComparisons = new ArrayList<Object[]>(); URL testRoot = DocumentTransformationTest.class.getClassLoader().getResource("testCases"); File testCaseDir = new File(testRoot.toURI()); for (File docFile : testCaseDir.listFiles(new FileFilter() { @Override/*from www . ja v a 2 s . c o m*/ public boolean accept(File pathname) { return pathname.getName().matches(".*\\.docx"); } })) { File expectedDir = new File(testCaseDir, docFile.getName().replaceFirst("\\A(.*)\\.docx\\Z", "$1")); fileComparisons.add(new Object[] { docFile, expectedDir }); } return fileComparisons; }
From source file:com.gemstone.gemfire.internal.logging.log4j.custom.CustomConfiguration.java
public static File createConfigFileIn(final File targetFolder) throws IOException, URISyntaxException { URL resource = openConfigResource(); File targetFile = new File(targetFolder, CONFIG_FILE_NAME); IOUtils.copy(resource.openStream(), new FileOutputStream(targetFile)); assertThat(targetFile).hasSameContentAs(new File(resource.toURI())); return targetFile; }
From source file:com.brightcove.test.upload.BatchIntegrationTest.java
private static File findFileInClasspath(String pFileName) throws URISyntaxException { URL url = ClassLoader.getSystemResource(pFileName); if (url == null) { return null; }/*from w ww .j av a2 s . c om*/ return new File(url.toURI()); }
From source file:org.edgexfoundry.EdgeXConfigWatcherApplication.java
public static void registerWatcher(List<CatalogService> services, String notificationPath) { try (CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();) { httpClient.start();// www. j a v a 2 s. com for (CatalogService service : services) { LOGGER.info("Attempting registration of {} to: {}", service.getServiceName(), notificationPath); URL serviceNotificationURL = new URL(notificationProtocol, service.getAddress(), service.getServicePort(), notificationPath); HttpGet request = new HttpGet(serviceNotificationURL.toURI()); Future<HttpResponse> future = httpClient.execute(request, null); future.get(); LOGGER.info("Registered {} @ {}", service.getServiceName(), notificationPath); } } catch (URISyntaxException e) { LOGGER.error("URI Syntax issue: " + e.getMessage()); } catch (InterruptedException e) { LOGGER.error("Interrupted process: " + e.getMessage()); Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOGGER.error("Execution problem: " + e.getMessage()); } catch (IOException e) { LOGGER.error("IO problem: " + e.getMessage()); } }