Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

In this page you can find the example usage for java.lang NumberFormatException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.centralperf.service.CSVResultService.java

/**
 * Build a sample based on a CSV line and information about the headers names and orders
 * @param headerInfo   Information about headers
 * @param CSVline      Array of string/*  w  w  w  . j  av a2 s . c o  m*/
 * @return   a sample
 */
public Sample buildSampleFromCSVLine(CSVHeaderInfo headerInfo, String[] CSVline) {
    if (isHeaderLine(CSVline)) {
        return null;
    }
    Sample sample = new Sample();
    try {
        // Try first to get a timestamp
        sample.setTimestamp(
                new Date(new Long(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_TIMESTAMP, CSVline))));
    } catch (NumberFormatException e) {
        // Try to parse this format : 2012/10/30 12:47:47
        SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        try {
            sample.setTimestamp(
                    parserSDF.parse(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_TIMESTAMP, CSVline)));
        } catch (ParseException e1) {
            log.error("Error on CSV parsing:" + e.getMessage(), e1);
        }
    }

    try {
        sample.setElapsed(new Long(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_ELAPSED, CSVline)));
    } catch (NumberFormatException e) {
    }
    sample.setSampleName(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_SAMPLENAME, CSVline));

    String status = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_STATUS, CSVline);
    if (status != null) {
        sample.setStatus(status);
    }

    String assertResult = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_ASSERTRESULT, CSVline);
    if (assertResult != null) {
        sample.setAssertResult(
                new Boolean(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_ASSERTRESULT, CSVline)));
    }

    String sizeString = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_SIZEINBYTES, CSVline);

    // TODO : manage format errors
    if (sizeString != null && !"".equals(sizeString.trim())) {
        try {
            sample.setSizeInOctet(new Long(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_SIZEINBYTES, CSVline)));
        } catch (NumberFormatException exception) {
        }
    } else {
        sample.setSizeInOctet(0);
    }

    String latencyString = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_LATENCY, CSVline);
    if (latencyString != null && !"".equals(latencyString.trim())) {
        try {
            sample.setLatency(new Long(headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_LATENCY, CSVline)));
        } catch (NumberFormatException exception) {
        }
    }

    String grpThreads = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_GROUPTHREADS, CSVline);
    if (grpThreads != null)
        sample.setGrpThreads(new Long(grpThreads));
    String allThreads = headerInfo.getValue(CSVHeaderInfo.CSV_HEADER_ALLTHREADS, CSVline);
    if (allThreads != null)
        sample.setAllThreads(new Long(allThreads));

    return sample;
}

From source file:de.fraunhofer.iosb.ilt.sta.service.Service.java

