Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Exception getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:Main.java

static void invokeAndWait(Runnable task) {
    if (SwingUtilities.isEventDispatchThread()) {
        task.run();//from   ww  w  .java  2  s .com
    } else {
        try {
            SwingUtilities.invokeAndWait(task);
        } catch (Exception ex) {
            ex.printStackTrace();
            ex.getLocalizedMessage();
        }
    }
}

From source file:Main.java

public static JSONObject callService(String url) {
    InputStream inputStream = null;
    JSONObject result = null;//from   w w w . j  a v  a2s  . c  om
    try {
        // create HttpClient
        HttpClient httpclient = new DefaultHttpClient();
        // make GET request to the given URL
        HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
        // receive response as inputStream
        inputStream = httpResponse.getEntity().getContent();
        // convert inputstream to string
        if (inputStream != null) {
            String response = convertInputStreamToString(inputStream);
            //result = new JSONObject(response);
        }
    } catch (Exception e) {
        Log.d("InputStream", e.getLocalizedMessage());
    }
    return result;
}

From source file:editor.util.URLUtil.java

public static String readText(String uri) {
    String res = "";
    try {//w  ww.  j  a  v a  2s. co m
        java.net.URL url = new java.net.URL(uri);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream in = connection.getInputStream();
        byte buff[] = new byte[200];
        int ch;
        while ((ch = in.read(buff)) != -1)
            res += new String(buff, 0, ch);
        in.close();

        return res;
    } catch (Exception e) {
        return e.getLocalizedMessage();
    }
}

From source file:org.openlmis.performancetesting.Properties.java

public static int getInteger(String key) {
    String strValue = getString(key);
    int result = -1;
    try {//from  w ww  .  j  ava 2s.co m
        result = parseInt(strValue);
    } catch (Exception exc) {
        logger.error(exc.getLocalizedMessage());
    }
    return result;
}

From source file:io.ucoin.ucoinj.elasticsearch.util.Desktop.java

public static DesktopPower getDesktopPower() {
    if (desktopPower == null) {

        if (SystemUtils.IS_OS_WINDOWS) {
            // All Windows version are handled with WindowsPower class
            try {
                desktopPower = new WindowsPower();
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
            }//from ww w . ja v  a2  s  . c  o m

        } else if (SystemUtils.IS_OS_LINUX) {

            // TODO create a Linux/UnixPower because (for example) Kubuntu sends KILL signal when it shutdown, it should sent TERM !!
        }

    }

    return desktopPower;
}

From source file:Main.java

public static String GET(String url) {
    InputStream inputStream = null;
    String result = "";
    try {/*from   ww w . j  a v  a  2  s .  c  o  m*/

        // create HttpClient
        HttpClient httpclient = new DefaultHttpClient();

        // make GET request to the given URL
        HttpResponse httpResponse = httpclient.execute(new HttpGet(url));

        // receive response as inputStream
        inputStream = httpResponse.getEntity().getContent();

        // convert inputstream to string
        if (inputStream != null)
            result = convertInputStreamToString(inputStream);
        else
            result = "Did not work!";

    } catch (Exception e) {
        Log.d("InputStream", e.getLocalizedMessage());
    }

    return result;
}

From source file:com.codingrhemes.steamsalesmobile.HttpThumbnails.java

public static Bitmap readPictureFromTheWeb(String URL) {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    Bitmap thePicture = null;//www .  ja  va 2 s .  co m

    try {

        HttpResponse response = httpClient.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream inputStream = entity.getContent();
            thePicture = BitmapFactory.decodeStream(inputStream);
            inputStream.close();
        } else {
            Log.d("JSON", "Failed to download file");
        }
    } catch (Exception e) {
        Log.d("HttpThumbnails", e.getLocalizedMessage());
    }
    return thePicture;
}

From source file:Main.java

private static void ensureHttpClient() {
    if (httpClient != null)
        return;/*from w  w w  . j a v a 2  s .  c  o m*/

    BasicHttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 45000);
    HttpConnectionParams.setSoTimeout(params, 30000);

    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", new PlainSocketFactory(), 80));
    try {
        registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    } catch (Exception e) {
        Log.w(TAG, "Unable to register HTTPS socket factory: " + e.getLocalizedMessage());
    }

    ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, registry);
    httpClient = new DefaultHttpClient(connManager, params);
}

From source file:eu.morfeoproject.fast.catalogue.ontologies.OntologyFetcher.java

private static URI getOntologyUri(InputStream in, Syntax syntax) {
    try {/*from  w  w w. jav a 2s.c  o m*/
        Model model = RDF2Go.getModelFactory().createModel();
        model.open();
        model.readFrom(in, syntax);
        ClosableIterator<Statement> cIt = model.findStatements(Variable.ANY, RDF.type, OWL.Ontology);
        URI oUri = cIt.hasNext() ? cIt.next().getSubject().asURI() : null;
        cIt.close();
        model.close();
        return oUri;
    } catch (Exception e) {
        log.error(e.getLocalizedMessage(), e);
    }
    return null;
}

From source file:BareBonesBrowserLaunch.java

public static void openURL(String url) {
    String osName = System.getProperty("os.name");
    try {/*  ww w  .jav a  2 s.  com*/
        if (osName.startsWith("Mac OS")) {
            Class fileMgr = Class.forName("com.apple.eio.FileManager");
            Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
            openURL.invoke(null, new Object[] { url });
        } else if (osName.startsWith("Windows"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        else { //assume Unix or Linux
            String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
            String browser = null;
            for (int count = 0; count < browsers.length && browser == null; count++)
                if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0)
                    browser = browsers[count];
            if (browser == null)
                throw new Exception("Could not find web browser");
            else
                Runtime.getRuntime().exec(new String[] { browser, url });
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
    }
}