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

/**
 * Returns a namespaced root element of a document
 * Useful to create a namespace holder element
 * @param namespace//w  ww.  j  a  v a 2s  .  co m
 * @return the root Element
 */
public static Element getRootElement(String elementName, String namespace, String prefix)
        throws TransformerException {
    Element rootNS = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        DOMImplementation impl = builder.getDOMImplementation();
        Document namespaceHolder = impl.createDocument(namespace,
                (prefix == null ? "" : prefix + ":") + elementName, null);
        rootNS = namespaceHolder.getDocumentElement();
        rootNS.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, namespace);
    } catch (Exception e) {
        String err = "Error creating a namespace holder document: " + e.getLocalizedMessage();
        throw new TransformerException(err);
    }
    return rootNS;
}

From source file:com.jkoolcloud.tnt4j.streams.sample.custom.SampleIntegration.java

/**
 * The following can be used if using the default configuration file with a single stream.
 *
 * @param cfgFileName//from w w w  .j a  v  a 2s.c o  m
 *            configuration file name
 */
public static void simpleConfigAndRun(String cfgFileName) {
    try {
        StreamsConfigLoader cfg = new StreamsConfigLoader();
        TNTInputStream<?, ?> stream = cfg.getStream("StreamName"); // NON-NLS
        StreamThread ft = new StreamThread(stream);
        ft.start();
    } catch (Exception e) {
        LOGGER.log(OpLevel.ERROR, String.valueOf(e.getLocalizedMessage()), e);
    }
}

From source file:com.klinker.android.dream.util.NetworkUtils.java

/**
 * Get a JSON string from the given url//from  www  .j  av a2 s .  c o  m
 * @param url the url where the JSON is located
 * @return the String in the format of a JSON
 */
public static String getJsonString(String url) {
    InputStream inputStream;
    String result = "";

    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
        inputStream = httpResponse.getEntity().getContent();
        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.jkoolcloud.tnt4j.streams.sample.custom.SampleIntegration.java

/**
 * Configure streams and parsers, and run each stream in its own thread.
 *
 * @param cfgFileName/*from  w  ww.java 2 s  .  c  o  m*/
 *            configuration file name
 */
public static void loadConfigAndRun(String cfgFileName) {
    try {
        StreamsConfigLoader cfg = StringUtils.isEmpty(cfgFileName) ? new StreamsConfigLoader()
                : new StreamsConfigLoader(cfgFileName);
        Collection<TNTInputStream<?, ?>> streams = cfg.getStreams();
        if (streams == null || streams.isEmpty()) {
            throw new IllegalStateException("No Activity Streams found in configuration"); // NON-NLS
        }

        ThreadGroup streamThreads = new ThreadGroup("Streams"); // NON-NLS
        StreamThread ft;
        for (TNTInputStream<?, ?> stream : streams) {
            ft = new StreamThread(streamThreads, stream,
                    String.format("%s:%s", stream.getClass().getSimpleName(), stream.getName())); // NON-NLS
            ft.start();
        }
    } catch (Exception e) {
        LOGGER.log(OpLevel.ERROR, String.valueOf(e.getLocalizedMessage()), e);
    }
}

From source file:BrowserLauncher.java

public static void openURL(String url) {
    int os = PlatformDetector.detect();

    try {//from   www . j  a  v a2 s  .  c  o  m
        if (os == PlatformDetector.MACOS) {
            Class macUtils = Class.forName("com.apple.mrj.MRJFileUtils");
            Method openURL = macUtils.getDeclaredMethod("openURL", new Class[] { String.class });
            openURL.invoke(null, new Object[] { url });
        } else if (os == PlatformDetector.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());
    }
}

From source file:Main.java

public static void printCallPathTop(String text) {
    try {//from  w ww  .ja v a 2 s.c o  m
        throw new Exception(text);
    } catch (Exception e) {
        StackTraceElement[] l = e.getStackTrace();
        System.out.println(
                "DDTrace: [" + e.getLocalizedMessage() + "] " + l[1] + "\n" + l[2] + "\n" + l[l.length - 1]);
    }
}

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

public static String readJSONFeed(String URL) {
    StringBuilder stringBuilder = new StringBuilder();
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    try {// w  w  w .  ja  va 2  s  . c o m
        HttpResponse response = httpClient.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream inputStream = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
            inputStream.close();
        } else {
            Log.d("JSON", "Failed to download file");
        }
    } catch (Exception e) {
        Log.d("readJSONFeed", e.getLocalizedMessage());
    }
    return stringBuilder.toString();
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java

private static int getTimeBetweenStations(String line, String startStation, String endStation,
        Context context) {/*  www . j  a  va 2s  . c  o  m*/
    int ret = 1;
    try {
        String bufferString = Util.stringFromJsonAssets(context, "stations/metro_stations.json");
        JsonNode actualObj = Util.stringToJsonNode(bufferString);
        JsonNode stationsNode = line.contains("M1") ? actualObj.get("M1") : actualObj.get("M2");
        int i1 = 0, i2 = 1;
        for (int i = 0; i < stationsNode.size(); i++) {
            if (stationsNode.get(i).get("name").asText().equals(startStation))
                i1 = i;
            else if (stationsNode.get(i).get("name").asText().equals(endStation))
                i2 = i;
        }
        ret = Math.abs(i2 - i1);
    } catch (Exception e) {
        LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.movies.jsf.JsfUtil.java

public static void ensureAddErrorMessage(Exception ex, String defaultMsg) {
    String msg = ex.getLocalizedMessage();
    if (msg != null && msg.length() > 0) {
        addErrorMessage(msg);//w w  w.  j  a va  2 s  .c  o m
    } else {
        addErrorMessage(defaultMsg);
    }
}

From source file:com.smart.common.FileHelper.java

/**
 * ?//  w  ww. j  a  v  a 2s  . co  m
 *
 * @param filePath 
 * @param isCreate ?
 * @return
 * @throws java.lang.Exception
 */
public static boolean CheckFileExist(String filePath, boolean isCreate) throws Exception {
    try {
        File file = new File(filePath);
        if (!file.exists()) {
            if (isCreate) {
                file.mkdir();
            }
            return false;
        } else {
            return true;
        }
    } catch (Exception e) {
        throw new Exception(e.getLocalizedMessage());
    }
}