private <T> ServiceResponse<T> executePatch(ServiceRequest request) {
    ServiceResponse<T> response = new ServiceResponse<>();
    PersistenceManager pm = null;//from  w w w .ja v a 2s .  c  om
    try {
        if (request.getUrlPath() == null || request.getUrlPath().equals("/")) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        ResourcePath path;
        try {
            path = PathParser.parsePath(settings.getServiceRootUrl(), request.getUrlPath());
        } catch (NumberFormatException e) {
            return response.setStatus(404, "Not a valid id.");
        } catch (IllegalStateException e) {
            return response.setStatus(404, "Not a valid id: " + e.getMessage());
        }
        if (!(path.getMainElement() instanceof EntityPathElement)
                || path.getMainElement() != path.getLastElement()) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        EntityPathElement mainEntity = (EntityPathElement) path.getMainElement();
        if (mainEntity.getId() == null) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        if (request.getUrlQuery() != null && !request.getUrlQuery().isEmpty()) {
            return response.setStatus(400, "Not query options allowed on PACTH.");
        }
        EntityParser entityParser = new EntityParser(LongId.class);
        EntityType type = mainEntity.getEntityType();
        Entity entity;
        try {
            entity = entityParser.parseEntity(type.getImplementingClass(), request.getContent());
        } catch (JsonParseException | IncompleteEntityException e) {
            LOGGER.error("Could not parse json.", e);
            return response.setStatus(400, "Could not parse json.");
        }

        pm = PersistenceManagerFactory.getInstance().create();
        try {

            if (pm.update(mainEntity, entity)) {
                pm.commitAndClose();
                response.setCode(200);
            } else {
                LOGGER.debug("Failed to update entity.");
                pm.rollbackAndClose();
            }
        } catch (IllegalArgumentException | NoSuchEntityException e) {
            pm.rollbackAndClose();
            response.setStatus(400, e.getMessage());
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        if (pm != null) {
            pm.rollbackAndClose();
        }
    }
    return response;
}

From source file:de.fraunhofer.iosb.ilt.sta.service.Service.java

private <T> ServiceResponse<T> executePut(ServiceRequest request) {
    ServiceResponse<T> response = new ServiceResponse<>();
    PersistenceManager pm = null;//w  w  w.  j a  va  2  s. com
    try {
        if (request.getUrlPath() == null || request.getUrlPath().equals("/")) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        ResourcePath path;
        try {
            path = PathParser.parsePath(settings.getServiceRootUrl(), request.getUrlPath());
        } catch (NumberFormatException e) {
            return response.setStatus(404, "Not a valid id.");
        } catch (IllegalStateException e) {
            return response.setStatus(404, "Not a valid id: " + e.getMessage());
        }
        if (!(path.getMainElement() instanceof EntityPathElement)
                || path.getMainElement() != path.getLastElement()) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        EntityPathElement mainEntity = (EntityPathElement) path.getMainElement();
        if (mainEntity.getId() == null) {
            return response.setStatus(400, "PATCH only allowed on Entities.");
        }
        if (request.getUrlQuery() != null && !request.getUrlQuery().isEmpty()) {
            return response.setStatus(400, "Not query options allowed on PACTH.");
        }
        EntityParser entityParser = new EntityParser(LongId.class);
        EntityType type = mainEntity.getEntityType();
        Entity entity;
        try {
            entity = entityParser.parseEntity(type.getImplementingClass(), request.getContent());
            entity.complete(true);
            entity.setEntityPropertiesSet();
        } catch (JsonParseException | IncompleteEntityException e) {
            LOGGER.error("Could not parse json.", e);
            return response.setStatus(400, "Could not parse json.");
        }

        pm = PersistenceManagerFactory.getInstance().create();
        try {

            if (pm.update(mainEntity, entity)) {
                pm.commitAndClose();
                response.setCode(200);
            } else {
                LOGGER.debug("Failed to update entity.");
                pm.rollbackAndClose();
            }
        } catch (NoSuchEntityException e) {
            pm.rollbackAndClose();
            response.setStatus(400, e.getMessage());
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        if (pm != null) {
            pm.rollbackAndClose();
        }
    }
    return response;
}

From source file:net.solarnetwork.node.control.demandbalancer.DemandBalancer.java

private Integer percentForLimit(NodeControlInfo limit) {
    if (limit == null || limit.getValue() == null) {
        return null;
    }//  ww w .ja  v a 2  s.co m
    try {
        return Integer.valueOf(limit.getValue());
    } catch (NumberFormatException e) {
        log.warn("Error parsing limit value as integer percentage: {}", e.getMessage());
    }
    return null;
}

From source file:de.fraunhofer.iosb.ilt.sta.service.Service.java

private <T> ServiceResponse<T> executeGet(ServiceRequest request) {
    ServiceResponse<T> response = new ServiceResponse<>();
    PersistenceManager pm = null;/* ww w  . ja v a2s  . com*/
    try {

        ResourcePath path;
        try {
            path = PathParser.parsePath(settings.getServiceRootUrl(), request.getUrlPath());
        } catch (NumberFormatException e) {
            return response.setStatus(404, "Not a valid id.");
        } catch (IllegalStateException e) {
            return response.setStatus(404, "Not a valid id: " + e.getMessage());
        }
        Query query = null;
        try {
            query = QueryParser.parseQuery(request.getUrlQuery(), settings);
        } catch (IllegalArgumentException e) {
            return response.setStatus(404, "Invalid query: " + e.getMessage());
        }
        try {
            query.validate(path);
        } catch (IllegalArgumentException ex) {
            return response.setStatus(400, ex.getMessage());
        }
        pm = PersistenceManagerFactory.getInstance().create();
        if (!pm.validatePath(path)) {
            response.setStatus(404, "Nothing found.");
            pm.commitAndClose();
            return response;
        }
        T object;
        try {
            object = (T) pm.get(path, query);
        } catch (UnsupportedOperationException e) {
            LOGGER.error("Unsupported operation.", e);
            response.setStatus(500, "Unsupported operation: " + e.getMessage());
            pm.rollbackAndClose();
            return response;
        } catch (IllegalArgumentException e) {
            LOGGER.debug("Illegal operation.", e);
            response.setStatus(400, "Illegal operation: " + e.getMessage());
            pm.rollbackAndClose();
            return response;
        } catch (ClassCastException e) {
            LOGGER.error("Result did not match expected format", e);
            response.setStatus(500, "Illegal result type: " + e.getMessage());
            pm.rollbackAndClose();
            return response;
        }
        if (object == null) {
            response.setStatus(404, "Nothing found.");
            pm.commitAndClose();
            return response;
        }
        response.setResult(object);
        response.setResultFormatted(
                request.getFormatter().format(path, query, object, settings.isUseAbsoluteNavigationLinks()));
        response.setCode(200);
        pm.commitAndClose();
    } catch (Exception e) {
        response.setStatus(500, "Failed to execute query. See logs for details.");
        LOGGER.error("", e);
    } finally {
        if (pm != null) {
            pm.rollbackAndClose();
        }
    }
    return response;
}

From source file:dumptspacket.Main.java

public void start(String[] args) throws org.apache.commons.cli.ParseException {
    final String fileName;
    final Long limit;
    final Set<Integer> pids;

    System.out.println("args   : " + dumpArgs(args));

    final Option fileNameOption = Option.builder("f").required().longOpt("filename").desc("ts??")
            .hasArg().type(String.class).build();

    final Option limitOption = Option.builder("l").required(false).longOpt("limit")
            .desc("??(???????EOF??)").hasArg()
            .type(Long.class).build();

    final Option pidsOption = Option.builder("p").required().longOpt("pids")
            .desc("pid(?16?)").type(String.class).hasArgs().build();

    Options opts = new Options();
    opts.addOption(fileNameOption);/*from  ww  w . j  a  v a2 s. c o  m*/
    opts.addOption(limitOption);
    opts.addOption(pidsOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cl;
    HelpFormatter help = new HelpFormatter();

    try {

        // parse options
        cl = parser.parse(opts, args);

        // handle interface option.
        fileName = cl.getOptionValue(fileNameOption.getOpt());
        if (fileName == null) {
            throw new ParseException("????????");
        }

        // handlet destination option.
        Long xl = null;
        try {
            xl = Long.parseUnsignedLong(cl.getOptionValue(limitOption.getOpt()));
        } catch (NumberFormatException e) {
            xl = null;
        } finally {
            limit = xl;
        }

        Set<Integer> x = new HashSet<>();
        List<String> ls = new ArrayList<>();
        ls.addAll(Arrays.asList(cl.getOptionValues(pidsOption.getOpt())));
        for (String s : ls) {
            try {
                x.add(Integer.parseUnsignedInt(s, 16));
            } catch (NumberFormatException e) {
                throw new ParseException(e.getMessage());
            }
        }
        pids = Collections.unmodifiableSet(x);

        System.out.println("Starting application...");
        System.out.println("filename   : " + fileName);
        System.out.println("limit : " + limit);
        System.out.println("pids : " + dumpSet(pids));

        // your code
        TsReader reader;
        if (limit == null) {
            reader = new TsReader(new File(fileName), pids);
        } else {
            reader = new TsReader(new File(fileName), pids, limit);
        }

        Map<Integer, List<TsPacketParcel>> ret = reader.getPackets();
        try {
            for (Integer pid : ret.keySet()) {

                FileWriter writer = new FileWriter(fileName + "_" + Integer.toHexString(pid) + ".txt");

                for (TsPacketParcel par : ret.get(pid)) {
                    String text = Hex.encodeHexString(par.getPacket().getData());
                    writer.write(text + "\n");

                }
                writer.flush();
                writer.close();
            }
        } catch (IOException ex) {
            LOG.fatal("", ex);
        }

    } catch (ParseException e) {
        // print usage.
        help.printHelp("My Java Application", opts);
        throw e;
    } catch (FileNotFoundException ex) {
        LOG.fatal("", ex);
    }
}

From source file:de.fraunhofer.iosb.ilt.sta.service.Service.java

private <T> ServiceResponse<T> executePost(ServiceRequest request) {
    ServiceResponse<T> response = new ServiceResponse<>();
    String urlPath = request.getUrlPath();
    if (urlPath == null || urlPath.equals("/")) {
        return response.setStatus(400, "POST only allowed to Collections.");
    }/* w  w  w. j  av  a  2s  .  co m*/

    // TODO: If we get more of these special urls, come up with a nicer way to handle 'em.
    if (urlPath.equals("/CreateObservations")) {
        return handleCreateObservations(request, response);
    }

    PersistenceManager pm = null;
    try {
        ResourcePath path;
        try {
            path = PathParser.parsePath(settings.getServiceRootUrl(), urlPath);
        } catch (NumberFormatException e) {
            return response.setStatus(404, "Not a valid id.");
        } catch (IllegalStateException e) {
            return response.setStatus(404, "Not a valid id: " + e.getMessage());
        }
        if (!(path.getMainElement() instanceof EntitySetPathElement)) {
            return response.setStatus(400, "POST only allowed to Collections.");
        }
        if (request.getUrlQuery() != null && !request.getUrlQuery().isEmpty()) {
            return response.setStatus(400, "Not query options allowed on POST.");
        }

        EntitySetPathElement mainSet = (EntitySetPathElement) path.getMainElement();
        EntityType type = mainSet.getEntityType();
        EntityParser entityParser = new EntityParser(LongId.class);
        Entity entity;
        try {
            entity = entityParser.parseEntity(type.getImplementingClass(), request.getContent());
            entity.complete(mainSet);
        } catch (JsonMappingException | IncompleteEntityException | IllegalStateException ex) {
            LOGGER.debug("Post failed.", ex.getMessage());
            LOGGER.debug("Exception:", ex);
            return response.setStatus(400, ex.getMessage());
        }

        pm = PersistenceManagerFactory.getInstance().create();
        try {
            if (pm.insert(entity)) {
                pm.commitAndClose();
                String url = UrlHelper.generateSelfLink(path, entity);
                try {
                    response.setResult((T) entity);
                } catch (ClassCastException ex) {
                    LOGGER.debug("Could not cas result to desired format", ex);
                }
                response.setCode(201);
                response.addHeader("location", url);
            } else {
                LOGGER.debug("Failed to insert entity.");
                pm.rollbackAndClose();
                return response.setStatus(400, "Failed to insert entity.");
            }
        } catch (IllegalArgumentException | IncompleteEntityException | NoSuchEntityException e) {
            pm.rollbackAndClose();
            return response.setStatus(400, e.getMessage());
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        return response.setStatus(500, "Failed to store data.");
    } finally {
        if (pm != null) {
            pm.rollbackAndClose();
        }
    }
    return response;
}

From source file:com.skelril.aurora.jail.CSVJailCellDatabase.java

@Override
public synchronized boolean load() {

    FileInputStream input = null;
    boolean successful = true;

    try {/*from w ww .j a  v  a  2  s  . co m*/
        input = new FileInputStream(cellFile);
        InputStreamReader streamReader = new InputStreamReader(input, "utf-8");
        CSVReader reader = new CSVReader(new BufferedReader(streamReader));
        String[] line;

        while ((line = reader.readNext()) != null) {
            if (line.length < 6) {
                log.warning("A cell entry with < 6 fields was found!");
                continue;
            }
            try {
                String name = line[0].trim().toLowerCase();
                String prison = line[1].trim().toLowerCase();
                String world = line[2].trim();
                int x = Integer.parseInt(line[3]);
                int y = Integer.parseInt(line[4]);
                int z = Integer.parseInt(line[5]);
                if ("".equals(name) || "null".equals(name))
                    name = null;
                if (name == null)
                    continue;
                JailCell jailCell = new JailCell(name, prison, world, x, y, z);
                Map<String, JailCell> map = nameJailCell.get(prison);
                if (map == null) {
                    map = new HashMap<>();
                    nameJailCell.put(prison, map);
                }
                map.put(name, jailCell);
                jailCells.add(jailCell);
            } catch (NumberFormatException e) {
                log.warning("Non-int int field found in cell!");
            }
        }
        log.info(jailCells.size() + " jail cell(s) loaded.");
    } catch (FileNotFoundException ignored) {
    } catch (IOException e) {
        nameJailCell = new HashMap<>();
        log.warning("Failed to load " + cellFile.getAbsolutePath() + ": " + e.getMessage());
        successful = false;
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ignored) {
            }
        }
    }
    return successful;
}

From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java

@RequestMapping(value = "/acknowledgeAlert", method = RequestMethod.GET)
public void acknowledgeAlert(HttpServletRequest request, HttpServletResponse response) throws IOException {
    int alertId;//from w  w  w  .j a v  a2  s .  c o  m
    ObjectNode responseJSON = mapper.createObjectNode();

    try {
        alertId = Integer.valueOf(request.getParameter("alertId"));
    } catch (NumberFormatException e) {
        // Empty json response
        response.getOutputStream().write(responseJSON.toString().getBytes());
        if (LOGGER.finerEnabled()) {
            LOGGER.finer(e.getMessage());
        }
        return;
    }

    try {
        // get cluster object
        Cluster cluster = Repository.get().getCluster();

        // set alert is acknowledged
        cluster.acknowledgeAlert(alertId);
        responseJSON.put("status", "deleted");
    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}

From source file:net.di2e.ecdr.commons.query.rest.parsers.BasicQueryParser.java

@Override
public int getCount(MultivaluedMap<String, String> queryParameters) throws UnsupportedQueryException {
    String stringCount = queryParameters.getFirst(SearchConstants.COUNT_PARAMETER);
    int count = this.defaultCount;
    LOGGER.debug("Attempting to set 'count' value from request [{}] to int", stringCount);
    if (StringUtils.isNotBlank(stringCount)) {
        try {/*w  w w.  j a v a2 s.  c o m*/
            count = Integer.parseInt(stringCount);
        } catch (NumberFormatException e) {
            String message = "Invalid Number found for 'count' [" + stringCount + "].  Resulted in exception: "
                    + e.getMessage();
            LOGGER.warn(message);
            throw new UnsupportedQueryException(message);
        }
    } else {
        LOGGER.debug("'count' parameter was not specified, defaulting value to [{}]", count);
    }
    return count;
}