Example usage for java.text ParseException toString

List of usage examples for java.text ParseException toString

Introduction

In this page you can find the example usage for java.text ParseException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.artifactory.ui.rest.service.builds.buildsinfo.tabs.licenses.OverrideSelectedLicensesService.java

@Override
public void execute(ArtifactoryRestRequest request, RestResponse response) {
    try {//from   w w  w. j a  v a  2 s  .com
        BuildLicenseModel buildLicenseModel = (BuildLicenseModel) request.getImodel();
        String name = request.getPathParamByKey("name");
        String buildNumber = request.getPathParamByKey("number");
        String buildStarted = DateUtils.formatBuildDate(Long.parseLong(request.getPathParamByKey("date")));
        // get license-repo map
        Build build = getBuild(name, buildNumber, buildStarted, response);
        Multimap<RepoPath, ModuleLicenseModel> repoPathLicenseMultimap = getRepoPathLicenseModuleModelMultimap(
                build);
        // update licenses
        updateLicenses(buildLicenseModel.getLicenses(), repoPathLicenseMultimap, response);
    } catch (ParseException e) {
        response.error("error updating licenses");
        log.error(e.toString());
    }
}

From source file:org.montanafoodhub.base.get.OrderHub.java

protected List<Order> readFromFile(Context context) {
    List<Order> myOrderArr = new ArrayList<Order>();
    try {/*from www  .  j  a  v a  2s .  c o  m*/
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // create products from the file here
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(myOrderArr, inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    } catch (ParseException pe) {
        Log.e(HubInit.logTag, "Can't parse Order date  (" + fileName + ") : " + pe.toString());
    }
    Log.w(HubInit.logTag, "Number of orders loaded: " + myOrderArr.size());
    return myOrderArr;
}

From source file:org.apache.ws.security.util.XmlSchemaDateFormat.java

/**
 * This method was snarfed from <tt>org.apache.axis.encoding.ser.CalendarDeserializer</tt>,
 * which was written by Sam Ruby (rubys@us.ibm.com) and Rich Scheuerle (scheu@us.ibm.com).
 * Better error reporting was added./*from  ww  w .  java  2 s. co  m*/
 *
 * @see DateFormat#parse(java.lang.String)
 */
public Date parse(String src, ParsePosition parse_pos) {
    Date date;

    // validate fixed portion of format
    int index = 0;
    try {
        if (src != null) {
            if ((src.charAt(0) == '+') || (src.charAt(0) == '-')) {
                src = src.substring(1);
            }

            if (src.length() < 19) {
                parse_pos.setIndex(src.length() - 1);
                handleParseError(parse_pos, "TOO_FEW_CHARS");
            }
            validateChar(src, parse_pos, index = 4, '-', "EXPECTED_DASH");
            validateChar(src, parse_pos, index = 7, '-', "EXPECTED_DASH");
            validateChar(src, parse_pos, index = 10, 'T', "EXPECTED_CAPITAL_T");
            validateChar(src, parse_pos, index = 13, ':', "EXPECTED_COLON_IN_TIME");
            validateChar(src, parse_pos, index = 16, ':', "EXPECTED_COLON_IN_TIME");
        }

        // convert what we have validated so far
        try {
            synchronized (DATEFORMAT_XSD_ZULU) {
                date = DATEFORMAT_XSD_ZULU.parse((src == null) ? null : (src.substring(0, 19) + ".000Z"));
            }
        } catch (Exception e) {
            throw new NumberFormatException(e.toString());
        }

        index = 19;

        // parse optional milliseconds
        if (src != null) {
            if ((index < src.length()) && (src.charAt(index) == '.')) {
                int milliseconds = 0;
                int start = ++index;

                while ((index < src.length()) && Character.isDigit(src.charAt(index))) {
                    index++;
                }

                String decimal = src.substring(start, index);

                if (decimal.length() == 3) {
                    milliseconds = Integer.parseInt(decimal);
                } else if (decimal.length() < 3) {
                    milliseconds = Integer.parseInt((decimal + "000").substring(0, 3));
                } else {
                    milliseconds = Integer.parseInt(decimal.substring(0, 3));

                    if (decimal.charAt(3) >= '5') {
                        ++milliseconds;
                    }
                }

                // add milliseconds to the current date
                date.setTime(date.getTime() + milliseconds);
            }

            // parse optional timezone
            if (((index + 5) < src.length()) && ((src.charAt(index) == '+') || (src.charAt(index) == '-'))) {
                validateCharIsDigit(src, parse_pos, index + 1, "EXPECTED_NUMERAL");
                validateCharIsDigit(src, parse_pos, index + 2, "EXPECTED_NUMERAL");
                validateChar(src, parse_pos, index + 3, ':', "EXPECTED_COLON_IN_TIMEZONE");
                validateCharIsDigit(src, parse_pos, index + 4, "EXPECTED_NUMERAL");
                validateCharIsDigit(src, parse_pos, index + 5, "EXPECTED_NUMERAL");

                final int hours = (((src.charAt(index + 1) - '0') * 10) + src.charAt(index + 2)) - '0';
                final int mins = (((src.charAt(index + 4) - '0') * 10) + src.charAt(index + 5)) - '0';
                int millisecs = ((hours * 60) + mins) * 60 * 1000;

                // subtract millisecs from current date to obtain GMT
                if (src.charAt(index) == '+') {
                    millisecs = -millisecs;
                }

                date.setTime(date.getTime() + millisecs);
                index += 6;
            }

            if ((index < src.length()) && (src.charAt(index) == 'Z')) {
                index++;
            }

            if (index < src.length()) {
                handleParseError(parse_pos, "TOO_MANY_CHARS");
            }
        }
    } catch (ParseException pe) {
        log.error(pe.toString(), pe);
        index = 0; // IMPORTANT: this tells DateFormat.parse() to throw a ParseException
        parse_pos.setErrorIndex(index);
        date = null;
    }
    parse_pos.setIndex(index);
    return (date);
}

From source file:com.vip.saturn.job.console.controller.JobController.java

@RequestMapping(value = "checkAndForecastCron", method = RequestMethod.POST)
public RequestResult checkAndForecastCron(final String cron, HttpServletRequest request) {
    RequestResult result = new RequestResult();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    if (cron != null && !cron.trim().isEmpty()) {
        try {/*from   www .j av a2  s .  co  m*/
            CronExpression cronExpression = new CronExpression(cron.trim());
            StringBuilder sb = new StringBuilder(100);
            Date date = new Date();
            for (int i = 0; i < 10; i++) {
                Date next = cronExpression.getNextValidTimeAfter(date);
                if (next != null) {
                    sb.append(dateFormat.format(next)).append("<br>");
                    date = next;
                }
            }
            result.setSuccess(true);
            if (sb.length() == 0) {
                result.setMessage("Cron maybe describe the past time, the job will never be executed");
            } else {
                if (sb.toString().split("<br>") != null && sb.toString().split("<br>").length >= 10) {
                    sb.append("......");
                }
                result.setMessage(sb.toString());
            }
        } catch (ParseException e) {
            result.setSuccess(false);
            result.setMessage(e.toString());
            return result;
        }
    } else {
        result.setSuccess(false);
        result.setMessage("Cron cannot be null or empty");
    }
    return result;
}

From source file:de.teambluebaer.patientix.activities.StartActivity.java

/**
 * This Method refactors the spelling of the date.
 *
 * @return String of german formated date.
 *///from  w  ww . ja v  a  2 s .  c  o m

private String getbirthDate() {
    String birthDate = "";
    try {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
        Date date = dateFormat.parse(Constants.GLOBALMETAANDFORM.getMeta().getPatientBithDate());
        SimpleDateFormat dt1 = new SimpleDateFormat("dd.mm.yyyy");
        birthDate = dt1.format(date);
    } catch (ParseException ex2) {
        Log.d("DateParseFail", ex2.toString());
    }
    return birthDate;
}

From source file:com.windroilla.invoker.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//from w  w w. j av a  2s .  c o  m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        Log.i("Device ID ", deviceID);
        // normal downstream message.
        apiService.getBlockTimes(new RequestBlockTimes(deviceID)).subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.newThread()).subscribe(new Action1<BlockTimeList>() {
                    @Override
                    public void call(BlockTimeList blockTimeList) {
                        Log.d(TAG, blockTimeList.access_time);
                        Vector<ContentValues> cVVector = new Vector<ContentValues>(
                                blockTimeList.getBlockTimes().size());
                        AlarmManager mgrAlarm = (AlarmManager) getApplicationContext()
                                .getSystemService(ALARM_SERVICE);
                        ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        formatter.setLenient(false);

                        for (int i = 0; i < blockTimeList.getBlockTimes().size(); i++) {
                            BlockTime blockTime = blockTimeList.getBlockTimes().get(i);
                            Log.d(TAG,
                                    blockTime.getCourse_id() + " " + blockTime.getId() + " "
                                            + blockTime.getStarttime() + " " + blockTime.getEndtime() + " "
                                            + blockTime.getCreated_time());
                            ContentValues blockTimeValues = new ContentValues();
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_START_TIME,
                                    blockTime.getStarttime());
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_END_TIME,
                                    blockTime.getEndtime());
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_CREATED_TIME,
                                    blockTime.getCreated_time());
                            Intent startIntent = new Intent(getBaseContext(), AlarmReceiver.class);
                            startIntent.setAction("com.windroilla.invoker.blockservice.start");
                            Intent endIntent = new Intent(getBaseContext(), AlarmReceiver.class);
                            endIntent.setAction("com.windroilla.invoker.blockservice.stop");
                            PendingIntent pendingStartIntent = PendingIntent.getBroadcast(
                                    getApplicationContext(), blockTime.getId(), startIntent,
                                    PendingIntent.FLAG_UPDATE_CURRENT);
                            PendingIntent pendingEndIntent = PendingIntent.getBroadcast(getApplicationContext(),
                                    -blockTime.getId(), endIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            try {
                                mgrAlarm.set(AlarmManager.RTC_WAKEUP,
                                        formatter.parse(blockTime.getStarttime()).getTime(),
                                        pendingStartIntent);
                                Log.d(TAG,
                                        formatter.parse(blockTime.getStarttime()).getTime() + " "
                                                + System.currentTimeMillis() + " "
                                                + (formatter.parse(blockTime.getStarttime()).getTime()
                                                        - System.currentTimeMillis()));
                                Log.d(TAG,
                                        formatter.parse(blockTime.getEndtime()).getTime() + " "
                                                + System.currentTimeMillis() + " "
                                                + (formatter.parse(blockTime.getEndtime()).getTime()
                                                        - System.currentTimeMillis()));
                                mgrAlarm.set(AlarmManager.RTC_WAKEUP,
                                        formatter.parse(blockTime.getEndtime()).getTime(), pendingEndIntent);
                            } catch (ParseException e) {
                                Log.e(TAG, e.toString());
                            }
                            intentArray.add(pendingStartIntent);
                            intentArray.add(pendingEndIntent);
                            cVVector.add(blockTimeValues);
                        }
                        Log.d(TAG, intentArray.size() + " PendingIntents have been progressed");
                        int inserted = 0;
                        // add to database
                        if (cVVector.size() > 0) {
                            ContentValues[] cvArray = new ContentValues[cVVector.size()];
                            cVVector.toArray(cvArray);
                            getBaseContext().getContentResolver()
                                    .bulkInsert(BlocktimeContract.BlocktimeEntry.CONTENT_URI, cvArray);
                        }

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "BlockTimes Sync failed! " + throwable);
                    }
                });

    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(message);
    // [END_EXCLUDE]
}

