List of usage examples for java.net URISyntaxException getLocalizedMessage
public String getLocalizedMessage()
From source file:fr.cs.examples.propagation.VisibilityCircle.java
/** Program entry point. * @param args program arguments// w w w.j a v a 2s. c o m */ public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // input/out File input = new File(VisibilityCircle.class.getResource("/visibility-circle.in").toURI().getPath()); File output = new File(input.getParentFile(), "visibility-circle.csv"); new VisibilityCircle().run(input, output, ","); System.out.println("visibility circle saved as file " + output); } catch (URISyntaxException use) { System.err.println(use.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { System.err.println(ioe.getLocalizedMessage()); System.exit(1); } catch (IllegalArgumentException iae) { System.err.println(iae.getLocalizedMessage()); System.exit(1); } catch (OrekitException oe) { System.err.println(oe.getLocalizedMessage()); System.exit(1); } }
From source file:fr.cs.examples.propagation.TrackCorridor.java
/** Program entry point. * @param args program arguments//w ww. j av a 2 s . c o m */ public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); // input/out File input = new File(TrackCorridor.class.getResource("/track-corridor.in").toURI().getPath()); File output = new File(input.getParentFile(), "track-corridor.csv"); new TrackCorridor().run(input, output, ","); System.out.println("corridor saved as file " + output); } catch (URISyntaxException use) { System.err.println(use.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { System.err.println(ioe.getLocalizedMessage()); System.exit(1); } catch (IllegalArgumentException iae) { System.err.println(iae.getLocalizedMessage()); System.exit(1); } catch (OrekitException oe) { System.err.println(oe.getLocalizedMessage()); System.exit(1); } }
From source file:fr.cs.examples.bodies.Phasing.java
/** Program entry point. * @param args program arguments/*from w ww. java 2s .c o m*/ */ public static void main(String[] args) { try { if (args.length != 1) { System.err.println("usage: java fr.cs.examples.bodies.Phasing filename"); System.exit(1); } // configure Orekit Autoconfiguration.configureOrekit(); // input/out URL url = Phasing.class.getResource("/" + args[0]); if (url == null) { System.err.println(args[0] + " not found"); System.exit(1); } File input = new File(url.toURI().getPath()); new Phasing().run(input); } catch (URISyntaxException use) { System.err.println(use.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { System.err.println(ioe.getLocalizedMessage()); System.exit(1); } catch (IllegalArgumentException iae) { iae.printStackTrace(System.err); System.err.println(iae.getLocalizedMessage()); System.exit(1); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } catch (OrekitException oe) { oe.printStackTrace(System.err); System.err.println(oe.getLocalizedMessage()); System.exit(1); } }
From source file:com.evolveum.midpoint.report.impl.ReportNodeUtils.java
public static InputStream executeOperation(String host, String fileName, String intraClusterHttpUrlPattern, String operation) throws CommunicationException, SecurityViolationException, ObjectNotFoundException, ConfigurationException, IOException { fileName = fileName.replaceAll("\\s", SPACE); InputStream inputStream = null; InputStream entityContent = null; LOGGER.trace("About to initiate connection with {}", host); try {// w ww .ja va 2s .co m if (StringUtils.isNotEmpty(intraClusterHttpUrlPattern)) { LOGGER.trace("The cluster uri pattern: {} ", intraClusterHttpUrlPattern); URI requestUri = buildURI(intraClusterHttpUrlPattern, host, fileName); fileName = URLDecoder.decode(fileName, ReportTypeUtil.URLENCODING); LOGGER.debug("Sending request to the following uri: {} ", requestUri); HttpRequestBase httpRequest = buildHttpRequest(operation); httpRequest.setURI(requestUri); httpRequest.setHeader("User-Agent", ReportTypeUtil.HEADER_USERAGENT); HttpClient client = HttpClientBuilder.create().build(); try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpRequest)) { HttpEntity entity = response.getEntity(); Integer statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { LOGGER.debug("Response OK, the file successfully returned by the cluster peer. "); if (entity != null) { entityContent = entity.getContent(); ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = entityContent.read(buffer)) > -1) { arrayOutputStream.write(buffer, 0, len); } arrayOutputStream.flush(); inputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray()); } } else if (statusCode == HttpStatus.SC_NO_CONTENT) { if (HttpDelete.METHOD_NAME.equals(operation)) { LOGGER.info("Deletion of the file {} was successful.", fileName); } } else if (statusCode == HttpStatus.SC_FORBIDDEN) { LOGGER.error("The access to the report with the name {} is forbidden.", fileName); String error = "The access to the report " + fileName + " is forbidden."; throw new SecurityViolationException(error); } else if (statusCode == HttpStatus.SC_NOT_FOUND) { String error = "The report file " + fileName + " was not found on the originating nodes filesystem."; throw new ObjectNotFoundException(error); } } catch (ClientProtocolException e) { String error = "An exception with the communication protocol has occurred during a query to the cluster peer. " + e.getLocalizedMessage(); throw new CommunicationException(error); } } else { LOGGER.error( "Cluster pattern parameters is empty, please refer to the documentation and set up the parameter value accordingly"); throw new ConfigurationException( "Cluster pattern parameters is empty, please refer to the documentation and set up the parameter value accordingly"); } } catch (URISyntaxException e1) { throw new CommunicationException("Invalid uri syntax: " + e1.getLocalizedMessage()); } catch (UnsupportedEncodingException e) { LOGGER.error("Unhandled exception when listing nodes"); LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing nodes", e); } finally { IOUtils.closeQuietly(entityContent); } return inputStream; }
From source file:jmupen.JMupenUpdater.java
public static void restartApplication() { final String javaBin; if (JMupenUtils.getOs().equalsIgnoreCase("win")) { javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe"; } else {// ww w.j a v a 2 s . com javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; } File currentJar = null; try { currentJar = getJarFile(); } catch (URISyntaxException ex) { System.err.println("Malformed JAR URL " + ex.getLocalizedMessage()); } if (currentJar == null) { return; } /* is it a jar file? */ if (!currentJar.getName().endsWith(".jar")) { return; } /* Build command: java -jar application.jar */ final ArrayList<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-jar"); command.add(currentJar.getPath()); final ProcessBuilder builder = new ProcessBuilder(command); try { builder.start(); } catch (IOException ex) { System.err.println("Error restarting app. " + ex.getLocalizedMessage()); } System.exit(0); }
From source file:jmupen.JMupenUpdater.java
public static void checkForUpdates() { try {// w ww. j a v a 2 s.c o m jarFile = getJarFile(); } catch (URISyntaxException ex) { System.err.println("Error getting jarfile path. " + ex.getLocalizedMessage()); return; } try { if (jarFile != null) { // Get URL connection and lastModified time URL url = new URL(JarURL); URLConnection connection = url.openConnection(); long localMod = jarFile.lastModified(), onlineMod = connection.getLastModified(); updatePackage = new File( JMupenUtils.getConfigDir().concat(JMupenUtils.getBar()).concat("jmupen-update.jar")); if (updatePackage.exists()) { JMupenUpdater.setUpdateAvailable(true); JMupenGUI.getInstance().showUpdateDialog(); return; } if (localMod >= onlineMod - tenmin) { System.out.println("No update available at " + JarURL + '(' + localMod + '>' + onlineMod + ')'); JMupenUpdater.setUpdateAvailable(false); return; } else { JMupenUpdater.setUpdateAvailable(true); } System.out.println("Loading update from " + JarURL); byte bytes[] = getBytes(connection); System.out.println("Update loaded"); writeBytes(updatePackage, bytes); System.out.println("Update saved: " + updatePackage.getAbsolutePath()); jarFile.setLastModified(onlineMod); JMupenGUI.getInstance().showUpdateDialog(); } } catch (Exception e) { System.err.println("Error updating JMupen. " + e.getLocalizedMessage()); } }
From source file:jmupen.JMupenUpdater.java
public static void startWinUpdaterApplication() { final String javaBin; javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe"; File updaterJar = new File(tmpDir.getAbsolutePath() + File.separator + "bin" + File.separator + "win" + File.separator + "JMupenWinupdater.jar"); File currentJarPathTxt = new File( tmpDir.getAbsolutePath() + File.separator + "bin" + File.separator + "currentjar.txt"); try {/*from w w w. ja v a 2 s . com*/ FileUtils.writeStringToFile(currentJarPathTxt, getJarFile().getAbsolutePath()); } catch (IOException e) { System.err.println("Error writing jar filepath " + e.getLocalizedMessage()); JMupenGUI.getInstance().showError("Error writing jar filepath to txt", e.getLocalizedMessage()); } catch (URISyntaxException ex) { System.err.println("Error writing jar filepath " + ex.getLocalizedMessage()); } if (!updaterJar.exists()) { JMupenGUI.getInstance().showError("WinUpdater not found", "in folder: " + updaterJar.getAbsolutePath()); return; } /* is it a jar file? */ if (!updaterJar.getName().endsWith(".jar")) { JMupenGUI.getInstance().showError("WinUpdater does not end with .jar????", updaterJar.getAbsolutePath()); return; } /* Build command: java -jar application.jar */ final ArrayList<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-jar"); command.add(updaterJar.getPath()); final ProcessBuilder builder = new ProcessBuilder(command); try { builder.start(); } catch (IOException ex) { System.err.println("Error starting updater. " + ex.getLocalizedMessage()); JMupenGUI.getInstance().showError("Error starting updater", ex.getLocalizedMessage()); } System.gc(); System.exit(0); }
From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java
/** * Extracts page index information from a URI. The expected pattern is "page=x" where x is * a non-negative integer number. The page index must be specified as part of the URI fragment * and is 1-based, i.e. the first page is 1 but the the method returns a zero-based page * index.//from w w w . j a v a 2s. c o m * An example: <code>http://www.foo.bar/images/scan1.tif#page=4</code> (The method will return * 3.) * <p> * If no page index information is found in the URI or if the URI cannot be parsed, the * method returns null. * @param uri the URI that should be inspected * @return the page index (0 is the first page) or null if there's no page index information * in the URI */ public static Integer getPageIndexFromURI(String uri) { if (uri.indexOf('#') < 0) { return null; } try { URI u = new URI(uri); String fragment = u.getFragment(); if (fragment != null) { int pos = fragment.indexOf(PAGE_INDICATOR); if (pos >= 0) { pos += PAGE_INDICATOR.length(); StringBuffer sb = new StringBuffer(); while (pos < fragment.length()) { char c = fragment.charAt(pos); if (c >= '0' && c <= '9') { sb.append(c); } else { break; } pos++; } if (sb.length() > 0) { int pageIndex = Integer.parseInt(sb.toString()) - 1; pageIndex = Math.max(0, pageIndex); return new Integer(pageIndex); } } } } catch (URISyntaxException e) { throw new IllegalArgumentException("URI is invalid: " + e.getLocalizedMessage()); } return null; }
From source file:org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager.java
/** * Get the temporary directory path. If there is an instance of Eclipse * running, the temporary directory will reside under the workspace. * * @return the temporary directory path suitable to be passed to the * java.io.File constructor without a trailing separator *///from w w w .ja va2 s.c o m public static String getTemporaryDirPath() { // Get the workspace path from the properties String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$ if (property != null) { try { File dir = URIUtil.toFile(URIUtil.fromString(property)); dir = new File(dir.getAbsolutePath() + File.separator + TEMP_DIR_NAME); if (!dir.exists()) { dir.mkdirs(); } return dir.getAbsolutePath(); } catch (URISyntaxException e) { Activator.logError(e.getLocalizedMessage(), e); } } return System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ }
From source file:org.rhq.plugins.jbossas5.ApplicationServerComponent.java
private static void validateNamingURL(String namingURL) { URI namingURI;//from w w w. ja v a 2 s .c om try { namingURI = new URI(namingURL); } catch (URISyntaxException e) { throw new RuntimeException("Naming URL '" + namingURL + "' is not valid: " + e.getLocalizedMessage()); } if (!namingURI.isAbsolute()) throw new RuntimeException("Naming URL '" + namingURL + "' is not absolute."); if (!namingURI.getScheme().equals("jnp")) throw new RuntimeException( "Naming URL '" + namingURL + "' has an invalid protocol - the only valid protocol is 'jnp'."); }