List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:edu.toronto.cs.xcurator.cli.CLIRunner.java
public static void main(String[] args) { Options options = setupOptions();// ww w .j a va 2 s. c o m CommandLineParser parser = new BasicParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption('t')) { fileType = line.getOptionValue('t'); } else { fileType = XML; } if (line.hasOption('o')) { tdbDirectory = line.getOptionValue('o'); File d = new File(tdbDirectory); if (!d.exists() || !d.isDirectory()) { throw new Exception("TDB directory does not exist, please create."); } } if (line.hasOption('h')) { domain = line.getOptionValue('h'); try { URL url = new URL(domain); } catch (MalformedURLException ex) { throw new Exception("The domain name is ill-formed"); } } else { printHelpAndExit(options); } if (line.hasOption('m')) { serializeMapping = true; mappingFilename = line.getOptionValue('m'); } if (line.hasOption('d')) { dirLocation = line.getOptionValue('d'); inputStreams = new ArrayList<>(); final List<String> files = Util.getFiles(dirLocation); for (String inputfile : files) { File f = new File(inputfile); if (f.isFile() && f.exists()) { System.out.println("Adding document to mapping discoverer: " + inputfile); inputStreams.add(new FileInputStream(f)); } // If it is a URL download link for the document from SEC else if (inputfile.startsWith("http") && inputfile.contains("://")) { // Download System.out.println("Adding remote document to mapping discoverer: " + inputfile); try { URL url = new URL(inputfile); InputStream remoteDocumentStream = url.openStream(); inputStreams.add(remoteDocumentStream); } catch (MalformedURLException ex) { throw new Exception("The document URL is ill-formed: " + inputfile); } catch (IOException ex) { throw new Exception("Error in downloading remote document: " + inputfile); } } else { throw new Exception("Cannot open XBRL document: " + f.getName()); } } } if (line.hasOption('f')) { fileLocation = line.getOptionValue('f'); inputStreams = new ArrayList<>(); File f = new File(fileLocation); if (f.isFile() && f.exists()) { System.out.println("Adding document to mapping discoverer: " + fileLocation); inputStreams.add(new FileInputStream(f)); } // If it is a URL download link for the document from SEC else if (fileLocation.startsWith("http") && fileLocation.contains("://")) { // Download System.out.println("Adding remote document to mapping discoverer: " + fileLocation); try { URL url = new URL(fileLocation); InputStream remoteDocumentStream = url.openStream(); inputStreams.add(remoteDocumentStream); } catch (MalformedURLException ex) { throw new Exception("The document URL is ill-formed: " + fileLocation); } catch (IOException ex) { throw new Exception("Error in downloading remote document: " + fileLocation); } } else { throw new Exception("Cannot open XBRL document: " + f.getName()); } } setupDocumentBuilder(); RdfFactory rdfFactory = new RdfFactory(new RunConfig(domain)); List<Document> documents = new ArrayList<>(); for (InputStream inputStream : inputStreams) { Document dataDocument = null; if (fileType.equals(JSON)) { String json = IOUtils.toString(inputStream); final String xml = Util.json2xml(json); final InputStream xmlInputStream = IOUtils.toInputStream(xml); dataDocument = createDocument(xmlInputStream); } else { dataDocument = createDocument(inputStream); } documents.add(dataDocument); } if (serializeMapping) { System.out.println("Mapping file will be saved to: " + new File(mappingFilename).getAbsolutePath()); rdfFactory.createRdfs(documents, tdbDirectory, mappingFilename); } else { rdfFactory.createRdfs(documents, tdbDirectory); } } catch (Exception ex) { ex.printStackTrace(); System.err.println("Unexpected exception: " + ex.getMessage()); System.exit(1); } }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
public static void main(final String[] args) { final String[][] test = new String[][] { new String[] { null, "file://y:/" }, new String[] { null, "file://y:/yacy" }, new String[] { null, "file://y:/yacy/" }, new String[] { null, "file://y:" }, new String[] { null, "file://Z:admin\\home" }, // thats wrong but may appear new String[] { null, "file://Z:\\admin\\home" }, new String[] { null, "https://www.example.com/shoe/?p=2&ps=75#t={%22san_NaviPaging%22:2}" }, // ugly strange pagination link new String[] { null, "C:WINDOWS\\CMD0.EXE" }, new String[] { null, "file://C:WINDOWS\\CMD0.EXE" }, new String[] { null, "file:///bin/yacy2" }, // file://<host>/<path> may have many '/' if the host is omitted and the path starts with '/' new String[] { null, "file:/bin/yacy1" }, // file://<host>/<path> may have many '/' if the host is omitted and the path starts with '/' new String[] { null, "file:C:WINDOWS\\CMD.EXE" }, new String[] { null, "file:///C:WINDOWS\\CMD1.EXE" }, new String[] { null, "file:///C|WINDOWS\\CMD2.EXE" }, new String[] { null, "http://www.anomic.de/test/" }, new String[] { null, "http://www.anomic.de/" }, new String[] { null, "http://www.anomic.de" }, new String[] { null, "http://www.anomic.de/home/test?x=1#home" }, new String[] { null, "http://www.anomic.de/home/test?x=1" }, new String[] { null, "http://www.anomic.de/home/test#home" }, new String[] { null, "ftp://ftp.anomic.de/home/test#home" }, new String[] { null, "ftp://bob:builder@ftp.anomic.de/home/test.gif" }, new String[] { null, "http://www.anomic.de/home/../abc/" }, new String[] { null, "mailto:abcdefg@nomailnomail.com" }, new String[] { "http://www.anomic.de/home", "test" }, new String[] { "http://www.anomic.de/home", "test/" }, new String[] { "http://www.anomic.de/home/", "test" }, new String[] { "http://www.anomic.de/home/", "test/" }, new String[] { "http://www.anomic.de/home/index.html", "test.htm" }, new String[] { "http://www.anomic.de/home/index.html", "http://www.yacy.net/test" }, new String[] { "http://www.anomic.de/home/index.html", "ftp://ftp.yacy.net/test" }, new String[] { "http://www.anomic.de/home/index.html", "../test" }, new String[] { "http://www.anomic.de/home/index.html", "mailto:abcdefg@nomailnomail.com" }, new String[] { null, "news:de.test" }, new String[] { "http://www.anomic.de/home", "news:de.test" }, new String[] { null, "mailto:bob@web.com" }, new String[] { "http://www.anomic.de/home", "mailto:bob@web.com" }, new String[] { "http://www.anomic.de/home", "ftp://ftp.anomic.de/src" }, new String[] { null, "ftp://ftp.delegate.org/" }, new String[] { "http://www.anomic.de/home", "ftp://ftp.delegate.org/" }, new String[] { "http://www.anomic.de", "mailto:yacy@weltherrschaft.org" }, new String[] { "http://www.anomic.de", "javascipt:temp" }, new String[] { null, "http://yacy-websuche.de/wiki/index.php?title=De:IntroInformationFreedom&action=history" }, new String[] { null, "http://diskusjion.no/index.php?s=5bad5f431a106d9a8355429b81bb0ca5&showuser=23585" }, new String[] { null, "http://diskusjion.no/index.php?s=5bad5f431a106d9a8355429b81bb0ca5&showuser=23585" }, new String[] { null, "http://www.scc.kit.edu/publikationen/80.php?PHPSESSID=5f3624d3e1c33d4c086ab600d4d5f5a1" }, new String[] { null, "smb://localhost/" }, new String[] { null, "smb://localhost/repository" }, // paths must end with '/' new String[] { null, "smb://localhost/repository/" }, new String[] { null, "\\\\localhost\\" }, // Windows-like notion of smb shares new String[] { null, "\\\\localhost\\repository" }, new String[] { null, "\\\\localhost\\repository\\" }, new String[] { null, "http://test.net/test1.htm?s=multiple&a=amp&b=in&c=url" }, new String[] { null, "http://test.net/test2.htm?s=multiple&amp;amp;amp;a=amp" }, new String[] { null, "http://validator.w3.org/check?uri=http://www.anomic.de/" } }; //MultiProtocolURI.initSessionIDNames(FileUtils.loadList(new File("defaults/sessionid.names"))); String environment, url;//from ww w .jav a 2 s .com MultiProtocolURL aURL, aURL1; java.net.URL jURL; for (String[] element : test) { environment = element[0]; url = element[1]; try { aURL = MultiProtocolURL.newURL(environment, url); } catch (final MalformedURLException e) { e.printStackTrace(); aURL = null; } if (environment == null) { try { jURL = new java.net.URL(url); } catch (final MalformedURLException e) { jURL = null; } } else { try { jURL = new java.net.URL(new java.net.URL(environment), url); } catch (final MalformedURLException e) { jURL = null; } } // check equality to java.net.URL if (((aURL == null) && (jURL != null)) || ((aURL != null) && (jURL == null)) || ((aURL != null) && (jURL != null) && (!(jURL.toString().equals(aURL.toNormalform(false)))))) { System.out.println("Difference for environment=" + environment + ", url=" + url + ":"); System.out.println((jURL == null) ? "jURL rejected input" : "jURL=" + jURL.toString()); System.out.println((aURL == null) ? "aURL rejected input" : "aURL=" + aURL.toNormalform(false) + "; host=" + aURL.getHost() + "; path=" + aURL.getPath() + "; file=" + aURL.getFile()); } if (aURL != null && jURL != null && jURL.toString().equals(aURL.toNormalform(false))) { System.out.println("jURL == aURL=" + aURL.toNormalform(false) + "; host=" + aURL.getHost() + "; path=" + aURL.getPath() + "; file=" + aURL.getFile()); } // check stability: the normalform of the normalform must be equal to the normalform if (aURL != null) try { aURL1 = new MultiProtocolURL(aURL.toNormalform(false)); if (!(aURL1.toNormalform(false).equals(aURL.toNormalform(false)))) { System.out.println("no stability for url:"); System.out.println("aURL0=" + aURL.toNormalform(false)); System.out.println("aURL1=" + aURL1.toNormalform(false)); } } catch (final MalformedURLException e) { System.out.println("no stability for url:"); System.out.println("aURL0=" + aURL.toNormalform(false)); System.out.println("aURL1 cannot be computed:" + e.getMessage()); } } }
From source file:com.wanikani.wklib.Util.java
public static URL getURL(JSONObject obj, String key) throws JSONException { String s;/*from w ww .j a v a 2 s . c o m*/ try { s = getString(obj, key); return s != null ? new URL(s) : null; } catch (MalformedURLException e) { throw new JSONException(e.getMessage()); } }
From source file:Main.java
public static String readFile(String link) { try {//from w ww . ja v a 2s. co m // Create a URL for the desired page URL url = new URL(link); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String text = ""; String str; while ((str = in.readLine()) != null) text += str + "\n"; in.close(); return text; } catch (MalformedURLException e) { e.printStackTrace(); return e.getMessage(); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); } }
From source file:it.geosolutions.geonetwork.op.GNInfo.java
public static boolean ping(HTTPUtils connection, String serviceURL) { if (LOGGER.isDebugEnabled()) LOGGER.debug("PING"); connection.setIgnoreResponseContentOnSuccess(true); String url = serviceURL + "/srv/eng/util.ping"; try {/*from w w w . j a v a 2s . c om*/ connection.get(url); } catch (MalformedURLException ex) { LOGGER.error(ex.getMessage()); return false; } if (connection.getLastHttpStatus() != HttpStatus.SC_OK) { if (LOGGER.isInfoEnabled()) LOGGER.info("PING failed"); return false; } return true; }
From source file:Main.java
public static String callJsonAPI(String urlString) { // Use HttpURLConnection as per Android 6.0 spec, instead of less efficient HttpClient HttpURLConnection urlConnection = null; StringBuilder jsonResult = new StringBuilder(); try {/*from w w w . j a v a 2 s. c om*/ URL url = new URL(urlString); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setUseCaches(false); urlConnection.setConnectTimeout(TIMEOUT_CONNECTION); urlConnection.setReadTimeout(TIMEOUT_READ); urlConnection.connect(); int status = urlConnection.getResponseCode(); switch (status) { case 200: case 201: BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line; while ((line = br.readLine()) != null) { jsonResult.append(line).append("\n"); } br.close(); } } catch (MalformedURLException e) { System.err.print(e.getMessage()); return e.getMessage(); } catch (IOException e) { System.err.print(e.getMessage()); return e.getMessage(); } finally { if (urlConnection != null) { try { urlConnection.disconnect(); } catch (Exception e) { System.err.print(e.getMessage()); } } } return jsonResult.toString(); }
From source file:Main.java
public static String getJsonCurrencyObject(String myurl) { StringBuilder strBuilder = new StringBuilder(); try {/*from ww w.jav a 2 s .c o m*/ URL url = new URL(myurl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream inputStream = new BufferedInputStream(connection.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { strBuilder.append(line); } inputStream.close(); } catch (MalformedURLException ex) { Log.d("HttpURLConnection", "getJsonCurrencyObject: " + ex.getMessage()); } catch (IOException e) { Log.d("readJSONFeed", e.getLocalizedMessage()); e.printStackTrace(); } catch (Exception ex) { Log.d("GeneralException", ex.getMessage()); } return strBuilder.toString(); }
From source file:com.jts.main.helper.Http.java
public static String get(String urlString) { BufferedReader reader = null; try {/*from ww w. j a v a2s . c o m*/ URL url = new URL(urlString); reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuilder buffer = new StringBuilder(); int read; char[] chars = new char[1024]; while ((read = reader.read(chars)) != -1) { buffer.append(chars, 0, read); } return buffer.toString(); } catch (MalformedURLException ex) { errMsg = ex.getMessage(); } catch (IOException ex) { errMsg = ex.getMessage(); } finally { if (reader != null) { try { reader.close(); } catch (IOException ex) { errMsg = ex.getMessage(); } } } return ""; }
From source file:grails.plugins.sitemapper.ValidationUtils.java
public static void assertLocation(String url) { try {/*from www .ja v a 2s.com*/ new URL(url); } catch (MalformedURLException e) { throw new SitemapperException(e.getMessage(), e); } }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList, boolean removeFragment) { if (href == null) return null; href = href.trim();/*from ww w.j a va 2 s . c o m*/ if (href.length() == 0) return null; String fragment = null; try { URI u = URIUtils.resolve(currentURL.toURI(), href); href = u.toString(); href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList); URI uri = URI.create(href); uri = uri.normalize(); String p = uri.getPath(); if (p != null) if (p.contains("/./") || p.contains("/../")) return null; if (!removeFragment) fragment = uri.getRawFragment(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment).normalize().toURL(); } catch (MalformedURLException e) { Logging.info(e.getMessage()); return null; } catch (URISyntaxException e) { Logging.info(e.getMessage()); return null; } catch (IllegalArgumentException e) { Logging.info(e.getMessage()); return null; } }