From source file:com.bringcommunications.etherpay.HistoryActivity.java

private int set_transactions(String rsp) {
    //typical response id:
    //{/*from w  w w .ja  va  2 s .c  om*/
    //  "status": 1,
    //  "data": [
    //    {
    //      "hash": "0x1b3dca103e0605b45f81eede754401df4082b87c4faf3f1205755b36f1b34ddf",
    //      "sender": "0x8b8a571730b631f58e7965d78582eae1b0417ab6",
    //      "recipient": "0x85d9147b0ec6d60390c8897244d039fb55b087c6",
    //      "accountNonce": "76",
    //      "price": 25000000000,
    //      "gasLimit": 35000,
    //      "amount": 2000000108199936,
    //      "block_id": 2721132,
    //      "time": "2016-11-30T09:58:07.000Z",
    //      "newContract": 0,
    //      "isContractTx": null,
    //      "blockHash": "0x5c1118c94176902cab1783f8d4f8d17544c7a16c8ef377f674fa89693eb3ab0c",
    //      "parentHash": "0x1b3dca103e0605b45f81eede754401df4082b87c4faf3f1205755b36f1b34ddf",
    //      "txIndex": null,
    //      "gasUsed": 21000,
    //      "type": "tx"
    //      },
    //      .....
    //   }
    int idx = 0;
    int status = 0;
    int no_transactions = 0;
    if (rsp.contains("status")) {
        int field_idx = rsp.indexOf("status") + "status".length();
        int beg_idx = rsp.indexOf(':', field_idx) + 1;
        int end_idx = rsp.indexOf(',', beg_idx);
        status = Integer.valueOf(rsp.substring(beg_idx, end_idx).trim());
        idx = end_idx + 1;
    }
    if (status != 1) {
        Util.show_err(getBaseContext(), "error retrieving transactions!", 3);
        Util.show_err(getBaseContext(), rsp.substring(0, 30), 10);
        return (0);
    }
    rsp = rsp.substring(idx);
    idx = 0;
    for (int i = 0; i < 100; ++i) {
        if (rsp.contains("{")) {
            idx = rsp.indexOf('{') + 1;
            rsp = rsp.substring(idx);
        } else {
            break;
        }
        ++no_transactions;
        String txid = "";
        String from = "";
        String to = "";
        long nonce = 0;
        float size = 0;
        Calendar date = Calendar.getInstance();
        if (rsp.contains("hash")) {
            int field_idx = rsp.indexOf("hash") + "hash".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            txid = rsp.substring(beg_idx, end_idx).replaceAll("\"", "").trim();
        }
        if (rsp.contains("sender")) {
            int field_idx = rsp.indexOf("sender") + "sender".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            from = rsp.substring(beg_idx, end_idx).replace("\"", "").trim();
            if (!show_sent && from.equals(acct_addr))
                continue;
        }
        if (rsp.contains("recipient")) {
            int field_idx = rsp.indexOf("recipient") + "recipient".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            to = rsp.substring(beg_idx, end_idx).replace("\"", "").trim();
            if (!show_received && to.equals(acct_addr))
                continue;
        }
        if (rsp.contains("accountNonce")) {
            int field_idx = rsp.indexOf("accountNonce") + "accountNonce".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            nonce = Long.valueOf(rsp.substring(beg_idx, end_idx).replace("\"", "").trim());
        }
        if (rsp.contains("amount")) {
            int field_idx = rsp.indexOf("amount") + "amount".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            long wei_amount = Long.valueOf(rsp.substring(beg_idx, end_idx).trim());
            size = wei_amount / WEI_PER_ETH;
        }
        if (rsp.contains("time")) {
            int field_idx = rsp.indexOf("time") + "time".length();
            int beg_idx = rsp.indexOf(':', field_idx) + 1;
            int end_idx = rsp.indexOf(',', beg_idx);
            String date_str = rsp.substring(beg_idx, end_idx).replace("\"", "").trim();
            //System.out.println("raw date: " + created_at);
            //could the date string have more or less than 3 digits after the decimal? (eg 5: 2015-11-10T01:20:14.16525Z). to avoid
            //complication, (and parse exceotions) we always force 3.
            int decimal_idx = date_str.indexOf(".");
            String conforming_date_str = date_str;
            if (decimal_idx < 0)
                System.out.println("hey! no decimal in date string: " + conforming_date_str);
            if (decimal_idx >= 0) {
                //decimal_idx is idx of decimal point. add 1 to get len, and we need 3 more digits (followed by 'Z')
                if (date_str.length() >= decimal_idx + 5)
                    //substring includes end_idx -1
                    conforming_date_str = date_str.substring(0, decimal_idx + 4) + "Z";
                else
                    conforming_date_str = date_str.substring(0, decimal_idx) + ".000Z";
            }
            //in java 7, an 'X' in the dateformat indicates that the date string might contain an ISO8601 suffix, eg. Z for UTC.
            //unfortunately that doesn't work for android. a 'Z' in the dateformat indicates that the timezone conforms to the RFC822
            //time zone standard, e.g. -0800. so we'll just convert to that.
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            conforming_date_str = conforming_date_str.replaceAll("Z$", "+0000");
            try {
                date.setTime(df.parse(conforming_date_str));
            } catch (ParseException e) {
                System.out.println(e.toString());
            }
        }
        Transaction_Info transaction_info = new Transaction_Info(txid, to, from, nonce, size, date);
        transaction_list.add(transaction_info);
        if (rsp.contains("}")) {
            idx = rsp.indexOf('}') + 1;
            rsp = rsp.substring(idx);
        } else {
            break;
        }
    }
    return (no_transactions);
}

