Refine search
public java.net.URL toJavaURL() { try { return new java.net.URL(toString()); } catch (MalformedURLException e) { throw new IllegalStateException(e.getMessage(), e); } }
public void fillStreamFromHttpFile(Uri uri) { try { URL url = new URL(uri.getPath()); url.openConnection(); inStream = new BufferedInputStream(url.openStream()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public String getGID(URL url) throws MalformedURLException { Matcher m = p.matcher(url.toExternalForm()); if (m.matches()) { return m.group(1); } throw new MalformedURLException("Expected luscious.net URL format: " + "luscious.net/albums/albumname \n members.luscious.net/albums/albumname - got " + url + " instead."); }
/** * Create a new {@code UrlResource} based on a URI specification. * <p>The given parts will automatically get encoded if necessary. * @param protocol the URL protocol to use (e.g. "jar" or "file" - without colon); * also known as "scheme" * @param location the location (e.g. the file path within that protocol); * also known as "scheme-specific part" * @param fragment the fragment within that location (e.g. anchor on an HTML page, * as following after a "#" separator) * @throws MalformedURLException if the given URL specification is not valid * @see java.net.URI#URI(String, String, String) */ public UrlResource(String protocol, String location, @Nullable String fragment) throws MalformedURLException { try { this.uri = new URI(protocol, location, fragment); this.url = this.uri.toURL(); this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString()); } catch (URISyntaxException ex) { MalformedURLException exToThrow = new MalformedURLException(ex.getMessage()); exToThrow.initCause(ex); throw exToThrow; } }
@Override public void connect() throws IOException { if (this.parsed) { return; } if (this.uri == null) { throw new IOException(); } Matcher matcher = pattern.matcher(this.uri.getSchemeSpecificPart()); if (matcher.matches()) { this.contentType = matcher.group("mimeType"); if (contentType == null) { this.contentType = "application/data"; } if (matcher.group("base64") == null) { // Support Urlencode but not decode here because already decoded by URI class. this.data = matcher.group("data").getBytes(); } else { this.data = Base64.getDecoder().decode(matcher.group("data")); } } else { throw new MalformedURLException(); } parsed = true; }
StringBuilder url = new StringBuilder(request.getEndpoint().toString()); url.append(urlPath); return new URL(url.toString()); } catch (MalformedURLException e) { throw new SdkClientException( "Unable to convert request to well formed URL: " + e.getMessage(), e);
static public URL makeURL( URL parent, String urlString) throws MalformedURLException { if (installed) return new URL( parent, urlString); // install failed, use alternate form of URL constructor try { URI uri = new URI( urlString); URLStreamHandler h = (URLStreamHandler) hash.get( uri.getScheme().toLowerCase());; return new URL( parent, urlString, h); } catch (URISyntaxException e) { throw new MalformedURLException(e.getMessage()); } // return new URL( url.getScheme(), url.getHost(), url.getPort(), url.getFile(), h); }
public RemoteUrl(String url, List<String> serverList) { this.url = url; this.serverList = serverList; for (String server : serverList) { try { if (!server.startsWith("http://")) { if (server.startsWith("https://")) { } else { server = "http://" + server; } } urls.add(new URL(server + url)); } catch (MalformedURLException e) { LOGGER.error(e.toString()); } } }
String file = url.getFile(); if ( ! entry.startsWith( "/" ) ) { entry = "/" + entry; final String protocol = url.getProtocol(); jarUrl = new URL( file ); if ( "file".equals( jarUrl.getProtocol() ) ) { if ( file.indexOf( ' ' ) != -1 ) { jarUrl = new File( jarUrl.getFile() ).toURI().toURL(); jarUrl = new File(file).toURI().toURL(); "Unable to determine JAR Url from " + url + ". Cause: " + e.getMessage() );
private URL getEmbeddedJarUrl(final String embeddedJarPath) throws MalformedURLException { final URL embeddedJarUrl; try { embeddedJarUrl = new URL(this.oneNestedJarUrlBase, embeddedJarPath); } catch (MalformedURLException ex) { // TODO: Notify this to reporters as far as possible. System.err.println("Failed to load entry in embedded JAR: " + embeddedJarPath); ex.printStackTrace(); throw ex; } return embeddedJarUrl; }
private String getResourceUrlString(String resource) { URL url = null; try { if (resource.startsWith("http") || resource.startsWith("file")) { url = new URL(resource); } else { url = new File(resource).toURI().toURL(); } } catch (MalformedURLException ex) { logger.log(Level.WARNING, "Failed to determine URL of " + resource + ". Reason: " + ex.getMessage()); logger.log(Level.FINER, "Details: ", ex); } return url != null ? url.toString() : null; }
private URL calculateImageUrl() { if (typ == ImportTyp.DIR) { try { return imageFiles[currentPos - 1].toURI().toURL(); } catch (MalformedURLException e1) { } } URL startUrl = null; if (typ == ImportTyp.SHAPE) startUrl = shapeFileUrl; if (typ == ImportTyp.CSV) startUrl = csvFileURL; String path = startUrl.getPath(); int index = path.lastIndexOf('/'); String imagePath = null; if (index == -1) { imagePath = currentLocation; } else { imagePath = path.substring(0, index + 1) + currentLocation; } try { return new URL( startUrl.getProtocol(), startUrl.getHost(), startUrl.getPort(), imagePath); } catch (MalformedURLException e) { logError(e, e.getMessage()); return null; } }
private static URI validateIssuer(String issuer) throws URISyntaxException { try { new URL(issuer); } catch (MalformedURLException x) { throw new URISyntaxException(issuer, x.getMessage()); } return new URI(issuer); }
try url = new URI(taintedURL).normalize().toURL(); throw new MalformedURLException(e.getMessage()); final String path = url.getPath().replace("/$", ""); final SortedMap<String, String> params = createParameterMap(url.getQuery()); final int port = url.getPort(); final String queryString;
public PreLoad(Context context, String url) { try { this.url = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } uri = URI.create(url); fileUtils = ProxyFileUtils.getInstance(context, uri, false); }
gazetteerURL = new URL(gazetteer.toString() + "&placename=" + place); } catch (MalformedURLException e) { results.error(feature, e.toString()); (HttpURLConnection) gazetteerURL.openConnection();
additionalClasspath.add(new URL(modulePathString)); } catch (MalformedURLException mue) { isUrl = false; additionalClasspath.add(modulePath.toURI().toURL()); LOGGER.warn("Recursive directories are not supported, skipping " + classpathResource.getAbsolutePath()); } else { additionalClasspath.add(classpathResource.toURI().toURL()); throw new MalformedURLException("Path specified does not exist");
public static URL getEncodedURL(String urlStr) throws MalformedURLException { URL url = new URL(urlStr); String scheme = String.valueOf(url.getProtocol()).toLowerCase(); if (scheme.equals("http") || scheme.equals("https")) { try { return new URL(url.toURI().toASCIIString()); } catch (URISyntaxException e) { MalformedURLException malformedURLException = new MalformedURLException(e.getMessage()); malformedURLException.initCause(e); throw malformedURLException; } } return url; }
public String getHref() { String relativeLocation = getAttributeWithNoDefault( "href" ); if (relativeLocation.indexOf( ':' ) > 0 || relativeLocation.equals( "#" )) { return relativeLocation; } else { try { return new URL( ((HTMLDocumentImpl) getOwnerDocument()).getBaseUrl(), relativeLocation ).toExternalForm(); } catch (MalformedURLException e) { return e.toString(); } } }