List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:gate.corpora.twitter.Population.java
@Override protected List<Action> buildActions(final NameBearerHandle handle) { List<Action> actions = new ArrayList<Action>(); if (!(handle.getTarget() instanceof Corpus)) return actions; actions.add(new AbstractAction("Populate from Twitter JSON files") { private static final long serialVersionUID = -8511779592856786327L; @Override//from w w w. ja va 2 s . com public void actionPerformed(ActionEvent e) { final PopulationDialogWrapper dialog = new PopulationDialogWrapper(); // If no files were selected then just stop try { final List<URL> fileUrls = dialog.getFileUrls(); if ((fileUrls == null) || fileUrls.isEmpty()) { return; } // Run the population in a separate thread so we don't lock up the GUI Thread thread = new Thread(Thread.currentThread().getThreadGroup(), "Twitter JSON Corpus Populator") { public void run() { try { for (URL fileUrl : fileUrls) { populateCorpus((Corpus) handle.getTarget(), fileUrl, dialog.getEncoding(), dialog.getContentKeys(), dialog.getFeatureKeys(), dialog.getTweetsPerDoc()); } } catch (ResourceInstantiationException e) { e.printStackTrace(); } } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } catch (MalformedURLException e0) { e0.printStackTrace(); } } }); return actions; }
From source file:eu.optimis.mi.gui.server.MonitoringManagerWebServiceImpl.java
public String getIdMetricDateStrMonitoringResources(String id, String level, String metricName, String dfrom, String dto) {/*from ww w . j a v a 2 s . co m*/ String xml = new String(""); String urlString = MMANAGER_URL + "QueryResources/date/metric/" + metricName + "/" + level + "/" + id + "/" + dfrom + "." + dto; logger.debug("Metric monitoring resource URL:" + urlString); try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/XML"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); logger.debug("Output from Server... \n" + dfrom.toString()); String li; while ((li = br.readLine()) != null) { xml = xml.concat(li); } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return xml; }
From source file:com.cladonia.xngreditor.URLUtilities.java
/** * Creates a new URL./*from w w w. ja va 2s.c om*/ * * @param protocol the protocol, ie: file, http, https, ftp. * @param username the username for the connection. * @param password the password for the connection. * @param host the host server. * @param file the file on the server. * * @return the url or null if the URL could not be created. */ public static URL createURL(String protocol, String username, String password, String host, int port, String path, String query, String ref) { URL url = null; try { StringBuffer result = new StringBuffer(protocol); result.append(':'); if (host != null && host.length() > 0) { result.append("//"); if (username != null && username.length() > 0) { result.append(username); result.append(':'); if (password != null && password.length() > 0) { result.append(password); } result.append('@'); } result.append(host); } if (port > 0) { result.append(':'); result.append(port); } if (path != null) { result.append(path); } if (query != null) { result.append('?'); result.append(query); } if (ref != null) { result.append('#'); result.append(ref); } url = new URL(result.toString()); } catch (MalformedURLException e) { e.printStackTrace(); // just return null url = null; } return url; }
From source file:org.makersoft.activerecord.bootstrap.Bootstrap.java
private URL[] getPackagePaths() { URL classpathUrl = ClasspathUrlFinder.findClassBase(this.getClass()); try {/* www . j a v a 2 s . c o m*/ String classpath = classpathUrl.getPath(); String testClasspath = classpath.substring(0, classpath.lastIndexOf("classes")) + "test-classes/"; return new URL[] { new URL("file:" + classpath + basePackage.replaceAll("\\.", "/") + "/"), new URL("file:" + testClasspath + basePackage.replaceAll("\\.", "/") + "/") }; } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:com.coodesoft.notee.MyImageGetter.java
@Override public Drawable getDrawable(String source) { Drawable d = null;//from w ww. ja v a2 s . c o m String strSrcLeft5 = source.substring(0, 5); // data if (strSrcLeft5.equalsIgnoreCase("data:")) { InputStream is = new ByteArrayInputStream(source.getBytes()); //d = Drawable.createFromStream(is, null); //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); //Bitmap dBitmap = BitmapFactory.decodeByteArray(data, 0, length); int nPosComma = source.indexOf(','); if (nPosComma > 0) { byte[] arrBuffer = Base64.decode(source.substring(nPosComma + 1), Base64.DEFAULT); //byte[] arrBuffer = Base64Coder.decode(source.substring(nPosComma + 1)); Bitmap dBitmap = BitmapFactory.decodeByteArray(arrBuffer, 0, arrBuffer.length); d = new BitmapDrawable(dBitmap); d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight()); } } else { // url try { InputStream is = (InputStream) new URL(source).getContent(); Bitmap dBitmap = BitmapFactory.decodeStream(is); if (dBitmap == null) { d = Resources.getSystem().getDrawable(android.R.drawable.picture_frame); } else { d = new BitmapDrawable(dBitmap); d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight()); } d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /* URLDrawable urlDrawable = new URLDrawable(); // get the actual source ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask( urlDrawable); asyncTask.execute(source); // return reference to URLDrawable where I will change with actual image from // the src tag return urlDrawable; */ } return d; }
From source file:com.cloverstudio.spika.utils.BitmapManager.java
private Bitmap downloadBitmap(String url) { try {//from ww w .ja v a2s .co m Bitmap bitmap = BitmapFactory.decodeStream( (InputStream) ConnectionHandler.httpGetRequest(url, UsersManagement.getLoginUser().getId())); imgRatio = (float) bitmap.getWidth() / (float) bitmap.getHeight(); smallImg = false; // int REQUIRED_SIZE = 100; // // int width = 0; // int height = 0; // // if (bitmap.getHeight() < REQUIRED_SIZE // && bitmap.getWidth() < REQUIRED_SIZE) { // width = bitmap.getWidth(); // height = bitmap.getHeight(); // smallImg = true; // } else if (bitmap.getHeight() < height) { // height = bitmap.getHeight(); // } else if (bitmap.getWidth() < width) { // width = bitmap.getWidth(); // } // // // bitmap = Bitmap.createScaledBitmap(bitmap, // (int) (height * imgRatio), height, true); cache.put(url, new SoftReference<Bitmap>(bitmap)); return bitmap; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SpikaException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SpikaForbiddenException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:cz.autoclient.github.local.ReleaseFileLocal.java
public ReleaseFileLocal(ReleaseLocal parent, JSONObject elm) { this.parent = parent; URL downloadUrl = null;//from ww w . j a v a 2 s.co m String name = null; long size = 0; try { name = elm.getString("name"); size = elm.getInt("size"); downloadUrl = new URL(parent.url, URLEncoder.encode(name)); } catch (JSONException e) { } catch (MalformedURLException ex) { System.out.println("Error creating url: \"" + parent.url + "\" + \"" + URLEncoder.encode(name) + "\""); ex.printStackTrace(); } ; this.downloadUrl = downloadUrl; this.name = name; this.size = size; }
From source file:net.dries007.coremod.Module.java
/** * This method gets all the dependencies, ASM classes and ATs from the files associated with this module. *///from www. ja v a2 s .c om public void parceJarFiles() { for (ModuleFile mFile : this.files) { try { JarFile jar = new JarFile(mFile.file); Manifest mf = jar.getManifest(); if (mf != null) { for (Entry<Object, Object> attribute : mf.getMainAttributes().entrySet()) { attributes.put(attribute.getKey().toString(), attribute.getValue().toString()); } /** * Reading NORMAL libs from the modules' manifest files. * We want: Space sperated pairs of filename:sha1 */ if (Data.hasKey(Data.LIBKEY_NORMAL, Data.LIBURL_NORMAL)) { String libs = mf.getMainAttributes().getValue(Data.get(Data.LIBKEY_NORMAL)); if (libs != null) for (String lib : libs.split(" ")) { DefaultDependency dependency = new DefaultDependency(lib); dependecies.add(dependency); } } /** * Reading MAVEN libs from the modules' manifest files. * We want: the maven name */ if (Data.hasKey(Data.LIBKEY_MAVEN, Data.LIBURL_MAVEN)) { String libs = mf.getMainAttributes().getValue(Data.get(Data.LIBKEY_MAVEN)); if (libs != null) for (String lib : libs.split(" ")) { MavenDependency dependency = new MavenDependency(this, lib); dependecies.add(dependency); dependecies.addAll(Coremod.getDependencies(dependency)); } } /* * Reading ASM classes from the modules' manifest files */ if (Data.hasKey(Data.CLASSKEY_ASM)) { String asmclasses = mf.getMainAttributes().getValue(Data.get(Data.CLASSKEY_ASM)); if (asmclasses != null) for (String asmclass : asmclasses.split(" ")) { this.ASMClasses.add(asmclass); System.out.println("[" + Data.NAME + "] Added ASM class (" + asmclass + ") for module file " + jar.getName()); } } /* * Reading AT Files from the modules' manifest files */ if (Data.hasKey(Data.FILEKEY_TA)) { String ats = mf.getMainAttributes().getValue(Data.FILEKEY_TA); if (ats != null) for (String at : ats.split(" ")) { this.ATFiles.add(at); System.out.println("[" + Data.NAME + "] Added AccessTransformer (" + at + ") for module file " + jar.getName()); } } } jar.close(); } catch (final MalformedURLException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } } }
From source file:MainClass.java
private void writeAttributes(AttributeSet attributes) throws IOException { Enumeration e = attributes.getAttributeNames(); while (e.hasMoreElements()) { Object name = e.nextElement(); String value = (String) attributes.getAttribute(name); try {/*from w w w.j a va2s . co m*/ if (name == HTML.Attribute.HREF || name == HTML.Attribute.SRC || name == HTML.Attribute.LOWSRC || name == HTML.Attribute.CODEBASE) { URL u = new URL(base, value); out.write(" " + name + "=\"" + u + "\""); } else { out.write(" " + name + "=\"" + value + "\""); } } catch (MalformedURLException ex) { System.err.println(ex); System.err.println(base); System.err.println(value); ex.printStackTrace(); } } }
From source file:dhtaccess.benchmark.ThroughputMeasure.java
private void start(boolean details, int repeats, int queryFreq, boolean doPut, String[] args) { this.repeats = repeats; // prepare for RPC int numAccessor = args.length; DHTAccessor[] accessorArray = new DHTAccessor[numAccessor]; try {//from w w w . j a v a2 s . c o m for (int i = 0; i < numAccessor; i++) { accessorArray[i] = new DHTAccessor(args[i]); } } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } // generate key prefix Random rnd = new Random(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < KEY_PREFIX_LENGTH; i++) { sb.append((char) ('a' + rnd.nextInt(26))); } String keyPrefix = sb.toString(); String valuePrefix = VALUE_PREFIX; // benchmarking System.out.println("Repeats " + repeats + " times."); System.out.println("Query frequency (times/sec): " + queryFreq); if (doPut) { System.out.println("Putting: " + keyPrefix + "<number>"); for (int i = 0; i < repeats; i++) { byte[] key = null, value = null; try { key = (keyPrefix + i).getBytes(ENCODE); value = (valuePrefix + i).getBytes(ENCODE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(1); } int accIndex = rnd.nextInt(numAccessor); DHTAccessor acc = accessorArray[accIndex]; acc.put(key, value, TTL); } } System.out.println("Benchmarking by getting."); System.out.println("(Start getting " + INITIAL_SLEEP + " msec later.)"); Timer timer = new Timer("Benchmark driving timer", false /* isDaemon */); this.count = this.repeats; this.startTime = System.currentTimeMillis() + INITIAL_SLEEP; for (int i = 0; i < repeats; i++) { byte[] key = null; try { key = (keyPrefix + i).getBytes(ENCODE); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.exit(1); } int accIndex = rnd.nextInt(numAccessor); DHTAccessor acc = accessorArray[accIndex]; TimerTask task = new GetQuerier(acc, key, details); timer.schedule(task, new Date(this.startTime + (long) (1000.0 * i / queryFreq))); } }