List of usage examples for java.lang NumberFormatException getMessage
public String getMessage()
From source file:com.project.atm.model.async.ProcessExecutor.java
public ProcessExecutor(ThreadPoolTaskExecutor taskExecutor) { this.taskExecutor = taskExecutor; String processThread = ResourceHelper.getAppResource("processThread"); if (processThread.isEmpty() || processThread.equals("")) { taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2); } else {//from w ww . j a v a2 s.c o m try { taskExecutor.setCorePoolSize(Integer.parseInt(processThread)); } catch (NumberFormatException nfe) { logger.error(nfe.getMessage() + ", set to default configuration"); taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2); } } }
From source file:au.org.ala.layers.grid.GridClassBuilder.java
public static HashMap<Integer, GridClass> buildFromGrid(String filePath) throws IOException { File wktDir = new File(filePath); wktDir.mkdirs();/*from w w w . j a v a2 s. c o m*/ int[] wktMap = null; //track values for the SLD ArrayList<Integer> maxValues = new ArrayList<Integer>(); ArrayList<String> labels = new ArrayList<String>(); HashMap<Integer, GridClass> classes = new HashMap<Integer, GridClass>(); Properties p = new Properties(); p.load(new FileReader(filePath + ".txt")); boolean mergeProperties = false; Map<String, Set<Integer>> groupedKeys = new HashMap<String, Set<Integer>>(); Map<Integer, Integer> translateKeys = new HashMap<Integer, Integer>(); Map<String, Integer> translateValues = new HashMap<String, Integer>(); ArrayList<Integer> keys = new ArrayList<Integer>(); for (String key : p.stringPropertyNames()) { try { int k = Integer.parseInt(key); keys.add(k); //grouping of property file keys by value String value = p.getProperty(key); Set<Integer> klist = groupedKeys.get(value); if (klist == null) klist = new HashSet<Integer>(); else mergeProperties = true; klist.add(k); groupedKeys.put(value, klist); if (!translateValues.containsKey(value)) translateValues.put(value, translateValues.size() + 1); translateKeys.put(k, translateValues.get(value)); } catch (NumberFormatException e) { logger.info("Excluding shape key '" + key + "'"); } catch (Exception e) { logger.error(e.getMessage(), e); } } java.util.Collections.sort(keys); Grid g = new Grid(filePath); boolean generateWkt = false; //((long) g.nrows) * ((long) g.ncols) < (long) Integer.MAX_VALUE; if (mergeProperties) { g.replaceValues(translateKeys); if (!new File(filePath + ".txt.old").exists()) FileUtils.moveFile(new File(filePath + ".txt"), new File(filePath + ".txt.old")); StringBuilder sb = new StringBuilder(); for (String value : translateValues.keySet()) { sb.append(translateValues.get(value)).append("=").append(value).append('\n'); } FileUtils.writeStringToFile(new File(filePath + ".txt"), sb.toString()); return buildFromGrid(filePath); } if (generateWkt) { for (String name : groupedKeys.keySet()) { try { Set<Integer> klist = groupedKeys.get(name); String key = klist.iterator().next().toString(); int k = Integer.parseInt(key); GridClass gc = new GridClass(); gc.setName(name); gc.setId(k); if (klist.size() == 1) klist = null; logger.info("getting wkt for " + filePath + " > " + key); Map wktIndexed = Envelope.getGridSingleLayerEnvelopeAsWktIndexed( filePath + "," + key + "," + key, klist, wktMap); //write class wkt File zipFile = new File(filePath + File.separator + key + ".wkt.zip"); ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFile)); zos.putNextEntry(new ZipEntry(key + ".wkt")); zos.write(((String) wktIndexed.get("wkt")).getBytes()); zos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (zos != null) { try { zos.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } BufferedOutputStream bos = null; try { bos = new BufferedOutputStream( new FileOutputStream(filePath + File.separator + key + ".wkt")); bos.write(((String) wktIndexed.get("wkt")).getBytes()); bos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (bos != null) { try { bos.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } logger.info("wkt written to file"); gc.setArea_km(SpatialUtil.calculateArea((String) wktIndexed.get("wkt")) / 1000.0 / 1000.0); //store map wktMap = (int[]) wktIndexed.get("map"); //write wkt index FileWriter fw = null; try { fw = new FileWriter(filePath + File.separator + key + ".wkt.index"); fw.append((String) wktIndexed.get("index")); fw.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (fw != null) { try { fw.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } //write wkt index a binary, include extents (minx, miny, maxx, maxy) and area (sq km) int minPolygonNumber = 0; int maxPolygonNumber = 0; RandomAccessFile raf = null; try { raf = new RandomAccessFile(filePath + File.separator + key + ".wkt.index.dat", "rw"); String[] index = ((String) wktIndexed.get("index")).split("\n"); for (int i = 0; i < index.length; i++) { if (index[i].length() > 1) { String[] cells = index[i].split(","); int polygonNumber = Integer.parseInt(cells[0]); raf.writeInt(polygonNumber); //polygon number int polygonStart = Integer.parseInt(cells[1]); raf.writeInt(polygonStart); //character offset if (i == 0) { minPolygonNumber = polygonNumber; } else if (i == index.length - 1) { maxPolygonNumber = polygonNumber; } } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (raf != null) { try { raf.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } //for SLD maxValues.add(gc.getMaxShapeIdx()); labels.add(name.replace("\"", "'")); gc.setMinShapeIdx(minPolygonNumber); gc.setMaxShapeIdx(maxPolygonNumber); logger.info("getting multipolygon for " + filePath + " > " + key); MultiPolygon mp = Envelope.getGridEnvelopeAsMultiPolygon(filePath + "," + key + "," + key); gc.setBbox(mp.getEnvelope().toText().replace(" (", "(").replace(", ", ",")); classes.put(k, gc); try { //write class kml zos = null; try { zos = new ZipOutputStream( new FileOutputStream(filePath + File.separator + key + ".kml.zip")); zos.putNextEntry(new ZipEntry(key + ".kml")); Encoder encoder = new Encoder(new KMLConfiguration()); encoder.setIndenting(true); encoder.encode(mp, KML.Geometry, zos); zos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (zos != null) { try { zos.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } logger.info("kml written to file"); final SimpleFeatureType TYPE = DataUtilities.createType("class", "the_geom:MultiPolygon,id:Integer,name:String"); FeatureJSON fjson = new FeatureJSON(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE); SimpleFeature sf = featureBuilder.buildFeature(null); //write class geojson zos = null; try { zos = new ZipOutputStream( new FileOutputStream(filePath + File.separator + key + ".geojson.zip")); zos.putNextEntry(new ZipEntry(key + ".geojson")); featureBuilder.add(mp); featureBuilder.add(k); featureBuilder.add(name); fjson.writeFeature(sf, zos); zos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (zos != null) { try { zos.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } logger.info("geojson written to file"); //write class shape file File newFile = new File(filePath + File.separator + key + ".shp"); ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", newFile.toURI().toURL()); params.put("create spatial index", Boolean.FALSE); ShapefileDataStore newDataStore = null; try { newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); newDataStore.createSchema(TYPE); newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84); Transaction transaction = new DefaultTransaction("create"); String typeName = newDataStore.getTypeNames()[0]; SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; featureStore.setTransaction(transaction); List<SimpleFeature> features = new ArrayList<SimpleFeature>(); DefaultFeatureCollection collection = new DefaultFeatureCollection(); collection.addAll(features); featureStore.setTransaction(transaction); features.add(sf); featureStore.addFeatures(collection); transaction.commit(); transaction.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (newDataStore != null) { try { newDataStore.dispose(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } zos = null; try { zos = new ZipOutputStream( new FileOutputStream(filePath + File.separator + key + ".shp.zip")); //add .dbf .shp .shx .prj String[] exts = { ".dbf", ".shp", ".shx", ".prj" }; for (String ext : exts) { zos.putNextEntry(new ZipEntry(key + ext)); FileInputStream fis = null; try { fis = new FileInputStream(filePath + File.separator + key + ext); byte[] buffer = new byte[1024]; int size; while ((size = fis.read(buffer)) > 0) { zos.write(buffer, 0, size); } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } //remove unzipped files new File(filePath + File.separator + key + ext).delete(); } zos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (zos != null) { try { zos.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } logger.info("shape file written to zip"); } catch (Exception e) { logger.error(e.getMessage(), e); } } catch (Exception e) { logger.error(e.getMessage(), e); } } //write polygon mapping g.writeGrid(filePath + File.separator + "polygons", wktMap, g.xmin, g.ymin, g.xmax, g.ymax, g.xres, g.yres, g.nrows, g.ncols); //copy the header file to get it exactly the same, but change the data type copyHeaderAsInt(filePath + ".grd", filePath + File.separator + "polygons.grd"); } else { //build classes without generating polygons Map<Float, float[]> info = new HashMap<Float, float[]>(); for (int j = 0; j < keys.size(); j++) { info.put(keys.get(j).floatValue(), new float[] { 0, Float.NaN, Float.NaN, Float.NaN, Float.NaN }); } g.getClassInfo(info); for (int j = 0; j < keys.size(); j++) { int k = keys.get(j); String key = String.valueOf(k); String name = p.getProperty(key); GridClass gc = new GridClass(); gc.setName(name); gc.setId(k); //for SLD maxValues.add(Integer.valueOf(key)); labels.add(name.replace("\"", "'")); gc.setMinShapeIdx(Integer.valueOf(key)); gc.setMaxShapeIdx(Integer.valueOf(key)); float[] stats = info.get(keys.get(j).floatValue()); //only include if area > 0 if (stats[0] > 0) { gc.setBbox("POLYGON((" + stats[1] + " " + stats[2] + "," + stats[1] + " " + stats[4] + "," + stats[3] + " " + stats[4] + "," + stats[3] + " " + stats[2] + "," + stats[1] + " " + stats[2] + "))"); gc.setArea_km((double) stats[0]); classes.put(k, gc); } } } //write sld exportSLD(filePath + File.separator + "polygons.sld", new File(filePath + ".txt").getName(), maxValues, labels); writeProjectionFile(filePath + File.separator + "polygons.prj"); //write .classes.json ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(new File(filePath + ".classes.json"), classes); return classes; }
From source file:org.dspace.app.webui.cris.controller.RedirectEntityDetailsController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("id"); T entity = null;/* www . j av a2 s . c o m*/ if (id == null || id.isEmpty()) { String modeCode = request.getParameter("code"); if (modeCode != null && !modeCode.isEmpty()) { entity = ((ApplicationService) applicationService).getEntityBySourceId(modeCode, modelClass); } else { String path = request.getPathInfo().substring(1); // remove // first / String[] splitted = path.split("/"); request.setAttribute("authority", splitted[1]); entity = ((ApplicationService) applicationService).get(modelClass, ResearcherPageUtils.getRealPersistentIdentifier(splitted[1], modelClass)); } } else { try { entity = applicationService.get(modelClass, Integer.parseInt(id)); } catch (NumberFormatException e) { log.error(e.getMessage(), e); } } return new ModelAndView("redirect:" + ResearcherPageUtils.getPersistentIdentifier(entity)); }
From source file:com.sec.ose.osi.ui.frm.main.report.BOMTableRow.java
protected BOMTableRow(String componentName, String componentLicense, int fileCount) { super();//from ww w . ja v a 2 s .c o m this.componentName = componentName; this.componentLicense = componentLicense; this.fileCount = fileCount; if (this.componentName == null) this.componentName = ""; if (this.componentLicense == null) this.componentLicense = ""; int fileCnt = 0; try { fileCnt = this.fileCount; } catch (NumberFormatException ex) { log.warn(ex.getMessage()); fileCnt = 0; } if (fileCnt >= DEFAULT_CHECKED_FILECNT) setChecked(true); }
From source file:com.circle_technologies.cnn4j.predictive.command.CommandTrain.java
@Override public String execute(DataAccumulator accumulator, @Nullable CommandLine commandLine) { try {/* ww w .j a va2s .co m*/ int epochs = Integer.parseInt(commandLine.getOptionValue("e")); getContext().getNetwork().enableWebUi(commandLine.hasOption("w")); getContext().getNetwork().train(accumulator.getInputValues(), accumulator.getOutputValues(), epochs); return "Training done"; } catch (NumberFormatException e) { Log.info("RNN", "expected epochs param to be an integer: " + e.getMessage()); e.printStackTrace(); return "Training failed"; } }
From source file:dk.netarkivet.archive.webinterface.BatchGUI.java
/** * Creates an entry for the overview table for the batchjobs. If the batchjob cannot be instatiated, then an error * is written before the table entry, and only the name of the batchjob is written, though the whole name. * <p>//from w w w .j a v a2s. c o m * <br/> * E.g.: <br/> * <tr><br/> * <th>ChecksumJob</th><br/> * <th>Tue Mar 23 13:56:45 CET 2010</th><br/> * <th><input type="submit" name="ChecksumJob_output" value="view" /><br/> * <input type="submit" name="ChecksumJob_output" value="download" /> <br/> * 5 bytes</th><br/> * <th><input type="submit" name="ChecksumJob_error" value="view" /><br/> * <input type="submit" name="ChecksumJob_error" value="download" /><br/> * 5 bytes</th><br/> * </tr> * <p> * <br/> * Which looks something like this: <br/> * <br/> * <p> * <tr> * <th>ChecksumJob</th> * <th>Tue Mar 23 13:56:45 CET 2010</th> * <th><input type="submit" name="ChecksumJob_output" value="view" /> <input type="submit" name="ChecksumJob_output" * value="download" /> 5 bytes</th> * <th><input type="submit" name="ChecksumJob_error" value="view" /> <input type="submit" name="ChecksumJob_error" * value="download" /> 5 bytes</th> * </tr> * * @param batchClassPath The name of the batch job. * @param locale The language package. * @return The HTML code for the entry in the table. */ private static String getOverviewTableEntry(String batchClassPath, Locale locale) { StringBuilder res = new StringBuilder(); try { // Check whether it is retrievable. (Throws UnknownID if not). getBatchClass(batchClassPath); final String batchName = getJobName(batchClassPath); File batchDir = getBatchDir(); // retrieve the latest batchjob results. String timestamp = getLatestTimestamp(batchName); File outputFile = new File(batchDir, batchName + timestamp + Constants.OUTPUT_FILE_EXTENSION); File errorFile = new File(batchDir, batchName + timestamp + Constants.ERROR_FILE_EXTENSION); // write the HTML res.append(" <td><a href=\"" + Constants.URL_BATCHJOB + "?" + Constants.BATCHJOB_PARAMETER + "=" + batchClassPath + "\">" + batchName + "</a></td>\n"); // add time of last run String lastRun = ""; if (timestamp.isEmpty()) { lastRun = I18N.getString(locale, "batchpage;Batchjob.has.never.been.run", new Object[] {}); } else { try { lastRun = new Date(Long.parseLong(timestamp.substring(1))).toString(); } catch (NumberFormatException e) { log.warn("Could not parse the timestamp '" + timestamp + "'", e); lastRun = e.getMessage(); } } res.append(" <td>" + lastRun + "</td>\n"); // add output file references (retrieval and size) if (outputFile.exists() && outputFile.isFile() && outputFile.canRead()) { res.append(" <td><a href=" + Constants.URL_RETRIEVE_RESULT_FILES + "?filename=" + outputFile.getName() + ">" + I18N.getString(locale, "batchpage;Download.outputfile", new Object[] {}) + "</a> " + outputFile.length() + " bytes, " + FileUtils.countLines(outputFile) + " lines</td>\n"); } else { res.append(" <td>" + I18N.getString(locale, "batchpage;No.outputfile", new Object[] {}) + "</td>\n"); } // add error file references (retrieval and size) if (errorFile.exists() && errorFile.isFile() && errorFile.canRead()) { res.append(" <td><a href=" + Constants.URL_RETRIEVE_RESULT_FILES + "?filename=" + errorFile.getName() + ">" + I18N.getString(locale, "batchpage;Download.errorfile", new Object[] {}) + "</a> " + errorFile.length() + " bytes, " + FileUtils.countLines(errorFile) + " lines</td>\n"); } else { res.append( " <td>" + I18N.getString(locale, "batchpage;No.errorfile", new Object[] {}) + "</td>\n"); } } catch (NetarkivetException e) { // Handle unretrievable batchjob. String errMsg = "Unable to instantiate '" + batchClassPath + "' as a batchjob."; log.warn(errMsg, e); // clear the string builder. res = new StringBuilder(); res.append(I18N.getString(locale, "batchpage;Warning.0", errMsg) + "\n"); res.append(" <td>" + batchClassPath + "</td>\n"); res.append(" <td>" + "--" + "</td>\n"); res.append(" <td>" + "--" + "</td>\n"); res.append(" <td>" + "--" + "</td>\n"); } return res.toString(); }
From source file:cz.incad.Kramerius.security.rightscommands.post.Edit.java
@Override public void doCommand() { try {//from ww w. j a v a 2s.c o m HttpServletRequest req = this.requestProvider.get(); //Right right = RightsServlet.createRightFromPost(req, rightsManager, userManager, criteriumWrapperFactory); Map values = new HashMap(); Enumeration parameterNames = req.getParameterNames(); while (parameterNames.hasMoreElements()) { String key = (String) parameterNames.nextElement(); String value = req.getParameter(key); SimpleJSONObjects simpleJSONObjects = new SimpleJSONObjects(); simpleJSONObjects.createMap(key, values, value); } List affectedObjects = (List) values.get("affectedObjects"); for (int i = 0; i < affectedObjects.size(); i++) { String pid = affectedObjects.get(i).toString(); editRight((Map) values.get("data"), pid); } } catch (NumberFormatException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } }
From source file:cz.incad.Kramerius.security.rightscommands.post.Create.java
@Override public void doCommand() { try {//ww w . ja v a 2s. c o m HttpServletRequest req = this.requestProvider.get(); //Right right = RightsServlet.createRightFromPost(req, rightsManager, userManager, criteriumWrapperFactory); Map values = new HashMap(); Enumeration parameterNames = req.getParameterNames(); while (parameterNames.hasMoreElements()) { String key = (String) parameterNames.nextElement(); String value = req.getParameter(key); SimpleJSONObjects simpleJSONObjects = new SimpleJSONObjects(); simpleJSONObjects.createMap(key, values, value); } List affectedObjects = (List) values.get("affectedObjects"); for (int i = 0; i < affectedObjects.size(); i++) { String pid = affectedObjects.get(i).toString(); insertRight((Map) values.get("data"), pid); } } catch (NumberFormatException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } }
From source file:biblivre3.marcutils.MarcUtils.java
public static Record jsonToRecord(JSONObject json, MaterialType mt, RecordStatus status) { if (json == null) { return null; }/*w w w.j a va 2 s . c o m*/ Record record = null; try { String strLeader = null; if (json.has("000")) { strLeader = json.getString("000"); } MarcFactory factory = MarcFactory.newInstance(); Leader leader = MarcUtils.createLeader(strLeader, mt, status); record = factory.newRecord(leader); Iterator<String> dataFieldsIterator = json.sortedKeys(); while (dataFieldsIterator.hasNext()) { String dataFieldTag = dataFieldsIterator.next(); try { Integer dataFieldIntTag = Integer.valueOf(dataFieldTag); if (dataFieldIntTag == 0) { continue; } else if (dataFieldIntTag < 10) { ControlField cf = factory.newControlField(dataFieldTag, json.getString(dataFieldTag)); record.addVariableField(cf); } else { JSONArray subFieldsArray = json.getJSONArray(dataFieldTag); for (int i = 0; i < subFieldsArray.length(); i++) { JSONObject subFieldJson = subFieldsArray.getJSONObject(i); DataField df = factory.newDataField(); df.setTag(dataFieldTag); df.setIndicator1(' '); df.setIndicator2(' '); Iterator<String> dfIterator = subFieldJson.sortedKeys(); while (dfIterator.hasNext()) { String subFieldTag = dfIterator.next(); if (subFieldTag.equals("ind1")) { df.setIndicator1(subFieldJson.getString(subFieldTag).charAt(0)); } else if (subFieldTag.equals("ind2")) { df.setIndicator2(subFieldJson.getString(subFieldTag).charAt(0)); } else { JSONArray subFieldDataArray = subFieldJson.getJSONArray(subFieldTag); for (int j = 0; j < subFieldDataArray.length(); j++) { String subfieldData = subFieldDataArray.getString(j); Subfield sf = factory.newSubfield(subFieldTag.charAt(0), subfieldData); df.addSubfield(sf); } } } record.addVariableField(df); } } } catch (NumberFormatException nfe) { log.error(nfe.getMessage(), nfe); } } } catch (JSONException je) { log.error(je.getMessage(), je); } return record; }
From source file:example.TableExample.java
private boolean delete(ChaincodeStub stub, String[] args) { int fieldID = 0; try {/*from ww w. j av a2s .com*/ fieldID = Integer.parseInt(args[0]); } catch (NumberFormatException e) { log.error("Illegal field id -" + e.getMessage()); return false; } TableProto.Column queryCol = TableProto.Column.newBuilder().setUint32(fieldID).build(); List<TableProto.Column> key = new ArrayList<>(); key.add(queryCol); return stub.deleteRow(tableName, key); }