List of usage examples for java.net URL getPath
public String getPath()
From source file:com.clican.pluto.orm.dynamic.impl.ClassLoaderUtilImpl.java
private void populateJarsFromManifest(Set<String> jars, ClassLoader loader) { BufferedReader reader = null; try {//from w w w .j a v a 2s . co m Enumeration<URL> e = loader.getResources("META-INF/MANIFEST.MF"); while (e.hasMoreElements()) { URL url = e.nextElement(); if (url.getPath().contains(SURE_FIRE_BOOTER_JAR)) { reader = new BufferedReader(new InputStreamReader(url.openStream())); String line = null; StringBuffer content = new StringBuffer(); while ((line = reader.readLine()) != null) { content.append(line.trim()); } String cont = content.toString().replaceAll("Manifest-Version: 1.0Class-Path: ", "") .replaceAll("Main-Class: org.apache.maven.surefire.booter.SurefireBooter", ""); for (String file : cont.split(" ")) { if (file.contains("file")) { jars.add(file.replaceAll("file:", "")); } } break; } } } catch (IOException e) { log.error("", e); } finally { try { if (reader != null) { reader.close(); } } catch (Exception e) { log.error("", e); } } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.miRnaSeqData.MiRnaSeqLoadAnnotationListener.java
@Override protected String getJobPath() throws Exception { URL jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_QPCR_MIRNA_annotation.kjb"); jobUrl = FileLocator.toFileURL(jobUrl); String jobPath = jobUrl.getPath(); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_QPCR_MIRNA_annotation_to_de_gpl_info.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_QPCR_MIRNA_annotation_to_lt.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/run_I2B2_LOAD_MIRNA_ANNOT_DEAPP.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_end_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_start_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_write_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); return jobPath; }
From source file:com.clican.pluto.orm.dynamic.impl.ClassLoaderUtilImpl.java
public Set<String> getRuntimeJars() { Set<String> jars = new HashSet<String>(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (log.isDebugEnabled()) { log.debug("The ContextClassLoader[" + loader + "]"); }/*w ww.j a v a 2 s .c o m*/ populateJarsFromManifest(jars, loader); for (URL url : Launcher.getBootstrapClassPath().getURLs()) { jars.add(url.getPath()); } populateJars(jars, loader); return jars; }
From source file:com.ecyrd.jspwiki.url.DefaultURLConstructor.java
/** * /*from ww w.ja v a 2 s . c o m*/ * {@inheritDoc} */ public void initialize(WikiEngine engine, Properties properties) { m_engine = engine; m_useRelativeURLStyle = "relative".equals(properties.getProperty(WikiEngine.PROP_REFSTYLE, "relative")); String baseurl = engine.getBaseURL(); if (baseurl != null && baseurl.length() > 0) { try { URL url = new URL(baseurl); String path = url.getPath(); m_pathPrefix = path; } catch (MalformedURLException e) { m_pathPrefix = "/JSPWiki/"; // Just a guess. } } }
From source file:com.krawler.esp.utils.mime.MimeTypes.java
/** * Find the Mime Content Type of a document from its URL. * // w w w .j a v a2 s . co m * @param url * of the document to analyze. * @return the Mime Content Type of the specified document URL, or * <code>null</code> if none is found. */ public MimeType getMimeType(URL url) { return getMimeType(url.getPath()); }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.GeneExpressionLoadAnnotationListener.java
@Override protected String getJobPath() throws Exception { URL jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation.kjb"); jobUrl = FileLocator.toFileURL(jobUrl); String jobPath = jobUrl.getPath(); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_AFFY_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_GEO_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation_to_lt.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/run_i2b2_load_annotation_deapp.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/extract_annotation_from_file.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_annotation_to_de_gpl_info.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); return jobPath; }
From source file:com.hp.autonomy.searchcomponents.hod.view.HodViewServerService.java
@Override public void viewDocument(final String reference, final ResourceIdentifier index, final OutputStream outputStream) throws IOException, HodErrorException { final GetContentRequestBuilder getContentParams = new GetContentRequestBuilder().setPrint(Print.all); final Documents<Document> documents = getContentService.getContent(Collections.singletonList(reference), index, getContentParams);//from www . j av a 2 s . c om // This document will always exist because the GetContentService.getContent throws a HodErrorException if the // reference doesn't exist in the index final Document document = documents.getDocuments().get(0); final Map<String, Serializable> fields = document.getFields(); final Object urlField = fields.get(URL_FIELD); final String documentUrl = urlField instanceof List ? ((List<?>) urlField).get(0).toString() : document.getReference(); final UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES); InputStream inputStream = null; try { try { final URL url = new URL(documentUrl); final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null); final String encodedUrl = uri.toASCIIString(); if (urlValidator.isValid(encodedUrl)) { inputStream = viewDocumentService.viewUrl(encodedUrl, new ViewDocumentRequestBuilder()); } else { throw new URISyntaxException(encodedUrl, "Invalid URL"); } } catch (URISyntaxException | MalformedURLException e) { // URL was not valid, fall back to using the document content inputStream = formatRawContent(document); } catch (final HodErrorException e) { if (e.getErrorCode() == HodErrorCode.BACKEND_REQUEST_FAILED) { // HOD failed to read the url, fall back to using the document content inputStream = formatRawContent(document); } else { throw e; } } IOUtils.copy(inputStream, outputStream); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.metabolomicsData.MetabolomicsLoadAnnotationListener.java
@Override protected String getJobPath() throws Exception { URL jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_metabolomic_annotation.kjb"); jobUrl = FileLocator.toFileURL(jobUrl); String jobPath = jobUrl.getPath(); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_metabolomic_annotation_to_de_gpl_info.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/load_metabolomic_annotation_to_lt.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL( "platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/run_i2b2_load_metabolomic_annot_deapp.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_end_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_start_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); jobUrl = new URL("platform:/plugin/fr.sanofi.fcl4transmart/jobs_kettle/cz_write_audit.ktr"); jobUrl = FileLocator.toFileURL(jobUrl); return jobPath; }
From source file:crawlercommons.fetcher.file.SimpleFileFetcher.java
@Override public FetchedResult get(String url, Payload payload) throws BaseFetchException { String path = null;// w ww. j a v a2 s.c om try { URL realUrl = new URL(url); if (!realUrl.getProtocol().equals("file")) { throw new BadProtocolFetchException(url); } path = realUrl.getPath(); if (path.length() == 0) { path = "/"; } } catch (MalformedURLException e) { throw new UrlFetchException(url, e.getMessage()); } File f = new File(path); FileInputStream fis = null; try { fis = new FileInputStream(f); long startTime = System.currentTimeMillis(); // TODO - limit to be no more than maxContentSize. We should read in // up to 16K, // then call Tika to detect the content type and use that to do // mime-type based // max size. // TODO - see Nutch's File protocol for doing a better job of // mapping file // errors (e.g. file not found) to HttpBaseException such as 404. // TODO - see Nutch's File protocol for handling directories - // return as HTML with links // TODO - see Nutch's File protocol for handling symlinks as // redirects. We'd want // to then enforce max redirects, which means moving the redirect // support back into // the BaseFetcher class. byte[] content = IOUtils.toByteArray(fis); long stopTime = System.currentTimeMillis(); long totalReadTime = Math.max(1, stopTime - startTime); long responseRate = (content.length * 1000L) / totalReadTime; String contentType = "application/octet-stream"; return new FetchedResult(url, url, System.currentTimeMillis(), new Metadata(), content, contentType, (int) responseRate, payload, url, 0, "localhost", HttpStatus.SC_OK, null); } catch (FileNotFoundException e) { throw new HttpFetchException(url, "Error fetching " + url, HttpStatus.SC_NOT_FOUND, new Metadata()); } catch (IOException e) { throw new IOFetchException(url, e); } finally { IOUtils.closeQuietly(fis); } }
From source file:fr.gael.dhus.server.http.webapp.owc.controller.OwcMenuController.java
@PreAuthorize("isAuthenticated () AND hasRole('ROLE_DATA_MANAGER')") @RequestMapping(value = "/settings/menu", method = RequestMethod.PUT) public ResponseEntity<?> setMenu(@RequestBody MenuData body) throws JSONException { URL configFile = ClassLoader.getSystemResource("../etc/conf/menu.json"); if (configFile != null && body != null) { logger.debug("Loading configuration file " + configFile.getPath()); try {/* w w w.ja v a 2 s. c o m*/ PrintWriter fileWriter = new PrintWriter(new FileOutputStream(configFile.getPath(), false)); fileWriter.println("{\"sections\":["); for (MenuSectionsData section : body.getSections()) { fileWriter.println("{"); if (section.getTitle() != null && !section.getTitle().isEmpty()) fileWriter.println("\"title\":\"" + section.getTitle() + "\","); if (section.getIcon() != null && !section.getIcon().isEmpty()) fileWriter.println("\"icon\":\"" + section.getIcon() + "\","); if (section.getComponent() != null && !section.getComponent().isEmpty()) fileWriter.println("\"component\":\"" + section.getComponent() + "\","); if (section.getWidth() != null && !section.getWidth().isEmpty()) fileWriter.println("\"width\":\"" + section.getWidth() + "\","); if (section.getRemoteUrl() != null && !section.getRemoteUrl().isEmpty()) fileWriter.println("\"remoteUrl\":\"" + section.getRemoteUrl() + "\""); else fileWriter.println("\"remoteUrl\":\"\""); fileWriter.println("},"); } fileWriter.println("]}"); fileWriter.close(); return new ResponseEntity<>("{\"code\":\"success\"}", HttpStatus.OK); } catch (IOException e) { logger.error(" Cannot write menu configration file "); e.printStackTrace(); return new ResponseEntity<>("{\"code\":\"unauthorized\"}", HttpStatus.UNAUTHORIZED); } } else { logger.error(" Cannot get menu configration file "); return new ResponseEntity<>("{\"code\":\"unauthorized\"}", HttpStatus.UNAUTHORIZED); } }