List of usage examples for java.net URL getFile
public String getFile()
From source file:com.nridge.core.base.std.WebUtl.java
public static String urlExtractFileName(String aURL) { if (StringUtils.isNotEmpty(aURL)) { try {// w ww . j a va 2 s . co m URL webURL = new URL(aURL); String fileName = webURL.getFile(); if (fileName.indexOf('/') == -1) return fileName; } catch (MalformedURLException ignored) { } int offset = aURL.lastIndexOf('/'); if (offset != -1) return aURL.substring(offset + 1); } return aURL; }
From source file:com.adaptc.mws.plugins.testing.support.PluginsResourceUtils.java
/** * Checks whether the file referenced by the given url is a plugin class * * @param url The URL instance//from w w w . j a v a 2 s . c o m * @return True if it is a plugin class */ public static boolean isPluginClass(URL url) { if (url == null) return false; return PLUGIN_PATH_PATTERN.matcher(url.getFile()).find(); }
From source file:com.bsb.cms.commons.utils.URLUtils.java
public static String getTemplatePath() { if (templateDir == null) { URL url = new Object() { }.getClass().getResource("/template"); String classpath = (new File(url.getFile())).getParentFile().getAbsolutePath(); templateDir = classpath + "/template/"; }/* w w w . j a v a 2 s. c o m*/ return templateDir; }
From source file:com.u2apple.tool.filter.ExcludeFilter.java
private static void loadRules() { URL url = DevicePatternFilter.class.getResource(RULES_CONF); File file = new File(url.getFile()); JAXBContext jaxbContext;/* ww w . ja va2s. c o m*/ try { jaxbContext = JAXBContext.newInstance(Rules.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); rules = (Rules) unmarshaller.unmarshal(file); } catch (JAXBException ex) { logger.error("Fail to parse exclude-filter.xml as {}", ex); } }
From source file:com.adaptc.mws.plugins.testing.support.PluginsResourceUtils.java
/** * Checks whether the file referenced by the given url is a translator class * * @param url The URL instance//from w ww. j a va 2 s . c o m * @return True if it is a translator class */ public static boolean isTranslatorClass(URL url) { if (url == null) return false; return TRANSLATOR_PATH_PATTERN.matcher(url.getFile()).find(); }
From source file:Main.java
public static File getFileFromCacheOrURL(File cacheDir, URL url) throws IOException { Log.i(TAG, "getFileFromCacheOrURL(): url = " + url.toExternalForm()); String filename = url.getFile(); int lastSlashPos = filename.lastIndexOf('/'); String fileNameNoPath = new String(lastSlashPos == -1 ? filename : filename.substring(lastSlashPos + 1)); File file = new File(cacheDir, fileNameNoPath); if (file.exists()) { if (file.length() > 0) { Log.i(TAG, "File exists in cache as: " + file.getAbsolutePath()); return file; } else {/*from w w w . j av a2s . com*/ Log.i(TAG, "Deleting zero length file " + file.getAbsolutePath()); file.delete(); } } Log.i(TAG, "File " + file.getAbsolutePath() + " does not exists."); URLConnection ucon = url.openConnection(); ucon.setReadTimeout(5000); ucon.setConnectTimeout(30000); InputStream is = ucon.getInputStream(); BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5); FileOutputStream outStream = new FileOutputStream(file); byte[] buff = new byte[5 * 1024]; // Read bytes (and store them) until there is nothing more to read(-1) int len; while ((len = inStream.read(buff)) != -1) { outStream.write(buff, 0, len); } // Clean up outStream.flush(); outStream.close(); inStream.close(); return file; }
From source file:com.bfd.harpc.common.configure.ResourceUtils.java
private static URL[] load3(String locationPattern) throws MalformedURLException { // a single resource with the given name URL url = new URL(locationPattern); return new File(url.getFile()).exists() ? new URL[] { url } : null; }
From source file:com.bsb.cms.commons.utils.URLUtils.java
/** * ?class path//from w w w . j ava 2s. c om * @return */ public static String getCLassPath() { String classpath = null; try { URL url = new Object() { }.getClass().getResource("/properties/log4j.properties"); classpath = (new File(url.getFile())).getParentFile().getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); } return classpath; }
From source file:eu.project.ttc.utils.TermSuiteUtils.java
/** * /*w ww.ja v a2s . com*/ */ public static void listClasspath() { ClassLoader cl = ClassLoader.getSystemClassLoader(); URL[] urls = ((URLClassLoader) cl).getURLs(); for (URL url : urls) { System.out.println(url.getFile()); } }
From source file:org.shept.util.JarUtils.java
/** * Extract the URL-String for the internal resource path from the given URL * (which points to a resource in a jar file). * This methods complements {@link ResourceUtils#extractJarFileURL(URL)} * //w w w . j a v a 2s.c om * @return empty String if no such internal jar path is found * @param jarPathUrl */ public static String jarPathInternal(URL jarPathUrl) { String urlFile = jarPathUrl.getFile(); int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR); if (separatorIndex != -1) { separatorIndex = separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length(); return urlFile.substring(separatorIndex, urlFile.length()); } return ""; }