List of usage examples for java.lang NumberFormatException getMessage
public String getMessage()
From source file:com.csc.fsg.life.biz.copyobject.XgErrorAreaErrorArrayCopyObject.java
/** Creates this object and initializes all fields and sub-objects with default values. In addition, initializes the user context./*from w w w. jav a 2 s.co m*/ @param userContext the user context. @throws CopyObjectException If there is an initialization problem. **/ public void init(UserContext userContext) throws CopyObjectException { if (initialized) return; setUserContext(userContext); try { } catch (NumberFormatException nfE) { throw new CopyObjectException(nfE.getMessage()); } initialized = true; }
From source file:cn.vlabs.duckling.vwb.ui.action.EditPageAction.java
private int getRequestVersion(HttpServletRequest request) { String version = request.getParameter("version"); if (version != null) { try {/* w w w .j a v a 2 s . c o m*/ return Integer.parseInt(version); } catch (NumberFormatException e) { log.warn(e.getMessage()); } } return VWBContext.LATEST_VERSION; }
From source file:cheladocs.controlo.DocumentoServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf; application/msword; application/excel"); String comando = request.getParameter("comando"); if (comando == null) { comando = "principal"; }/*from w ww . j a va 2 s. com*/ DocumentoDAO documentoDAO; Documento documento = new Documento(); if (comando == null || !comando.equalsIgnoreCase("principal")) { try { idDocumento = request.getParameter("numero_protocolo"); if (idDocumento != null) { documento.setNumeroProtocolo(Integer.parseInt(idDocumento)); } } catch (NumberFormatException ex) { System.err.println("Erro ao converter dado: " + ex.getMessage()); } } try { documentoDAO = new DocumentoDAO(); if (comando.equalsIgnoreCase("guardar")) { documento.getRequerente().setIdRequerente(Integer.parseInt(request.getParameter("requerente"))); documento.setDataEntrada(Date.valueOf(request.getParameter("data_entrada"))); documento.setOrigem(request.getParameter("origem_documento")); documento.setDescricaoAssunto(request.getParameter("descricao_assunto")); documento.getNaturezaAssunto() .setIdNaturezaAssunto(Integer.parseInt(request.getParameter("natureza_assunto"))); documento.getTipoExpediente() .setIdTipoExpediente(Integer.parseInt(request.getParameter("tipo_expediente"))); Part ficheiro = request.getPart("ficheiro"); if (ficheiro != null) { byte[] ficheiroDados = IOUtils.toByteArray(ficheiro.getInputStream()); documento.setConteudoDocumento(ficheiroDados); documento.setUrlFicheiroDocumento(ficheiro.getSubmittedFileName()); doUpload(ficheiro, request); } documentoDAO.save(documento); response.sendRedirect("paginas/gerir_documento.jsp"); } else if (comando.equalsIgnoreCase("editar")) { documento.setNumeroProtocolo(Integer.parseInt(request.getParameter("requerente"))); documento.getRequerente().setIdRequerente(Integer.parseInt(request.getParameter("requerente"))); documento.setDataEntrada(Date.valueOf(request.getParameter("data_entrada"))); documento.setOrigem(request.getParameter("origem_documento")); documento.setDescricaoAssunto(request.getParameter("descricao_assunto")); documento.getNaturezaAssunto() .setIdNaturezaAssunto(Integer.parseInt(request.getParameter("natureza_assunto"))); documento.getTipoExpediente() .setIdTipoExpediente(Integer.parseInt(request.getParameter("tipo_expediente"))); Part ficheiro = request.getPart("ficheiro"); if (ficheiro != null) { byte[] ficheiroDados = IOUtils.toByteArray(ficheiro.getInputStream()); documento.setConteudoDocumento(ficheiroDados); documento.setUrlFicheiroDocumento(ficheiro.getSubmittedFileName()); doUpload(ficheiro, request); } documentoDAO.update(documento); response.sendRedirect("paginas/gerir_documento.jsp"); } else if (comando.equalsIgnoreCase("eliminar")) { documentoDAO.delete(documento); response.sendRedirect("paginas/gerir_documento.jsp"); } else if (comando.equalsIgnoreCase("prepara_editar")) { documento = documentoDAO.findById(documento.getNumeroProtocolo()); request.setAttribute("documento", documento); RequestDispatcher rd = request.getRequestDispatcher("paginas/documento_editar.jsp"); rd.forward(request, response); } else if (comando.equalsIgnoreCase("listar")) { response.sendRedirect("paginas/gerir_documento.jsp"); } else if (comando.equalsIgnoreCase("imprimir_todos") || comando.equalsIgnoreCase("imprimir_by_id")) { ReporteUtil reporte = new ReporteUtil(); File caminhoRelatorio = null; HashMap hashMap = new HashMap(); if (comando.equalsIgnoreCase("imprimir_todos")) { caminhoRelatorio = new File(getServletConfig().getServletContext() .getRealPath("/WEB-INF/relatorios/DocumentoListar.jasper")); reporte.geraRelatorio(caminhoRelatorio.getPath(), hashMap, response); } else { hashMap.put("codigo_documento", Integer.parseInt(idDocumento)); caminhoRelatorio = new File(getServletConfig().getServletContext() .getRealPath("/WEB-INF/relatorios/Ficha_Documento.jasper")); reporte.geraRelatorio(caminhoRelatorio.getPath(), hashMap, response); } } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean.java
/** * Reorders columns// w ww. ja va 2 s.co m * @param request the request * @return url */ public String doReorderColumn(HttpServletRequest request) { String strColumnName = request.getParameter(PARAMETER_COLUMN); if (StringUtils.isBlank(strColumnName)) { return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } int nColumn = 0; try { nColumn = Integer.parseInt(strColumnName); } catch (NumberFormatException nfe) { AppLogService.error("AdminDashboardJspBean.doReorderColumn : " + nfe.getMessage(), nfe); return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP); } _service.doReorderColumn(nColumn); return JSP_MANAGE_DASHBOARDS; }
From source file:de.ub0r.android.websms.connector.smstrade.ConnectorSMStrade.java
/** * Send data./*from ww w .ja v a 2s. co m*/ * * @param context * {@link Context} * @param command * {@link ConnectorCommand} */ private void sendData(final Context context, final ConnectorCommand command) { // do IO try { // get Connection final StringBuilder url = new StringBuilder(URL); final ConnectorSpec cs = this.getSpec(context); final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); url.append("?user="); url.append(Utils.international2oldformat(Utils.getSender(context, command.getDefSender()))); url.append("&password="); url.append(Utils.md5(p.getString(Preferences.PREFS_PASSWORD, ""))); final String text = command.getText(); if (text != null && text.length() > 0) { final String sub = command.getSelectedSubConnector(); url.append("&route="); url.append(sub); url.append("&message="); url.append(URLEncoder.encode(text, "ISO-8859-15")); url.append("&to="); url.append(Utils.joinRecipientsNumbers( Utils.national2international(command.getDefPrefix(), command.getRecipients()), ";", true)); } else { url.append("credits/"); } Log.d(TAG, "--HTTP GET--"); Log.d(TAG, url.toString()); Log.d(TAG, "--HTTP GET--"); // send data HttpResponse response = Utils.getHttpClient(url.toString(), null, null, null, null, false); int resp = response.getStatusLine().getStatusCode(); if (resp != HttpURLConnection.HTTP_OK) { throw new WebSMSException(context, R.string.error_http, "" + resp); } String htmlText = Utils.stream2str(response.getEntity().getContent()).trim(); if (htmlText == null || htmlText.length() == 0) { throw new WebSMSException(context, R.string.error_service); } Log.d(TAG, "--HTTP RESPONSE--"); Log.d(TAG, htmlText); Log.d(TAG, "--HTTP RESPONSE--"); String[] lines = htmlText.split("\n"); htmlText = null; int l = lines.length; if (text != null && text.length() > 0) { try { final int ret = Integer.parseInt(lines[0].trim()); checkReturnCode(context, ret); if (l > 1) { cs.setBalance(lines[l - 1].trim()); } } catch (NumberFormatException e) { Log.e(TAG, "could not parse ret", e); throw new WebSMSException(e.getMessage()); } } else { cs.setBalance(lines[l - 1].trim()); } } catch (Exception e) { Log.e(TAG, null, e); throw new WebSMSException(e.getMessage()); } }
From source file:com.csc.fsg.life.biz.copyobject.XgErrorAreaCopyObject.java
/** * Creates this object and initializes all fields and sub-objects with * default values. In addition, initializes the user context. * * @param userContext the user context. * @throws CopyObjectException If there is an initialization problem. *//*from w w w .jav a 2s . c om*/ public void init(UserContext userContext) throws CopyObjectException { if (initialized) return; setUserContext(userContext); try { //bypass occursgroup xgErrorAreaErrorArray } catch (NumberFormatException nfE) { throw new CopyObjectException(nfE.getMessage()); } initialized = true; }
From source file:com.csc.fsg.life.biz.copyobject.XgErrorAreaCopyObject.java
/** * Default XgErrorAreaCopyObject constructor. Creates this object and * initializes all fields and sub-objects with default values. * * @throws CopyObjectException If there is an initialization problem. *///from ww w . j a va2s . c o m public XgErrorAreaCopyObject() throws CopyObjectException { bytes = new byte[21000]; try { setTrxStatus(""); setTrxIdentification(""); setNumberOfErrorsReturned(Long.valueOf(0)); xgErrorAreaErrorArray = new FixedSizeArrayList<XgErrorAreaErrorArray>(100); XgErrorAreaErrorArrayCopyObject xgErrorAreaErrorArrayCopyObject = new XgErrorAreaErrorArrayCopyObject(); for (int i = 0; i < 100; i++) { int start = 9 + (i * 200); int end = start + 200; replaceBytes(start, end, xgErrorAreaErrorArrayCopyObject.toBytes()); } replaceBytes(20009, 21000, convertToHost(Converter.ALPHANUM, 991, 0, "")); } catch (NumberFormatException nfE) { throw new CopyObjectException(nfE.getMessage()); } }
From source file:fr.gael.dhus.datastore.HierarchicalDirectoryBuilder.java
/** * The initialization of incoming consists re-computing the counter. * For optimization purpose, the counter is saved/retrieved form * incoming root file. A shutdown hook is installed to save the counter at * system exit./* ww w. j a v a 2 s .c o m*/ */ void init() { // Try to read counter from local file File root = getRoot(); File counter_file = new File(root, COUNTER_FILE_NAME); Long counter = null; if (counter_file.exists()) { try { String counter_string = FileUtils.readFileToString(counter_file); counter_string = counter_string.trim(); counter = Long.parseLong(counter_string); } catch (IOException e) { logger.error("Counter file " + counter_file.getPath() + " cannot be accessed", e); } catch (NumberFormatException nfe) { logger.error("Counter file " + counter_file.getPath() + " malformed: " + nfe.getMessage()); } catch (NullPointerException npe) { logger.error("Counter file " + counter_file.getPath() + "is empty."); } } // Counter file found: save it if (counter != null) { HierarchicalDirectoryBuilder.counter = counter; } else { // Counter file not found: compute it recomputeCounterFirstFreePath(); } // Install shutdown hook to save the counter at the end of the // system execution: shall be run only once. if (!isHookInstalled) { isHookInstalled = true; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { // Recompute the counter path (case of root changed). File root = getRoot(); File counter_file = new File(root, COUNTER_FILE_NAME); // Save the counter. FileUtils.writeStringToFile(counter_file, HierarchicalDirectoryBuilder.counter.toString()); } catch (IOException e) { logger.error("Unable to save Incoming counter: " + e.getMessage()); } } })); } }
From source file:games.strategy.engine.random.PropertiesDiceRoller.java
/** * /* w ww . java2 s.c o m*/ * @throws IOException * if there was an error parsing the string */ public int[] getDice(final String string, final int count) throws IOException, InvocationTargetException { final String errorStartString = m_props.getProperty("error.start"); final String errorEndString = m_props.getProperty("error.end"); // if the error strings are defined if (errorStartString != null && errorStartString.length() > 0 && errorEndString != null && errorEndString.length() > 0) { final int startIndex = string.indexOf(errorStartString); if (startIndex >= 0) { final int endIndex = string.indexOf(errorEndString, (startIndex + errorStartString.length())); if (endIndex > 0) { final String error = string.substring(startIndex + errorStartString.length(), endIndex); throw new InvocationTargetException(null, error); } } } String rollStartString; String rollEndString; if (count == 1) { rollStartString = m_props.getProperty("roll.single.start"); rollEndString = m_props.getProperty("roll.single.end"); } else { rollStartString = m_props.getProperty("roll.multiple.start"); rollEndString = m_props.getProperty("roll.multiple.end"); } int startIndex = string.indexOf(rollStartString); if (startIndex == -1) { throw new IOException("Cound not find start index, text returned is:" + string); } startIndex += rollStartString.length(); final int endIndex = string.indexOf(rollEndString, startIndex); if (endIndex == -1) { throw new IOException("Cound not find end index"); } final StringTokenizer tokenizer = new StringTokenizer(string.substring(startIndex, endIndex), " ,", false); final int[] rVal = new int[count]; for (int i = 0; i < count; i++) { try { // -1 since we are 0 based rVal[i] = Integer.parseInt(tokenizer.nextToken()) - 1; } catch (final NumberFormatException ex) { ex.printStackTrace(); throw new IOException(ex.getMessage()); } } return rVal; }
From source file:com.lyncode.xoai.serviceprovider.iterators.MetadataFormatIterator.java
public ListMetadataFormatsType harvest() throws InternalHarvestException { HttpClient httpclient = new DefaultHttpClient(); String url = makeUrl();/*from w ww . j a v a 2 s. c o m*/ config.getLogger().info("Harvesting: " + url); HttpGet httpget = new HttpGet(url); httpget.addHeader("User-Agent", config.getServiceName() + " : XOAI Service Provider"); httpget.addHeader("From", config.getServiceName()); HttpResponse response = null; try { response = httpclient.execute(httpget); StatusLine status = response.getStatusLine(); config.getLogger().debug(response.getStatusLine()); if (status.getStatusCode() == 503) // 503 Status (must wait) { org.apache.http.Header[] headers = response.getAllHeaders(); for (org.apache.http.Header h : headers) { if (h.getName().equals("Retry-After")) { String retry_time = h.getValue(); try { Thread.sleep(Integer.parseInt(retry_time) * 1000); } catch (NumberFormatException e) { config.getLogger().warn("Cannot parse " + retry_time + " to Integer", e); } catch (InterruptedException e) { config.getLogger().debug(e.getMessage(), e); } httpclient.getConnectionManager().shutdown(); httpclient = new DefaultHttpClient(); response = httpclient.execute(httpget); } } } HttpEntity entity = response.getEntity(); InputStream instream = entity.getContent(); OAIPMHtype res = OAIPMHParser.parse(instream, config); return res.getListMetadataFormats(); } catch (IOException e) { throw new InternalHarvestException(e); } catch (ParseException e) { throw new InternalHarvestException(e); } }