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:org.matrix.androidsdk.rest.client.UrlPostTask.java

/**
 * Convert a stream to a string//from  w w  w  . j a  v  a2s  . c  o m
 * @param is the input stream to convert
 * @return the string
 */
private static String convertStreamToString(InputStream is) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "convertStreamToString " + e.getLocalizedMessage());
    } finally {
        try {
            is.close();
        } catch (Exception e) {
            Log.e(LOG_TAG, "convertStreamToString finally failed " + e.getLocalizedMessage());
        }
    }
    return sb.toString();
}

From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java

@SuppressLint("NewApi")

public static JsonNode performGET(String urlString) {
    JsonNode ret = null;/*from   w  w  w  . j  av a  2  s . com*/

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 20000);
    HttpConnectionParams.setSoTimeout(myParams, 20000);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    HttpGet httpget = null;

    URL url = null;

    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        LOG.d("Request " + url.toString());
        httpget.setHeader("Content-type", "application/json");
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("Response " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);

    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:it.geosolutions.geobatch.catalog.file.GeoBatchDataDirAwarePropertyOverrideConfigurer.java

/**
 * Tries to find the provided properties file and then returns its properties.
 * //from w  w  w.ja  v  a  2  s .  c  om
 * @param propertiesFile the {@link File} to load from. Must exists and be readable.
 * @throws IOException in case something bad happens trying to read the proeprties from the file.
 * 
 */
protected static Properties loadProperties(final File propertiesFile) throws IOException {
    // checks on provided file
    if (!(propertiesFile != null && propertiesFile.exists() && propertiesFile.isFile()
            && propertiesFile.canRead())) {
        return null;
    }
    // load the file
    InputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream(propertiesFile));
        final Properties properties = new Properties();
        properties.load(is);
        return properties;
    } finally {
        // close
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace(e.getLocalizedMessage(), e);
                }
            }
        }
    }
}

From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java

public static List<JsonNode> getKortforsyningenPlaces(Location currentLocation, Address address) {
    String urlString;/*from w  ww .java 2s . c  o  m*/
    List<JsonNode> list = new ArrayList<JsonNode>();
    if (!address.hasCity()) {
        // TODO: Seriously
        address.setCity(address.getStreet());
    }
    try {
        // TODO: Removed a wildcard
        String stednavn = URLEncoder.encode(address.getStreet(), "UTF-8") + "*";
        urlString = "https://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=stedv2&stednavn="
                + stednavn + "&geop=" + "" + Util.limitDecimalPlaces(currentLocation.getLongitude(), 6) + ","
                + "" + Util.limitDecimalPlaces(currentLocation.getLatitude(), 6)
                + "&georef=EPSG:4326&outgeoref=EPSG:4326&login=ibikecph&password=Spoiledmilk123&hits=10";

        // &distinct=true gave an error from the API
        // DB_SQL_PROBLEM. Error executing SQL: ERROR: syntax error at or near "stednavn" Position: 453

        JsonNode rootNode = performGET(urlString);
        if (rootNode.has("features")) {
            JsonNode features = rootNode.get("features");
            for (JsonNode featureNode : features) {
                if (featureNode.has("properties") && featureNode.get("properties").has("stednavneliste")
                        && featureNode.get("properties").size() > 0)
                    list.add(featureNode);
            }
        }
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return list;
}

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

public static boolean ConvertBase64ToImage(String Base64param, String filePath) {
    if (Base64param == null) // ??
    {/*  w  ww  .j  a  v  a2  s  .c  o m*/
        return false;
    }
    //BASE64Decoder decoder = new BASE64Decoder();
    try {
        byte[] data = Base64.decodeBase64(Base64param);
        try (OutputStream stream = new FileOutputStream(filePath)) {
            stream.write(data);
            stream.close();
        }
        return true;
    } catch (Exception e) {
        RSLogger.ErrorLogInfo(String.format("ConvertBase64ToImage error: %s", e.getLocalizedMessage()), e);
        return false;
    }

}

From source file:Main.java

public static byte[] getContents(Document document) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {/*from w  ww.  ja v  a 2 s  .  c  o m*/
        print(new PrintStream(out, true, "UTF-8"), document);
        return out.toByteArray();
    } catch (Exception ex) {
        throw new IOException(ex.getLocalizedMessage());
    } finally {
        if (out != null)
            try {
                out.close();
            } catch (Exception e) {
                // ignore
            }
    }
}

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