From source file:net.parser.JobParser.java

public Date getApplicationDeadline() {

    String appDeadline = doc.select("#page-title .font14 strong").text();
    Date date = null;/*from   w w  w .jav  a  2 s  .c om*/
    try {
        date = new SimpleDateFormat("dd.MM.yyyy.").parse(appDeadline);
    } catch (ParseException e) {
        log.error("ParseException. Method: getApplicationDeadline: " + e.toString());
        e.printStackTrace();
    }

    return date;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java

/**
 * calculate the difference in minutes between two dates in millisecond
 * /*from www .j  a  v  a2s  .  com*/
 * @param first
 * @param second
 * @param timespan
 *            : the different of (e.g, ONE minute, ONE day...)
 * @return true if two dates are difference by time span
 */
public boolean timeDiff(String firstDate, String secondDate, long timespan) {
    SimpleDateFormat dfDate = new SimpleDateFormat(dateFormat);

    try {
        Date first = dfDate.parse(firstDate);
        Date second = dfDate.parse(secondDate);

        long diff = ((second.getTime() / timespan) - (first.getTime() / timespan));

        return (diff < 1) ? false : true;

    } catch (ParseException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return false;
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java

private String getDayFromDate(String timeOfMeasurement, String dateFormat, String applyPattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

    try {/* w  ww  . j a v  a  2 s  . co  m*/
        Date today = sdf.parse(timeOfMeasurement);
        sdf.applyPattern(applyPattern);

        return sdf.format(today);

    } catch (ParseException e) {
        e.printStackTrace();
        Log.e(TAG, e.toString());
    }
    return "";
}