List of usage examples for java.net URL toString
public String toString()
From source file:edu.isi.karma.kr2rml.mapping.WorksheetR2RMLJenaModelParser.java
public static Model loadSourceModelIntoJenaModel(R2RMLMappingIdentifier id) throws IOException { // Create an empty Model Model model = ModelFactory.createDefaultModel(); InputStream s;/* w w w.ja va2 s . c o m*/ if (id.getContent() != null) { s = IOUtils.toInputStream(id.getContent()); } else { URL modelURL = id.getLocation(); logger.info("Load model:" + modelURL.toString()); s = modelURL.openStream(); } model.read(s, null, "TURTLE"); return model; }
From source file:fr.cls.atoll.motu.processor.wps.framework.WPSUtils.java
public static InputStream post(String url, URL urlFile, Map<String, String> headers) throws MotuException { return WPSUtils.post(url, urlFile.toString(), headers); }
From source file:com.hdsfed.cometapi.ThreadTrackerDB.java
static private synchronized int genericDBActionOverHttpGET(String args, Boolean force) throws Exception { if (!CometProperties.getInstance().getIngestorHeartbeatEnabled()) { ScreenLog.fine("requested heartbeat action, but local heartbeat for ingest is disabled, return 200"); return 200; }/*from w ww . j a va2 s . c om*/ if (CometProperties.isHeartBeatTooSoon() && !force) { ScreenLog.fine("requested heartbeat action, but heartbeat too rapid; skipping args==" + args + " and return 200"); return 200; } ScreenLog.begin("ThreadTrackerDB::genericDBActionOverHttpGET(" + args + ")"); HttpResponse httpResponse; URL url; int status = -1; HttpClient mHttpClient = HCPUtils.initHttpClient(); url = new URL( "http://localhost" + CometProperties.getInstance().getWebAppPath() + "IngestorThreads" + args); HttpGet httpRequest = new HttpGet(url.toString()); httpResponse = mHttpClient.execute(httpRequest); status = HttpCatchError(httpRequest, httpResponse); if (httpResponse.getEntity().getContentLength() > 0) { EntityUtils.consume(httpResponse.getEntity()); } //forcefully clear it out mHttpClient = null; httpResponse = null; ScreenLog.end("ThreadTrackerDB::genericDBActionOverHttpGET(" + args + ") status=" + status); return status; }
From source file:net.gazeplay.commons.utils.games.Utils.java
public static void playSound(String ressource) { log.debug("Try to play " + ressource); URL url = ClassLoader.getSystemResource(ressource); String path = null;//from www . j a v a 2 s . co m if (url == null) { final File file = new File(ressource); log.debug("using file"); if (!file.exists()) { log.warn("file doesn't exist : {}", ressource); } path = file.toURI().toString(); } else { log.debug("using url"); path = url.toString(); } log.debug("path " + path); if (sxmp != null) sxmp.stop(); try { Media media = new Media(path); sxmp = new MediaPlayer(media); final Configuration configuration = Configuration.getInstance(); sxmp.setVolume(configuration.getEffectsVolume()); sxmp.volumeProperty().bind(configuration.getEffectsVolumeProperty()); sxmp.play(); } catch (Exception e) { log.error("Exception", e); } }
From source file:Browser.java
/** * Open the specified URL in the client web browser. * /*from ww w . ja v a 2 s. c o m*/ * @param url URL to open. * @throws IOException If there is brwoser problem. */ public static void openUrl(URL url) throws IOException { openUrl(url.toString()); }
From source file:apim.restful.importexport.utils.APIImportUtil.java
/** * This method adds the WSDL to the registry, if there is a WSDL associated with the API * * @param pathToArchive location of the extracted folder of the API * @param importedApi the imported API object * @param currentUser current logged in username *///w w w. java 2 s . c o m private static void addAPIWsdl(String pathToArchive, API importedApi, String currentUser) { String wsdlFileName = importedApi.getId().getApiName() + "-" + importedApi.getId().getVersion() + APIImportExportConstants.WSDL_EXTENSION; String wsdlPath = pathToArchive + APIImportExportConstants.WSDL_LOCATION + wsdlFileName; if (checkFileExistence(wsdlPath)) { try { URL wsdlFileUrl = new File(wsdlPath).toURI().toURL(); importedApi.setWsdlUrl(wsdlFileUrl.toString()); Registry registry = APIExportUtil.getRegistry(currentUser); APIUtil.createWSDL((org.wso2.carbon.registry.core.Registry) registry, importedApi); } catch (MalformedURLException e) { //this exception is logged and ignored since WSDL is optional for an API log.error("Error in getting WSDL URL. ", e); } catch (org.wso2.carbon.registry.core.exceptions.RegistryException e) { //this exception is logged and ignored since WSDL is optional for an API log.error("Error in putting the WSDL resource to registry. ", e); } catch (APIManagementException e) { //this exception is logged and ignored since WSDL is optional for an API log.error("Error in creating the WSDL resource in the registry. ", e); } } }
From source file:com.android.providers.downloads.OmaDownload.java
/** * This method notifies the server for the status of the download operation. * It sends a status report to a Web server if installNotify attribute is specified in the download descriptor. @param component the component that contains attributes in the descriptor. @param handler the handler used to send and process messages. A message indicates whether the media object is available to the user or not (READY or DISCARD). */// w ww.j a v a 2 s. c o m //protected static void installNotify (OmaDescription component, Handler handler) { protected static int installNotify(OmaDescription component, Handler handler) { int ack = -1; int release = OmaStatusHandler.DISCARD; URL url = component.getInstallNotifyUrl(); if (url != null) { DefaultHttpClient client = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(url.toString()); try { HttpParams params = postRequest.getParams(); HttpProtocolParams.setUseExpectContinue(params, false); postRequest.setEntity( new StringEntity(OmaStatusHandler.statusCodeToString(component.getStatusCode()) + "\n\r")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // TODO Auto-generated method stub Log.i("@M_" + Constants.LOG_OMA_DL, "Retry the request..."); return (executionCount <= OmaStatusHandler.MAXIMUM_RETRY); } }); try { HttpResponse response = client.execute(postRequest); if (response.getStatusLine() != null) { ack = response.getStatusLine().getStatusCode(); //200-series response code if (ack == HttpStatus.SC_OK || ack == HttpStatus.SC_ACCEPTED || ack == HttpStatus.SC_CREATED || ack == HttpStatus.SC_MULTI_STATUS || ack == HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION || ack == HttpStatus.SC_NO_CONTENT || ack == HttpStatus.SC_PARTIAL_CONTENT || ack == HttpStatus.SC_RESET_CONTENT) { if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = null; try { inputStream = entity.getContent(); if (inputStream != null) { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String s; while ((s = br.readLine()) != null) { Log.v("@M_" + Constants.LOG_OMA_DL, "Response: " + s); } } } finally { if (inputStream != null) { inputStream.close(); } entity.consumeContent(); } } } } catch (ConnectTimeoutException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); //After time out period, the client releases the media object for use. if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } catch (NoHttpResponseException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); //After time out period, the client releases the media object for use. if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } catch (IOException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); } if (client != null) { client.getConnectionManager().shutdown(); } } else { if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } if (handler != null) { Message mg = Message.obtain(); mg.arg1 = release; handler.sendMessage(mg); } return release; }
From source file:gate.corpora.twitter.Population.java
private static Document newDocument(URL url, int counter, int digits) throws ResourceInstantiationException { Document document = Factory.newDocument(""); String code = StringUtils.leftPad(Integer.toString(counter), digits, '0'); String name = StringUtils.stripToEmpty(StringUtils.substring(url.getPath(), 1)) + "_" + code; document.setName(name);//from w ww .j a v a2 s . com document.setSourceUrl(url); document.getFeatures().put(Document.DOCUMENT_MIME_TYPE_PARAMETER_NAME, TweetUtils.MIME_TYPE); document.getFeatures().put("gate.SourceURL", url.toString()); return document; }
From source file:de.betterform.agent.betty.Betty.java
public static URI toFileCompatibleURI(URL url) throws URISyntaxException { if (url == null) { return null; }/* w w w .ja v a 2 s.c om*/ String string = url.toString(); if (url.getProtocol().equals("file") && url.getQuery() != null) { return new URI(string.substring(0, string.indexOf('?'))); } return new URI(string); }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.java
/** * Make the given URL available as an executable file. A temporary file is created and deleted * upon a regular shutdown of the JVM. If the parameter {@code aCache} is {@code true}, the * temporary file is remembered in a cache and if a file is requested for the same URL at a * later time, the same file is returned again. If the previously created file has been deleted * meanwhile, it is recreated from the URL. * * @param aUrl//from w ww . ja v a2 s . c o m * the URL. * @param aCache * use the cache or not. * @return an executable file created from the given URL. * @throws IOException * if the file has permissions issues. */ public static synchronized File getUrlAsExecutable(URL aUrl, boolean aCache) throws IOException { File file; synchronized (urlFileCache) { file = urlFileCache.get(aUrl.toString()); if (!aCache || (file == null) || !file.exists()) { String name = FilenameUtils.getBaseName(aUrl.getPath()); file = File.createTempFile(name, ".temp"); file.setExecutable(true); if (!file.canExecute()) { StringBuilder errorMessage = new StringBuilder(128); errorMessage.append("Tried to use temporary folder, but seems it is not " + "executable. Please check the permissions rights from your " + "temporary folder.\n"); if (isEnvironmentVariableDefined(XDG_RUNTIME_DIR_ENV_VAR, errorMessage) && checkFolderPermissions(errorMessage, System.getenv(XDG_RUNTIME_DIR_ENV_VAR))) { file = getFileAsExecutable(aUrl, System.getenv(XDG_RUNTIME_DIR_ENV_VAR)); } else if (isEnvironmentVariableDefined(DKPRO_HOME_ENV_VAR, errorMessage) && checkFolderPermissions(errorMessage, System.getenv(DKPRO_HOME_ENV_VAR) + File.separator + "temp")) { file = getFileAsExecutable(aUrl, System.getenv(DKPRO_HOME_ENV_VAR) + File.separator + "temp"); } else { if (!isUserHomeDefined(errorMessage) || !checkFolderPermissions(errorMessage, System.getProperty("user.home") + File.separator + ".dkpro" + File.separator + "temp")) { throw new IOException(errorMessage.toString()); } file = getFileAsExecutable(aUrl, System.getProperty("user.home") + File.separator + ".dkpro" + File.separator + "temp"); } } file.deleteOnExit(); InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = aUrl.openStream(); outputStream = new FileOutputStream(file); copy(inputStream, outputStream); } finally { closeQuietly(inputStream); closeQuietly(outputStream); } if (aCache) { urlFileCache.put(aUrl.toString(), file); } } } return file; }