public static ArrayList<ITransportationInfo> getNext3Arrivals(String line, String startStation,
        String endStation, Context context) {
    ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>();
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("lines");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        if (lineJson.get("name").asText().contains(line)) {
            Calendar calendar = Calendar.getInstance();
            int day = calendar.get(Calendar.DAY_OF_WEEK);
            if (day == 1)
                day = 6;/*from   www.j  a v a 2 s . c om*/
            else
                day -= 2;
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);
            int period = 0, endTime = 0; // startTime
            try {
                if ((day == 4 || day == 5) && hour >= 0 && hour <= 7) { // Friday and Saturday night
                    period = lineJson.get("timetable").get("friday_saturday_night").get(0).get("period")
                            .asInt();
                    endTime = lineJson.get("timetable").get("friday_saturday_night").get(0).get("end_time")
                            .asInt();
                } else if ((day < 4 || day == 6) && hour >= 0 && hour <= 5) { // other days at night
                    JsonNode timetableNode = lineJson.get("timetable");
                    JsonNode timetableNodeContainer = timetableNode.get("sunday_thursday_night");
                    period = timetableNodeContainer.get(0).get("period").asInt();
                    endTime = timetableNodeContainer.get(0).get("end_time").asInt();
                } else {
                    JsonNode nodeRushour = lineJson.get("timetable").get("weekdays_rushour");
                    JsonNode nodeOutsideRushour = lineJson.get("timetable").get("weekdays_outside_rushour");
                    if ((day >= 0 && day < 5) && hour >= nodeRushour.get(0).get("start_time").asInt()
                            && hour < nodeRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeRushour.get(0).get("end_time").asInt();
                        period = nodeRushour.get(0).get("period").asInt();
                    } else if ((day >= 0 && day < 5) && hour >= nodeRushour.get(1).get("start_time").asInt()
                            && hour < nodeRushour.get(1).get("end_time").asInt()) {
                        endTime = nodeRushour.get(1).get("end_time").asInt();
                        period = nodeRushour.get(1).get("period").asInt();
                    } else if (hour >= nodeOutsideRushour.get(0).get("start_time").asInt()
                            && hour < nodeOutsideRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeOutsideRushour.get(0).get("end_time").asInt();
                        period = nodeOutsideRushour.get(0).get("period").asInt();
                    } else {
                        endTime = nodeOutsideRushour.get(1).get("end_time").asInt();
                        period = nodeOutsideRushour.get(1).get("period").asInt();
                    }

                }
                int currentHour = hour;
                int currentMinute = minute;
                int count = 0;
                period *= getTimeBetweenStations(line, startStation, endStation, context);
                while (count < 3) {
                    for (int k = 0; k < 60 && count < 3; k += period % 60) {
                        if (k >= currentMinute) {
                            currentMinute = k % 60;
                            currentHour += period / 60;
                            String arrivalTime = (currentHour < 10 ? "0" + currentHour : "" + currentHour) + ":"
                                    + (currentMinute < 10 ? "0" + currentMinute : "" + currentMinute);
                            int destHour = currentHour + period / 60;
                            int destMinute = currentMinute + period % 60;
                            if (destMinute > 59) {
                                destHour += destMinute / 60;
                                destMinute = destMinute % 60;
                            }
                            String destTime = (destHour < 10 ? "0" + destHour : "" + destHour) + ":"
                                    + (destMinute < 10 ? "0" + destMinute : "" + destMinute);
                            ret.add(new MetroData(arrivalTime, destTime, period));
                            count++;
                        }
                    }
                    currentMinute = 0;
                    if ((++currentHour) >= endTime)
                        break;
                }
            } catch (Exception e) {
                LOG.e(e.getLocalizedMessage());
            }
            break;
        }
    }
    return ret;
}

From source file:edu.du.penrose.systems.fedoraApp.tasks.WorkerFactory.java

/**
 * Return the worker specified in the remote task properties file ie {institution}_{batchSet}_REMOTE.properties, if there is problem log it and return null.
 * //  w w  w . j a v  a2s  . c  o  m
 * @see FedoraAppConstants#REMOTE_TASK_WORKER_CLASS_PROPERTY
 * 
 * @param batchSetName is of type codu_ectd where codu is the institution and ectd is the batch set name
 * @return the worker object or null.
 */
