List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:com.owly.srv.RemoteBasicStat.java
/** * Method which adds in to the object all fields related to the JSON object * obtained from the remote Server HTTP response. Here is an example of this * JSON Object ://from w ww . j ava2 s .com * {"StatType":"TopCpu","Date":"2013-05-16 09:39:17","Host":"centos-63", * "Metrics" * :{"cpu_idle":97.6,"cpu_steal":0.0,"cpu_wait":0.0,"cpu_low_priority" * :0.0,"cpu_software_interrupts" * :0.0,"cpu_hardware_interrupts":0.0,"cpu_kernel":0.0,"cpu_user":2.4}, * "MetricType":"SystemStat"} * * @param jsonObject */ public void setRmtSeverfromJSONObject(JSONObject jsonObject) { Logger log = Logger.getLogger(RemoteBasicStat.class); log.debug("Calling setRmtSeverfromJSONObject"); log.debug("JSON object to analyze : " + jsonObject.toString()); this.setTypeOfStat((String) jsonObject.get("StatType")); log.debug(" Type Stat : " + this.getTypeOfStat()); if (this.getTypeOfStat().equals("NOK")) { log.error("Metric received is not OK, check in client side"); } else { this.setHostname((String) jsonObject.get("Host")); log.debug(" Hostname : " + this.getHostname()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String strDateRemote = (String) jsonObject.get("Date"); try { Date dateRemote = dateFormat.parse(strDateRemote); this.setRmtServerDate(dateRemote); log.debug("Remote date is " + dateFormat.format(this.getDateRmtServerDate())); } catch (ParseException e) { log.error("Parse date Error : " + e.getMessage()); log.error("Exception ::", e); } this.setMetrics((JSONObject) jsonObject.get("Metrics")); log.debug(" Metrics : " + this.getMetrics().toString()); this.setMetricType((String) jsonObject.get("MetricType")); log.debug(" Type of Metric : " + this.getMetricType()); } }
From source file:com.sinet.gage.tasklets.DominFullImportTasklet.java
private Date getDateFormat(String dateString) { Date formattedDate = null;// ww w. ja v a 2 s .com try { if (StringUtils.hasLength(dateString)) { formattedDate = new Date(dateFormat.parse(dateString).getTime()); } } catch (ParseException e) { logger.error("Invalid date format: " + e.getMessage()); } return formattedDate; }
From source file:org.jboss.dashboard.dataset.csv.CSVDataSet.java
public Object parseValue(CSVDataProperty prop, String value) throws Exception { Domain domain = prop.getDomain();//from w w w. j a v a2s. c om try { if (domain instanceof DateDomain) { return _dateFormat.parse(value); } else if (domain instanceof NumericDomain) { return new Double(_numberFormat.parse(value).doubleValue()); } else return value; } catch (ParseException e) { String msg = "Error parsing value: " + value + ", " + e.getMessage() + ". Check column\u0027s data type consistency!"; log.error(msg); throw new Exception(msg); } }
From source file:de.atomfrede.tools.evalutation.evaluator.evaluators.Delta13Evaluator.java
@Override public boolean evaluate() throws Exception { CSVWriter writer = null;/* w w w . j a va 2s . co m*/ try { { // first the mean values if (!inputFile.exists()) return false; outputFile = new File(outputFolder, "delta13.csv"); outputFile.createNewFile(); if (!outputFile.exists()) return false; writer = getCsvWriter(outputFile); WriteUtils.writeHeader(writer); List<String[]> allLines = readAllLinesInFile(inputFile); allReferenceLines = findAllReferenceLines(allLines, OutputFileConstants.SOLENOID_VALVES); for (int i = 1; i < allLines.size(); i++) { String[] currentLine = allLines.get(i); double solenoid = parseDoubleValue(currentLine, OutputFileConstants.SOLENOID_VALVES); if (solenoid != 1.0) { // only for non reference lines compute the values String[] refLine2Use = getReferenceLineToUse(currentLine, allLines, allReferenceLines, OutputFileConstants.DATE_AND_TIME); double delta13 = computeDelta13(currentLine, refLine2Use); writeValue(writer, currentLine, delta13); } else { writeValue(writer, currentLine, 0.0); } progressBar.setValue((int) (i * 1.0 / allLines.size() * 100.0 * 0.5)); } } writer.close(); log.info("Delta13 for mean values done."); progressBar.setValue(50); { // first the mean values if (!standardDeviationInputFile.exists()) return false; standardDeviationOutputFile = new File(outputFolder, "standard-derivation-delta13.csv"); standardDeviationOutputFile.createNewFile(); if (!standardDeviationOutputFile.exists()) return false; writer = getCsvWriter(standardDeviationOutputFile); WriteUtils.writeHeader(writer); List<String[]> allLines = readAllLinesInFile(standardDeviationInputFile); for (int i = 1; i < allLines.size(); i++) { String[] currentLine = allLines.get(i); double solenoid = parseDoubleValue(currentLine, OutputFileConstants.SOLENOID_VALVES); if (solenoid != 1.0) { // only for non reference lines compute the values String[] refLine2Use = getReferenceLineToUse(currentLine, allLines, allReferenceLines, OutputFileConstants.DATE_AND_TIME); double delta13 = computeDelta13(currentLine, refLine2Use); writeValue(writer, currentLine, delta13); } else { writeValue(writer, currentLine, 0.0); } progressBar.setValue((int) ((i * 1.0 / allLines.size() * 100.0 * 0.5) + 50.0)); } } } catch (IOException ioe) { log.error("IOException " + ioe.getMessage()); DialogUtil.getInstance().showError(ioe); return false; } catch (ParseException pe) { log.error("ParseException " + pe.getMessage()); DialogUtil.getInstance().showError(pe); return false; } catch (Exception e) { log.error(e); DialogUtil.getInstance().showError(e); return false; } finally { if (writer != null) writer.close(); } log.info("Delta13 done."); progressBar.setValue(100); return true; }
From source file:com.thoughtworks.go.config.BackupConfig.java
private void validateTimer() { if (isBlank(schedule)) { return;/*from w w w. java 2s . c o m*/ } try { new CronExpression(schedule); } catch (ParseException pe) { errors.add(SCHEDULE, "Invalid cron syntax for backup configuration at offset " + pe.getErrorOffset() + ": " + pe.getMessage()); } }
From source file:org.kiji.mapreduce.lib.bulkimport.CSVBulkImporter.java
/** {@inheritDoc} */ @Override//from w w w . j av a 2s . co m public void setupImporter(KijiTableContext context) throws IOException { // Validate that the passed in delimiter is one of the supported options. List<String> validDelimiters = Lists.newArrayList(CSV_DELIMITER, TSV_DELIMITER); if (!validDelimiters.contains(mColumnDelimiter)) { throw new IOException(String.format("Invalid delimiter '%s' specified. Valid options are: '%s'", mColumnDelimiter, StringUtils.join(validDelimiters, "','"))); } // If the header row is specified in the configuration, use that. if (getConf().get(CONF_INPUT_HEADER_ROW) != null) { List<String> fields = null; String confInputHeaderRow = getConf().get(CONF_INPUT_HEADER_ROW); try { fields = split(confInputHeaderRow); } catch (ParseException pe) { LOG.error("Unable to parse header row: {} with exception {}", confInputHeaderRow, pe.getMessage()); throw new IOException("Unable to parse header row: " + confInputHeaderRow); } initializeHeader(fields); } }
From source file:edu.northwestern.bioinformatics.studycalendar.dao.reporting.ScheduledActivitiesReportRowDaoTest.java
public void testRowWithPersonIdAndStartAndEndDate() { filters.setPersonId("UNIVERSAL"); MutableRange<Date> range = new MutableRange<Date>(); Date startDate = null;//from w w w.j av a2 s . c o m Date endDate = null; try { startDate = API_DATE_FORMAT.get().parse("2007-09-29"); endDate = API_DATE_FORMAT.get().parse("2007-10-29"); } catch (ParseException pe) { pe.getMessage(); } range.setStart(startDate); range.setStop(endDate); filters.setActualActivityDate(range); assertSearchWithResults(NEG_18); }
From source file:org.dashbuilder.dataprovider.csv.CSVParser.java
protected Object parseValue(DataColumn column, String value) throws Exception { ColumnType type = column.getColumnType(); try {/*w w w. ja v a 2 s . co m*/ if (type.equals(ColumnType.DATE)) { String pattern = dataSetDef.getPattern(column.getId()); // Handle special date pattern "epoch" if (pattern != null && DATE_FORMAT_EPOCH.equalsIgnoreCase(pattern)) { Double _epoch = Double.parseDouble(value); return new Date(_epoch.longValue() * 1000); } else { DateFormat dateFormat = getDateFormat(column.getId()); return dateFormat.parse(value); } } else if (type.equals(ColumnType.NUMBER)) { DecimalFormat numberFormat = getNumberFormat(column.getId()); return numberFormat.parse(value).doubleValue(); } else { return value; } } catch (ParseException e) { String msg = "Error parsing value: " + value + ", " + e.getMessage() + ". Check column\u0027s data type consistency!"; throw new Exception(msg); } }
From source file:br.org.funcate.dynamicforms.views.GTimeView.java
/** * @param fragment the fragment./*from ww w . j ava 2 s . c om*/ * @param attrs attributes. * @param parentView parent * @param label label * @param value value * @param constraintDescription constraints * @param readonly if <code>false</code>, the item is disabled for editing. */ public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label, String value, String constraintDescription, boolean readonly) { super(fragment.getActivity(), attrs); final Context context = fragment.getActivity(); LinearLayout textLayout = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layoutParams.setMargins(10, 10, 10, 10); textLayout.setLayoutParams(layoutParams); textLayout.setOrientation(LinearLayout.VERTICAL); parentView.addView(textLayout); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(2, 2, 2, 2); textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription); textView.setTextColor(context.getResources().getColor(R.color.formcolor)); textLayout.addView(textView); button = new Button(context); button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); button.setPadding(15, 5, 15, 5); final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER; if (value == null || value.length() == 0) { String dateStr = timeFormatter.format(new Date()); button.setText(dateStr); } else { button.setText(value); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String dateStr = button.getText().toString(); Date date = null; try { date = timeFormatter.parse(dateStr); } catch (ParseException e) { //GPLog.error(this, null, e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); // fallback on current date date = new Date(); } final Calendar c = Calendar.getInstance(); c.setTime(date); int hourOfDay = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); FormTimePickerFragment newFragment = new FormTimePickerFragment(); newFragment.setAttributes(hourOfDay, minute, true, button); //newFragment.show(fragment.getFragmentManager(), "timePicker"); } }); button.setEnabled(!readonly); textLayout.addView(button); }
From source file:org.kiji.mapreduce.lib.bulkimport.CSVBulkImporter.java
/** {@inheritDoc} */ @Override//from w w w.j ava 2 s . c o m public void produce(Text value, KijiTableContext context) throws IOException { // This is the header line since fieldList isn't populated if (mFieldMap == null) { List<String> fields = null; try { fields = split(value.toString()); } catch (ParseException pe) { LOG.error("Unable to parse header row: {} with exception {}", value.toString(), pe.getMessage()); throw new IOException("Unable to parse header row: " + value.toString()); } initializeHeader(fields); // Don't actually import this line return; } List<String> fields = null; try { fields = split(value.toString()); } catch (ParseException pe) { reject(value, context, pe.toString()); return; } for (KijiColumnName kijiColumnName : getDestinationColumns()) { final EntityId eid = getEntityId(fields, context); String source = getSource(kijiColumnName); if (mFieldMap.get(source) < fields.size()) { String fieldValue = fields.get(mFieldMap.get(source)); context.put(eid, kijiColumnName.getFamily(), kijiColumnName.getQualifier(), fieldValue); } else { incomplete(value, context, "Detected trailing empty field: " + source); } } }