List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:com.garyclayburg.CsvParseFlapDoodleTest.java
private int importOneCSV(String csvFileName) throws URISyntaxException { URL testUsersCsv = this.getClass().getClassLoader().getResource(csvFileName); assert testUsersCsv != null; File csvInputFile = new File(testUsersCsv.toURI()); return csvImporter.importFile(csvInputFile); }
From source file:cz.incad.kramerius.audio.servlets.ServletAudioHttpRequestForwarder.java
public Void forwardHeadRequest(URL url) throws IOException, URISyntaxException { LOGGER.log(Level.INFO, "forwarding {0}", url); HttpHead repositoryRequest = new HttpHead(url.toURI()); forwardSelectedRequestHeaders(clientToProxyRequest, repositoryRequest); //printRepositoryRequestHeaders(repositoryRequest); HttpResponse repositoryResponse = httpClient.execute(repositoryRequest); //printRepositoryResponseHeaders(repositoryResponse); forwardSelectedResponseHeaders(repositoryResponse, proxyToClientResponse); forwardResponseCode(repositoryResponse, proxyToClientResponse); return null;/* w w w .j av a2 s . com*/ }
From source file:com.adaptris.core.fs.FsHelperTest.java
@Test public void testCreateFileRefWithBackSlash() throws Exception { URL url = FsHelper.createUrlFromString("file:///c:\\home\\fred", true); assertEquals("fred", new File(url.toURI()).getName()); }
From source file:eu.peppol.jdbc.OxalisDataSourceFactoryDbcpImplTest.java
private ConnectionFactory createConnectionFactory(boolean profileSql) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException { String jdbcDriverClassPath = globalConfiguration.getJdbcDriverClassPath(); URL url = new URL(jdbcDriverClassPath); try {//from www . ja v a 2s . c om File file = new File(url.toURI()); if (!file.exists()) { throw new IllegalStateException("JDBC driver class path not found: " + file); } } catch (URISyntaxException e) { throw new IllegalStateException( "Unable to convert URL " + url.toExternalForm() + " into URI: " + e.getMessage(), e); } URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread().getContextClassLoader()); String jdbcDriverClassName = globalConfiguration.getJdbcDriverClassName(); String connectURI = globalConfiguration.getJdbcConnectionURI(); // + "?initialTimeout=2"; String userName = globalConfiguration.getJdbcUsername(); String password = globalConfiguration.getJdbcPassword(); Class<?> aClass = null; try { aClass = Class.forName(jdbcDriverClassName, true, urlClassLoader); } catch (ClassNotFoundException e) { throw new IllegalStateException("Unable to locate class " + jdbcDriverClassName + " in class path '" + jdbcDriverClassPath + "'"); } Driver driver = (Driver) aClass.newInstance(); assertTrue(driver.acceptsURL(connectURI)); Properties properties = new Properties(); properties.put("user", userName); properties.put("password", password); if (profileSql) { properties.put("profileSQL", "true"); // MySQL debug option } return new DriverConnectionFactory(driver, connectURI, properties); }
From source file:com.omertron.slackbot.utils.HttpTools.java
/** * POST content to the URL with the specified body * * @param url URL to use in the request/*from www . j a v a2 s . c o m*/ * @param jsonBody Body to use in the request * @return String content * @throws ApiException */ public String postRequest(final URL url, final String jsonBody) throws ApiException { try { HttpPost httpPost = new HttpPost(url.toURI()); httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON); httpPost.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); StringEntity params = new StringEntity(jsonBody, ContentType.APPLICATION_JSON); httpPost.setEntity(params); return validateResponse(DigestedResponseReader.postContent(httpClient, httpPost, CHARSET), url); } catch (URISyntaxException | IOException ex) { throw new ApiException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } }
From source file:cz.incad.Kramerius.audio.AudioHttpRequestForwarder.java
public void forwardHeadRequest(URL url) throws IOException, URISyntaxException { LOGGER.log(Level.INFO, "forwarding {0}", url); HttpHead repositoryRequest = new HttpHead(url.toURI()); forwardSelectedRequestHeaders(clientToProxyRequest, repositoryRequest); //printRepositoryRequestHeaders(repositoryRequest); HttpResponse repositoryResponse = httpClient.execute(repositoryRequest); //printRepositoryResponseHeaders(repositoryResponse); forwardSelectedResponseHeaders(repositoryResponse, proxyToClientResponse); forwardResponseCode(repositoryResponse, proxyToClientResponse); }
From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java
/** * Generate a map of zip entries that have to be considered when zipping * pNode. This method calls itself recursively to traverse through * sub-directories. The provided map finally contains all files and folders * that have to be in the zip file. For files, the value of a map entry is * defined, for (empty) folders the value is null. The returned value is the * summed size of all files and can be used to decide whether or not the zip * should be finally created./*w w w .j av a2 s .c o m*/ * * @param pNode The node that should be handled. Filenodes will be directly * added to pMap, CollectionNodes will be traversed. * @param pPath The current part that is accessed. * @param pMap The map of resulting entries. * * @return The overall amount of data. */ private static long generateZipEntries(IDataOrganizationNode pNode, String pPath, Map<String, File> pMap) { long size = 0; String basePath = (pPath == null) ? pNode.getName() : pPath + "/" + pNode.getName(); if (pNode instanceof ICollectionNode) { ICollectionNode node = (ICollectionNode) pNode; if (!node.getChildren().isEmpty()) { for (IDataOrganizationNode childNode : node.getChildren()) { size += generateZipEntries(childNode, basePath, pMap); } } else { //empty node pMap.put(basePath, null); } } else if (pNode instanceof IFileNode) { IFileNode node = (IFileNode) pNode; File f = null; String lfn = node.getLogicalFileName().asString(); try { URL lfnUrl = new URL(lfn); if ("file".equals(lfnUrl.getProtocol())) { f = new File(lfnUrl.toURI()); size += f.length(); } else { throw new MalformedURLException( "Protocol " + lfnUrl.getProtocol() + " currently not supported."); } pMap.put(basePath, f); } catch (MalformedURLException | URISyntaxException ex) { LOGGER.warn("Unsupported LFN " + lfn + ". Only LFNs refering to locally accessible files are supported."); } } else { throw new IllegalArgumentException("Argument " + pNode + " is not a supported argument. Only nodes of type ICollectionNode or IFileNode are supported."); } return size; }
From source file:org.opendaylight.sfc.sbrest.json.SffExporterTest.java
private String gatherServiceFunctionForwardersJsonStringFromFile(String testFileName) { String jsonString = null;/*from w w w . j a va 2s. co m*/ try { URL fileURL = getClass().getResource(testFileName); jsonString = TestUtil.readFile(fileURL.toURI(), StandardCharsets.UTF_8); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } for (SffTestValues sffTestValue : SffTestValues.values()) { jsonString = jsonString != null ? jsonString.replaceAll("\\b" + sffTestValue.name() + "\\b", sffTestValue.getValue()) : null; } return jsonString; }
From source file:com.constellio.app.modules.es.connectors.http.fetcher.config.BasicUrlNormalizer.java
@Override public String normalize(String url) throws MalformedURLException, URISyntaxException { String trimmedUrl = StringUtils.trim(url); String noFragmentUrl = StringUtils.substringBefore(trimmedUrl, "#"); if (StringUtils.isEmpty(new URL(noFragmentUrl).getFile())) { noFragmentUrl = noFragmentUrl + "/"; }/*from www.j a va 2 s .com*/ URL normalizedUrl = new URL(noFragmentUrl); String lowerCaseHost = StringUtils.lowerCase(normalizedUrl.getHost()); normalizedUrl = new URL(normalizedUrl.getProtocol(), lowerCaseHost, normalizedUrl.getPort(), normalizedUrl.getFile()); return normalizedUrl.toURI().normalize().toString(); }
From source file:fr.free.movierenamer.scrapper.impl.FanartTvScrapper.java
@Override protected final List<ImageInfo> fetchImagesInfo(M media) throws Exception { switch (media.getMediaId().getIdType()) { case IMDB:/* ww w . j a v a 2 s . co m*/ break; case TMDB: break; default: throw new UnsupportedOperationException( media.getMediaId().getIdType() + " is not supported by " + getName() + " image scrapper"); } URL searchUrl = new URL("http", host, "/" + getTypeName() + "/" + apikey + "/" + media.getMediaId() + "/");// Last slash is required JSONObject json = URIRequest.getJsonDocument(searchUrl.toURI()); JSONObject jmedia = JSONUtils.selectFirstObject(json); List<ImageInfo> imagesInfos = new ArrayList<ImageInfo>(); if (jmedia == null) { return imagesInfos; } for (String tag : getTags()) { List<JSONObject> images = JSONUtils.selectList(tag, jmedia); if (images == null) { continue; } for (JSONObject image : images) { Map<ImageInfo.ImageProperty, String> imageFields = new EnumMap<ImageInfo.ImageProperty, String>( ImageInfo.ImageProperty.class); int id = JSONUtils.selectInteger("id", image); imageFields.put(ImageInfo.ImageProperty.url, JSONUtils.selectString("url", image)); imageFields.put(ImageInfo.ImageProperty.language, JSONUtils.selectString("lang", image)); ImageInfo.ImageCategoryProperty category = getCategory(tag); imagesInfos.add(new ImageInfo(id, imageFields, category)); } } return imagesInfos; }