public static WorkerInf getWorker(String batchSetName) {
    String[] tempArray = batchSetName.split("_");
    String institution = tempArray[0];
    String batchSet = tempArray[1];
    WorkerInf myWorkerObject = null;
    String propertiesFileName = null;
    String workerClassName = null;

    try {
        if (batchSetName.endsWith(FedoraAppConstants.REMOTE_TASK_NAME_SUFFIX)) {
            propertiesFileName = FedoraAppConstants.getServletContextListener().getInstituionURL().getFile()
                    + institution + "/" + batchSet + "/" + batchSet + FedoraAppConstants.REMOTE_TASK_NAME_SUFFIX
                    + ".properties";
        } else {
            propertiesFileName = FedoraAppConstants.getServletContextListener().getInstituionURL().getFile()
                    + institution + "/" + batchSet + "/" + batchSet
                    + FedoraAppConstants.BACKGROUND_TASK_NAME_SUFFIX + ".properties";
        }

        ProgramProperties optionsProperties = new ProgramFileProperties(new File(propertiesFileName));

        if (batchSetName.endsWith(FedoraAppConstants.REMOTE_TASK_NAME_SUFFIX)) {
            workerClassName = optionsProperties
                    .getProperty(FedoraAppConstants.REMOTE_TASK_WORKER_CLASS_PROPERTY);
        } else {
            workerClassName = optionsProperties.getProperty(FedoraAppConstants.TASK_WORKER_CLASS_PROPERTY);
        }

        if (workerClassName == null || workerClassName.length() == 0) {
            logger.error("Unable to find ingest class in" + propertiesFileName);
            return null;
        }

        Constructor<?> workerConsctuctor = Class.forName(workerClassName).getConstructor(String.class);
        myWorkerObject = (WorkerInf) workerConsctuctor.newInstance(batchSetName);
    } catch (Exception e) {
        logger.error("Unable to find ingest class for instituion_batchSet:" + institution + ", " + batchSet
                + "  :" + e.getLocalizedMessage());
        return null;
    }

    return myWorkerObject;
}

From source file:com.mission_base.arviewer_android.viewer.ArvosAugment.java

/**
 * Parses the JSON format augment list downloaded from the web.
 * /*from  w  w w .j av  a2 s.c  o m*/
 * @param input
 *            The input in JSON format.
 * @param result
 *            The list of augments to parse to.
 * @return "OK" or "ER" followed by the error message.
 */
public static String parse(String input, List<ArvosAugment> result) {
    try {
        JSONObject jsonAugmentsList = new JSONObject(input);
        if (jsonAugmentsList.has("redirect")) {
            String redirectUrl = jsonAugmentsList.getString("redirect");
            if (redirectUrl != null) {
                redirectUrl = redirectUrl.trim();
                if (redirectUrl.length() > 0) {
                    return "RD" + redirectUrl;
                }
            }
        }

        if (jsonAugmentsList.has("sessionId")) {
            String sessionId = jsonAugmentsList.getString("sessionId");
            if (sessionId != null) {
                sessionId = sessionId.trim();
                if (sessionId.length() > 0) {
                    Arvos.getInstance().mSessionId = sessionId;
                }
            }
        }

        JSONArray jsonAugments = new JSONArray(jsonAugmentsList.getString("augments"));

        if (jsonAugments == null || jsonAugments.length() == 0) {
            return "ERNo augments found at your location. Retry ...";
        }

        for (int i = 0; i < jsonAugments.length(); i++) {
            JSONObject jsonAugment = jsonAugments.getJSONObject(i);
            if (jsonAugment != null) {
                ArvosAugment augment = new ArvosAugment();
                result.add(augment);

                augment.mName = jsonAugment.getString("name");
                augment.mUrl = jsonAugment.getString("url");

                augment.mAuthor = jsonAugment.has("author") ? jsonAugment.getString("author") : "";
                augment.mLatitude = (float) (jsonAugment.has("lat") ? jsonAugment.getDouble("lat") : 0f);
                augment.mLongitude = (float) (jsonAugment.has("lon") ? jsonAugment.getDouble("lon") : 0f);
                augment.mDescription = jsonAugment.has("description") ? jsonAugment.getString("description")
                        : "";
                augment.mDeveloperKey = jsonAugment.has("developerKey") ? jsonAugment.getString("developerKey")
                        : "";
            }
        }
    } catch (Exception e) {
        return "ERJSON parse error. " + e.getLocalizedMessage();
    }

    return "OK";
}

From source file:Main.java

public static void save(String filename, Node node) throws IOException {
    PrintStream out = null;//ww  w. jav  a2  s. co  m
    try {
        out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8");
        print(out, node);
    } catch (Exception ex) {
        throw new IOException(ex.getLocalizedMessage());
    } finally {
        if (out != null)
            try {
                out.close();
            } catch (Exception e) {
                // ignore
            }
    }
}