List of usage examples for java.text ParseException getMessage
public String getMessage()
From source file:com.twitter.hraven.etl.AssertHistoryListener.java
private void assertCounters(String jobId, String expectedEncodedCounters, CounterMap foundCounterMap) { assertNotNull(foundCounterMap);//from ww w .ja v a 2 s.co m Counters expCounters = null; try { expCounters = Counters.fromEscapedCompactString(expectedEncodedCounters); } catch (ParseException e) { fail("Excetion trying to parse counters: " + e.getMessage()); } for (Counters.Group group : expCounters) { String expGroupName = group.getName(); for (Counters.Counter counter : group) { String expName = counter.getName(); long expValue = counter.getValue(); Counter foundCounter = foundCounterMap.getCounter(expGroupName, expName); assertNotNull(String.format("Counter not found for job=%s, group=%s, name=%s", jobId, expGroupName, expName), foundCounter); assertEquals(String.format("Unexpected counter group"), expGroupName, foundCounter.getGroup()); assertEquals(String.format("Unexpected counter name for job=%s, group=%s", jobId, expGroupName), expName, foundCounter.getKey()); assertEquals(String.format("Unexpected counter value for job=%s, group=%s, name=%s", jobId, expGroupName, expName), expValue, foundCounter.getValue()); } } }
From source file:com.comcast.cats.monitor.reboot.BarcelonaRebootMonitor.java
/** * Parse the snmp result to detect reboot. * /* w ww . ja v a2 s . co m*/ * Examples of expected results : "18:54:41.36", "2 days, 18:54:41.36", * "1 day, 18:54:41.36" */ @Override protected void parseRebootInfo(String snmpQueryResult) { logger.debug("snmpQueryResult " + snmpQueryResult); long upTime = 0; String upTimeDays = null; String upTimehours; try { if (snmpQueryResult != null && !snmpQueryResult.isEmpty()) { Pattern pattern = Pattern.compile(REBOOT_DETECTION_REGEX_STRING); Matcher matcher = pattern.matcher(snmpQueryResult); if (matcher.find()) { // seperate the days information and the time information. upTimeDays = StringUtils.substringBefore(snmpQueryResult, matcher.group()).trim(); upTimehours = StringUtils.substringAfter(snmpQueryResult, matcher.group()).trim(); } else { upTimehours = snmpQueryResult.trim(); } upTime = calculateUptime(upTimeDays, upTimehours); long timeInterval = calculcateMonitorTimeIntervalInMillis(); logger.debug("timeInterval sec " + (timeInterval / (1000))); logger.debug("upTime sec " + (upTime) / 1000); if (timeInterval > upTime) { logger.debug("Reboot Happened"); RebootStatistics stats = new RebootStatistics(new Date()); stats.setMonitorType(REBOOT_TYPE); stats.setMessage("UP Time " + snmpQueryResult, settop.getHostMacAddress()); stats.setUptime(upTime / 1000); alarm(stats); } else { logger.trace("NO Reboot Happened"); } } else { logger.debug("SNMP detection failed : No response from settop " + snmpQueryResult); } } catch (ParseException e) { logger.trace("Result not in an expected format : " + e.getMessage()); } catch (NumberFormatException e) { logger.trace("Result not in an expected format : " + e.getMessage()); } ((Calendar) getState()).setTime(new Date()); }
From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java
private static LastModified getLastModified(String lastModified) { LastModified lMod = null;/* ww w .java 2 s . c om*/ DateTime dt; try { dt = new DateTime(lastModified); lMod = new LastModified(dt); } catch (ParseException e) { System.err.println(e.getMessage()); System.err.println("String turning into LAST-MODIFIED: " + lastModified); e.printStackTrace(); System.exit(1); } return lMod; }
From source file:org.n52.cario.gep.inbound.TrackInboundAdapter.java
private Date parseDateTime(Map<?, ?> props) { Date time = null;/* ww w . j a v a 2 s .c o m*/ try { time = isoDateTimeFormat.parse((String) props.get(TIME_KEY)); } catch (ParseException e) { logger.warn(e.getMessage()); } return time; }
From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java
private static CommandLine parseArgs(String args[]) throws org.apache.commons.cli.ParseException { CommandLineParser parser = new GnuParser(); CommandLine cl = null;//from ww w .j a v a 2 s . c o m try { cl = parser.parse(sOptions, args); } catch (org.apache.commons.cli.ParseException pe) { usage(pe.getMessage()); System.exit(1); } return cl; }
From source file:com.k42b3.quantum.worker.GitHubCommitWorker.java
@Override protected void fetch(HttpClient httpClient) { try {/* w w w. ja va2s. c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX"); String url = "https://api.github.com/repos/" + worker.getParams().get("owner") + "/" + worker.getParams().get("repo") + "/commits"; if (worker.getLastRequest() != null) { url = url + "?since=" + sdf.format(worker.getLastRequest()); } HttpGet httpGet = new HttpGet(url); if (worker.getLastRequest() != null) { httpGet.addHeader("If-Modified-Since", DateUtils.formatDate(worker.getLastRequest())); } logger.info("Request " + url); HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == 304) { return; } String json = EntityUtils.toString(response.getEntity()); Gson gson = new Gson(); Commits[] commits = gson.fromJson(json, Commits[].class); for (int i = 0; i < commits.length; i++) { try { Date date = sdf.parse(commits[i].getCommit().getAuthor().getDate()); Message message = new Message(); message.setMid(commits[i].getSha()); message.setUrl(commits[i].getHtmlUrl()); message.setMessage(commits[i].getCommit().getMessage()); message.setProducer(worker.getParams().get("repo")); message.setDate(date); queue.push(this, message); } catch (ParseException e) { logger.error(e.getMessage(), e); } } } catch (ClientProtocolException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:de.atomfrede.tools.evalutation.evaluator.evaluators.CO2DiffEvaluator.java
@Override public boolean evaluate() throws Exception { CSVWriter writer = null;/*from w ww . ja va 2s . com*/ try { { if (!inputFile.exists()) return false; outputFile = new File(outputFolder, "co2diff.csv"); outputFile.createNewFile(); if (!outputFile.exists()) return false; writer = getCsvWriter(outputFile); WriteUtils.writeHeader(writer); List<String[]> lines = readAllLinesInFile(inputFile); allReferenceLines = findAllReferenceLines(lines, OutputFileConstants.SOLENOID_VALVES); for (int i = 1; i < lines.size(); i++) { String[] currentLine = lines.get(i); double co2Diff = parseDoubleValue(currentLine, OutputFileConstants.CO2_ABSOLUTE) - getCO2DiffForLine(currentLine, lines, allReferenceLines); writeCO2Diff(writer, currentLine, co2Diff); progressBar.setValue((int) (i * 1.0 / lines.size() * 100.0 * 0.5)); } } log.info("CO2 Diff for Data Values done."); progressBar.setValue(50); writer.close(); { // now compute needed valus for standard derivation file if (!standardDeviationInputFile.exists()) return false; standardDeviationOutputFile = new File(outputFolder, "standard-derivation-co2diff.csv"); standardDeviationOutputFile.createNewFile(); if (!standardDeviationOutputFile.exists()) return false; writer = getCsvWriter(standardDeviationOutputFile); WriteUtils.writeHeader(writer); List<String[]> lines = readAllLinesInFile(standardDeviationInputFile); for (int i = 1; i < lines.size(); i++) { // if (i % 1000 == 0) // System.out.println("Writing Standard Derivation Line " // + i); String[] currentLine = lines.get(i); double co2Diff = parseDoubleValue(currentLine, OutputFileConstants.CO2_ABSOLUTE) - getCO2DiffForLine(currentLine, lines, allReferenceLines); writeCO2Diff(writer, currentLine, co2Diff); progressBar.setValue((int) ((i * 1.0 / lines.size() * 100.0 * 0.5) + 50.0)); } } log.info("CO2 Diff for StandardDerivation Values done."); } 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("CO2Diff done"); progressBar.setValue(100); return true; }
From source file:org.dashbuilder.dataprovider.backend.csv.CSVParser.java
protected Object parseValue(DataColumn column, String value) throws Exception { ColumnType type = column.getColumnType(); try {//from ww w . ja va 2s .c o m if (type.equals(ColumnType.DATE)) { 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:cz.zcu.kiv.eegdatabase.webservices.rest.user.UserServiceImpl.java
/** * @{@inheritDoc}/*from w w w .java2 s .co m*/ */ @Transactional @Override public PersonData create(String registrationPath, PersonData personData, Locale locale) throws RestServiceException { try { Person person = new Person(); person.setGivenname(personData.getName()); person.setSurname(personData.getSurname()); person.setPassword(personData.getPassword() == null ? ControllerUtils.getRandomPassword() : personData.getPassword()); String plainPassword = person.getPassword(); person.setRegistrationDate(new Timestamp(System.currentTimeMillis())); person.setGender(personData.getGender().charAt(0)); person.setLaterality(personData.getLeftHanded().charAt(0)); person.setDateOfBirth( new Timestamp(ControllerUtils.getDateFormat().parse(personData.getBirthday()).getTime())); person.setPhoneNumber(personData.getPhone()); person.setNote(personData.getNotes()); //dummy default education level List<EducationLevel> def = educationLevelDao.getEducationLevels(DEFAULT_EDUCATION_LEVEL); person.setEducationLevel(def.isEmpty() ? null : def.get(0)); //default role person.setAuthority(Util.ROLE_READER); // security specifics person.setUsername(personData.getEmail()); person.setAuthenticationHash(ControllerUtils.getMD5String(personData.getEmail())); person.setPassword(new BCryptPasswordEncoder().encode(plainPassword)); int pk = personDao.create(person); sendRegistrationConfirmMail(registrationPath, plainPassword, person, locale); personData.setId(pk); return personData; } catch (ParseException e) { log.error(e.getMessage(), e); throw new RestServiceException(e); } catch (MessagingException e) { log.error(e.getMessage(), e); throw new RestServiceException(e); } }
From source file:com.flexive.shared.FxFormatUtils.java
/** * Convert a String to Date//from w w w . jav a 2 s. c om * * @param value value to convert * @return Date */ public static Date toDate(String value) { try { try { return FxValueRendererFactory.getDateFormat().parse(unquote(value)); } catch (ParseException e) { //fallback to universal format if "short" format is no match return new SimpleDateFormat(UNIVERSAL_TIMEFORMAT).parse(unquote(value)); } } catch (Exception e) { throw new FxConversionException(e, "ex.conversion.value.error", FxDate.class.getCanonicalName(), value, e.getMessage()).asRuntimeException(); } }