Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

In this page you can find the example usage for java.net URISyntaxException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:es.darkhogg.hazelnutt.Hazelnutt.java

/**
 * Tries to restart the application in at most <i>time</i> milliseconds for
 * every alive thread.// w w w. j  a v a2s  .  c  o m
 * 
 * @param time Number of milliseconds to wait for each thread to terminate
 * @return If something have happened before terminating the application
 */
public static boolean restart(long time) {
    Logger logger = getLogger();
    logger.info("Trying to restart application...");

    // Get the path to java executable
    File javaBinDir = new File(System.getProperty("java.home"), "bin");
    logger.debug("Java directory: '" + javaBinDir.getAbsolutePath() + "'");

    File[] possiblePaths = { new File(javaBinDir, "javaw.exe"), new File(javaBinDir, "java.exe"),
            new File(javaBinDir, "java") };
    File javaPath;
    int i = 0;
    do {
        javaPath = possiblePaths[i];
        i++;
    } while (i < possiblePaths.length && !javaPath.exists());
    logger.debug("Java executable: '" + javaPath.getAbsolutePath() + "'");

    // Get path to JAR
    File jarFile = null;
    try {
        jarFile = new File(Hazelnutt.class.getProtectionDomain().getCodeSource().getLocation().toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return false;
    }

    String[] command = null;
    if (!jarFile.isDirectory()) {
        logger.debug("JAR file: '" + jarFile.getAbsolutePath() + "'");
        command = new String[] { javaPath.getPath(), "-jar", jarFile.getPath() };
    } else {
        File classDir = jarFile;
        logger.debug("Class path: '" + classDir.getAbsolutePath() + "'");
        command = new String[] { javaPath.getPath(), "-classpath",
                jarFile.getPath() + ";.;" + System.getProperty("java.class.path"), Hazelnutt.class.getName() };
        System.out.println(
                "\"" + command[0] + "\" \"" + command[1] + "\" \"" + command[2] + "\" \"" + command[3] + "\"");
    }

    // Execute
    try {
        Runtime.getRuntime().exec(command);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    // Terminate this application
    terminate(time);
    return true;
}

From source file:org.cgiar.dapa.ccafs.tpe.util.Utils.java

public static Object loadJSONFile(String fileName) {

    File resource = null;/*from ww  w  .ja  v  a2  s  .  c  o  m*/
    try {
        resource = new File(Thread.currentThread().getContextClassLoader().getResource(fileName).toURI());
    } catch (URISyntaxException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    JSONParser parser = new JSONParser();
    Object json = null;
    try {
        json = parser.parse(new FileReader(resource));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return json;

}

From source file:gemlite.core.internal.support.system.ServerConfigHelper.java

public static void initLog4j(String configFile) {
    configFile = "log4j2-server.xml";
    if (getProperty(ITEMS.NODE_TYPE.name()) == null)
        setProperty("NODE_TYPE", "");
    if (getProperty(ITEMS.NODE_NAME.name()) == null)
        setProperty("NODE_NAME", "");
    String resolvedLocation = SystemPropertyUtils.resolvePlaceholders("log4j2-server.xml");

    URL url;//from   w w w  .j av  a2  s .co m
    try {
        url = ServerConfigHelper.class.getClassLoader().getResource(configFile);
        LoggerContext context = (LoggerContext) LogManager.getContext(false);
        context.setConfigLocation(url.toURI());
        LogUtil.init();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    // System.setProperty("log4j.configurationFile", configFile);

    // try
    // {
    // if (!configFile.startsWith("classpath"))
    // configFile = "classpath:" + configFile;
    // Log4jConfigurer.initLogging(configFile);
    // }
    // catch (FileNotFoundException e)
    // {
    // System.err.println("File " + configFile + " not exists!");
    // }
}

From source file:com.tinyhydra.botd.BotdServerOperations.java

public static void GetTopTen(final Activity activity, final Handler handler, boolean override) {
    final SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0);
    final List<JavaShop> TopTen = new ArrayList<JavaShop>();
    for (int i = 0; i < 10; i++) {
        TopTen.add(new JavaShop());
    }/*from  www  . ja va2s. c o  m*/
    if (settings.getLong(Const.LastTopTenQueryTime, 0) > (Calendar.getInstance().getTimeInMillis() - 180000)
            & !override) {
        Message msg = new Message();
        msg.arg1 = Const.CODE_GETTOPTEN;
        handler.sendMessage(msg);
    } else
        new Thread() {
            @Override
            public void run() {
                BufferedReader in = null;
                try {
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet();
                    request.setURI(new URI(activity.getResources().getString(R.string.server_url)));
                    HttpResponse response = client.execute(request);
                    in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";
                    while ((line = in.readLine()) != null) {
                        sb.append(line);
                    }
                    in.close();
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(Const.LastTopTenQueryResults, sb.toString());
                    editor.putLong(Const.LastTopTenQueryTime, Calendar.getInstance().getTimeInMillis());
                    editor.commit();

                    Message msg = new Message();
                    msg.arg1 = Const.CODE_GETTOPTEN;
                    handler.sendMessage(msg);

                    // more generic error handling
                    //TODO: implement better error handling
                } catch (URISyntaxException usex) {
                    usex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } catch (ClientProtocolException cpex) {
                    cpex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } catch (IOException iex) {
                    iex.printStackTrace();
                    Utils.PostToastMessageToHandler(handler,
                            "Unable to retrieve Brew of the day. Poor signal? Please try again",
                            Toast.LENGTH_LONG);
                } finally {
                    if (in != null) {
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }.start();
}

From source file:com.tinyhydra.botd.BotdServerOperations.java

public static void CastVote(final Activity activity, final Handler handler, final String email,
        final String shopId, final String shopRef) {
    new Thread() {
        @Override/*  w ww.ja  va  2  s .c o m*/
        public void run() {
            try {
                URI uri = new URI(activity.getResources().getString(R.string.server_url));
                HttpClient client = new DefaultHttpClient();
                HttpPut put = new HttpPut(uri);

                JSONObject voteObj = new JSONObject();

                // user's phone-account-email-address is used to prevent multiple votes
                // the server will validate. 'shopId' is a consistent id for a specific location
                // but can't be used to get more data. 'shopRef' is an id that changes based on
                // some criteria that google places has imposed, but will let us grab data later on
                // and various Ref codes with the same id will always resolve to the same location.
                voteObj.put(JSONvalues.email.toString(), email);
                voteObj.put(JSONvalues.shopId.toString(), shopId);
                voteObj.put(JSONvalues.shopRef.toString(), shopRef);
                put.setEntity(new StringEntity(voteObj.toString()));

                HttpResponse response = client.execute(put);
                InputStream is = response.getEntity().getContent();
                int ch;
                StringBuffer sb = new StringBuffer();
                while ((ch = is.read()) != -1) {
                    sb.append((char) ch);
                }
                if (sb.toString().equals("0")) {
                    Utils.PostToastMessageToHandler(handler, "Vote cast!", Toast.LENGTH_SHORT);
                    // Set a local flag to prevent duplicate voting
                    SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putLong(Const.LastVoteDate, Utils.GetDate());
                    editor.commit();
                } else {
                    // The user shouldn't see this. The above SharedPreferences code will be evaluated
                    // when the user hits the Vote button. If the user gets sneaky and deletes local data though,
                    // the server will catch the duplicate vote based on the user's email address and send back a '1'.
                    Utils.PostToastMessageToHandler(handler,
                            "Vote refused. You've probably already voted today.", Toast.LENGTH_LONG);
                }
                GetTopTen(activity, handler, true);
                // Catch blocks. Return a generic error if anything goes wrong.
                //TODO: implement some better/more appropriate error handling.
            } catch (URISyntaxException usex) {
                usex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (UnsupportedEncodingException ueex) {
                ueex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (ClientProtocolException cpex) {
                cpex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (IOException ioex) {
                ioex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (JSONException jex) {
                jex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            }
        }
    }.start();
}

From source file:org.mrgeo.utils.ClassLoaderUtil.java

public static List<URL> loadVfs(URL resource) throws IOException {
    List<URL> result = new LinkedList<URL>();

    try {//from   ww w.  ja v  a2  s. com
        VirtualFile r = VFS.getChild(resource.toURI());
        if (r.exists() && r.isDirectory()) {
            for (VirtualFile f : r.getChildren()) {
                result.add(f.asFileURL());
            }
        }
    } catch (URISyntaxException e) {
        System.out.println("Problem reading resource '" + resource + "':\n " + e.getMessage());
        e.printStackTrace();
    }

    return result;
}

From source file:com.teleca.jamendo.api.util.Caller.java

/**
 * Performs HTTP GET using Apache HTTP Client v 4
 * //from  w  w  w  . jav  a  2 s  .com
 * @param url
 * @return
 * @throws WSError 
 */
public static String doGet(String url) throws WSError {

    String data = null;
    if (requestCache != null) {
        data = requestCache.get(url);
        if (data != null) {
            Log.d(JamendoApplication.TAG, "Caller.doGet [cached] " + url);
            return data;
        }
    }

    URI encodedUri = null;
    HttpGet httpGet = null;

    try {
        encodedUri = new URI(url);
        httpGet = new HttpGet(encodedUri);
    } catch (URISyntaxException e1) {
        // at least try to remove spaces
        String encodedUrl = url.replace(' ', '+');
        httpGet = new HttpGet(encodedUrl);
        e1.printStackTrace();
    }

    // initialize HTTP GET request objects
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse;

    try {
        // execute request
        try {
            httpResponse = httpClient.execute(httpGet);
        } catch (UnknownHostException e) {
            throw new WSError("Unable to access " + e.getLocalizedMessage());
        } catch (SocketException e) {
            throw new WSError(e.getLocalizedMessage());
        }

        // request data
        HttpEntity httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            data = convertStreamToString(inputStream);
            // cache the result
            if (requestCache != null) {
                requestCache.put(url, data);
            }
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(JamendoApplication.TAG, "Caller.doGet " + url);
    return data;
}

From source file:net.dian1.player.api.util.Caller.java

/**
 * Performs HTTP GET using Apache HTTP Client v 4
 * //w ww.jav a 2s  .c  o m
 * @param url
 * @return
 * @throws WSError 
 */
public static String doGet(String url) throws WSError {

    String data = null;
    if (requestCache != null) {
        data = requestCache.get(url);
        if (data != null) {
            Log.d(Dian1Application.TAG, "Caller.doGet [cached] " + url);
            return data;
        }
    }

    URI encodedUri = null;
    HttpGet httpGet = null;

    try {
        encodedUri = new URI(url);
        httpGet = new HttpGet(encodedUri);
    } catch (URISyntaxException e1) {
        // at least try to remove spaces
        String encodedUrl = url.replace(' ', '+');
        httpGet = new HttpGet(encodedUrl);
        e1.printStackTrace();
    }

    // initialize HTTP GET request objects
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse;

    try {
        // execute request
        try {
            httpResponse = httpClient.execute(httpGet);
        } catch (UnknownHostException e) {
            throw new WSError("Unable to access " + e.getLocalizedMessage());
        } catch (SocketException e) {
            throw new WSError(e.getLocalizedMessage());
        }

        // request data
        HttpEntity httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            data = convertStreamToString(inputStream);
            // cache the result
            if (requestCache != null) {
                requestCache.put(url, data);
            }
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(Dian1Application.TAG, "Caller.doGet " + url);
    return data;
}

From source file:org.loklak.api.search.GithubProfileScraper.java

public static SusiThought scrapeGithub(String profile) {

    Document html = null;//from  w  w  w . j av a 2s . c o  m

    JSONObject githubProfile = new JSONObject();

    try {
        html = Jsoup.connect("https://github.com/" + profile).get();
    } catch (IOException e) {

        URI uri = null;
        try {
            uri = new URI("https://api.github.com/search/users?q=" + profile);
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }

        JSONTokener tokener = null;
        try {
            tokener = new JSONTokener(uri.toURL().openStream());
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        JSONObject obj = new JSONObject(tokener);

        JSONArray arr = new JSONArray();
        arr.put(obj);

        SusiThought json = new SusiThought();
        json.setData(arr);
        return json;
    }

    String avatarUrl = html.getElementsByAttributeValue("class", "avatar rounded-2").attr("src");
    githubProfile.put("avatar_url", avatarUrl);

    String fullName = html.getElementsByAttributeValue("class", "vcard-fullname").text();
    githubProfile.put("full_name", fullName);

    String userName = html.getElementsByAttributeValue("class", "vcard-username").text();
    githubProfile.put("user_name", userName);

    String bio = html.getElementsByAttributeValue("class", "user-profile-bio").text();
    githubProfile.put("bio", bio);

    String atomFeedLink = html.getElementsByAttributeValue("type", "application/atom+xml").attr("href");
    githubProfile.put("atom_feed_link", "https://github.com" + atomFeedLink);

    String worksFor = html.getElementsByAttributeValue("itemprop", "worksFor").text();
    githubProfile.put("works_for", worksFor);

    String homeLocation = html.getElementsByAttributeValue("itemprop", "homeLocation").attr("title");
    githubProfile.put("home_location", homeLocation);

    String email = html.getElementsByAttributeValue("itemprop", "email").text();
    githubProfile.put("email", email);

    String specialLink = html.getElementsByAttributeValue("itemprop", "url").text();
    githubProfile.put("special_link", specialLink);

    String joiningDate = html.getElementsByAttributeValue("class", "join-date").attr("datetime");
    githubProfile.put("joining_date", joiningDate);

    /* If Individual User */
    if (html.getElementsByAttributeValue("class", "vcard-stat").size() != 0) {

        String followersUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(0).attr("href");
        githubProfile.put("followers_url", "https://github.com" + followersUrl);

        String followers = html.getElementsByAttributeValue("class", "vcard-stat").get(0).tagName("strong")
                .text();
        githubProfile.put("followers", followers);

        String starredUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(1).attr("href");
        githubProfile.put("starred_url", "https://github.com" + starredUrl);

        String starred = html.getElementsByAttributeValue("class", "vcard-stat").get(1).tagName("strong")
                .text();
        githubProfile.put("starred", starred);

        String followingUrl = html.getElementsByAttributeValue("class", "vcard-stat").get(2).attr("href");
        githubProfile.put("following_url", "https://github.com" + followingUrl);

        String following = html.getElementsByAttributeValue("class", "vcard-stat").get(2).tagName("strong")
                .text();
        githubProfile.put("following", following);
    }

    String gistsUrl = "https://api.github.com/users/" + profile + "/gists";
    githubProfile.put("gists_url", gistsUrl);

    String subscriptionsUrl = "https://api.github.com/users/" + profile + "/subscriptions";
    githubProfile.put("subscriptions_url", subscriptionsUrl);

    String reposUrl = "https://api.github.com/users/" + profile + "/repos";
    githubProfile.put("repos_url", reposUrl);

    String eventsUrl = "https://api.github.com/users/" + profile + "/events";
    githubProfile.put("events_url", eventsUrl);

    String receivedEventsUrl = "https://api.github.com/users/" + profile + "/received_events";
    githubProfile.put("received_events_url", receivedEventsUrl);

    JSONArray organizations = new JSONArray();
    Elements orgs = html.getElementsByAttributeValue("itemprop", "follows");
    for (Element e : orgs) {
        JSONObject obj = new JSONObject();

        String label = e.attr("aria-label");
        obj.put("label", label);

        String link = e.attr("href");
        obj.put("link", "https://github.com" + link);

        String imgLink = e.children().attr("src");
        obj.put("img_link", imgLink);

        String imgAlt = e.children().attr("alt");
        obj.put("img_Alt", imgAlt);

        organizations.put(obj);
    }
    githubProfile.put("organizations", organizations);

    /* If Organization */
    Elements navigation = html.getElementsByAttributeValue("class", "orgnav");
    for (Element e : navigation) {
        String orgRepositoriesLink = e.child(0).tagName("a").attr("href");
        githubProfile.put("organization_respositories_link", "https://github.com" + orgRepositoriesLink);

        String orgPeopleLink = e.child(1).tagName("a").attr("href");
        githubProfile.put("organization_people_link", "https://github.com" + orgPeopleLink);

        String orgPeopleNumber = e.child(1).tagName("a").child(1).text();
        githubProfile.put("organization_people_number", orgPeopleNumber);
    }

    JSONArray jsonArray = new JSONArray();
    jsonArray.put(githubProfile);

    SusiThought json = new SusiThought();
    json.setData(jsonArray);
    return json;
}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static void openWebpage(URL url) {
    try {/*from w  w  w .  j  a v a  2s  .c  om*/
        openWebpage(url.toURI());
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}