List of usage examples for java.net URL getProtocol
public String getProtocol()
From source file:de.yaio.commons.net.NetFirewall.java
/** * checks if url is allowed//w w w. java 2s.c om * @param url url to check (check protocoll, hostname and ip) * @return true/false if it is allowed * @throws MalformedURLException parsing the url * @throws UnknownHostException parsing the url */ public boolean isAllowed(final URL url) throws UnknownHostException, MalformedURLException { // check protocol if (!isInProtocolList(url.getProtocol())) { return false; } // check inetAddr InetAddress inetAddr = NetUtils.parseAddress(url.getHost()); String hostName = inetAddr.getHostName(); String ip = inetAddr.getHostAddress(); if (isInHostBlackList(hostName) || isInIPBlackList(ip)) { // blacklisted: but check for override by whitelist if (isInHostWhiteList(hostName) || isInIPWhiteList(ip)) { return true; } // blacklisted return false; } return true; }
From source file:net.ontopia.utils.ResourcesDirectoryReader.java
private void findResources() { resources = new ArrayList<>(); for (URL directoryURL : getResourceDirectories()) { String protocol = directoryURL.getProtocol(); if ("file".equals(protocol)) { findResourcesFromFile(directoryURL); } else if ("jar".equals(protocol)) { findResourcesFromJar(directoryURL); } // other protocols not yet supported }/*from w ww . ja va 2s. c o m*/ }
From source file:UnpackedJarFile.java
public static String readAll(URL url) throws IOException { Reader reader = null;//from w w w.j a v a 2 s . co m JarFile jarFile = null; try { if (url.getProtocol().equalsIgnoreCase("jar")) { // url.openStream() locks the jar file and does not release the lock even after the stream is closed. // This problem is avoided by using JarFile APIs. File file = new File(url.getFile().substring(5, url.getFile().indexOf("!/"))); String path = url.getFile().substring(url.getFile().indexOf("!/") + 2); jarFile = new JarFile(file); JarEntry jarEntry = jarFile.getJarEntry(path); if (jarEntry != null) { reader = new InputStreamReader(jarFile.getInputStream(jarEntry)); } else { throw new FileNotFoundException("JarEntry " + path + " not found in " + file); } } else { reader = new InputStreamReader(url.openStream()); } char[] buffer = new char[4000]; StringBuffer out = new StringBuffer(); for (int count = reader.read(buffer); count >= 0; count = reader.read(buffer)) { out.append(buffer, 0, count); } return out.toString(); } finally { close(reader); close(jarFile); } }
From source file:com.oakhole.Generate.java
/** * ??@Entity/*from w w w . ja va 2s.com*/ * @param packageToScan * @return * @throws java.io.IOException */ private Set<Class<?>> autoScan(String packageToScan) throws IOException { Set<Class<?>> entities = Sets.newConcurrentHashSet(); Enumeration<URL> dirs = Thread.currentThread().getContextClassLoader() .getResources(packageToScan.replace('.', '/')); while (dirs.hasMoreElements()) { URL url = dirs.nextElement(); // ?@Entity if ("file".endsWith(url.getProtocol())) { String filePath = URLDecoder.decode(url.getFile(), "utf-8"); fetchEntities(packageToScan, filePath, entities); } } return entities; }
From source file:com.esri.gpt.control.webharvest.client.waf.FtpClientRequest.java
/** * Creates instance of the request./*from w w w .j a va 2 s.c om*/ * @param url url * @param cp credential provider */ public FtpClientRequest(URL url, CredentialProvider cp) { this.protocol = Val.chkStr(url.getProtocol()); this.host = Val.chkStr(url.getHost()); this.port = url.getPort() >= 0 ? url.getPort() : 21; this.root = Val.chkStr(url.getPath()).replaceAll("/$", ""); this.cp = cp; }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.InfiniteFile.java
public URI getURI() throws MalformedURLException, URISyntaxException { // (note this doesn't work nicely with spaces) if (null != _smbFile) { URL url = _smbFile.getURL(); return new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); // (this odd construct is needed to handle spaces in paths) } else {//w w w.j av a 2 s . c om return _localFile.toURI(); // (confirmed spaces in paths works here) } }
From source file:Main.java
/** * Checks, whether the URL uses a file based protocol. * * @param url the url./* www . j a v a 2 s .c om*/ * @return true, if the url is file based. */ private boolean isFileStyleProtocol(final URL url) { if (url.getProtocol().equals("http")) { return true; } if (url.getProtocol().equals("https")) { return true; } if (url.getProtocol().equals("ftp")) { return true; } if (url.getProtocol().equals("file")) { return true; } if (url.getProtocol().equals("jar")) { return true; } return false; }
From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java
public void registerClickV(String uri) { String host = "http://lit-taiga-5566.herokuapp.com/"; String query = null, path = null; String telId = getTelNumber() == null ? getMacAddress() : getTelNumber(); try {/* w ww.jav a 2s .c om*/ URL url = new URL(uri.replaceAll("clickv://", host)); query = url.getQuery(); path = url.getProtocol() + "://" + url.getHost() + "/" + url.getPath(); } catch (MalformedURLException e) { e.printStackTrace(); } Toast.makeText(getActivity(), "??? :: " + query, Toast.LENGTH_SHORT).show(); try { new ServerConnenctionTask().execute(path, query, telId); Toast.makeText(getActivity(), "" + uri, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "?." + uri, Toast.LENGTH_SHORT).show(); } }
From source file:com.frostwire.ImageCache.java
public BufferedImage getImage(URL url, OnLoadedListener listener) { if (isCached(url)) { return loadFromCache(url, listener); } else if (!url.getProtocol().equals("http")) { return loadFromResource(url, listener); } else {/* w w w . ja v a2 s . c om*/ loadFromUrl(url, listener); return null; } }
From source file:v7cr.V7CR.java
Link getFile(BSONBackedObject file) { String fn = file.getStringField("filename"); String sha = file.getStringField("sha"); if (fn == null || sha == null) return null; URL url = getURL(); return new Link(fn, new ExternalResource( url.getProtocol() + "://" + url.getHost() + ":8088/upload/v7cr?filename=" + fn + "&sha=" + sha)); }