Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:de.prozesskraft.pkraft.Manager.java

/**
 * startet einen thread, der zeitgesteuert aufwacht und den prozess weiterschiebt
 *//*  www.ja va2 s .  co m*/
private static void startZyklischerThread(int initialWaitSecond) {
    // falls dieser thread von hier aus gestartet wird, soll kurz gewartet werden
    try {
        Thread.sleep(initialWaitSecond * 1000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // einen timer thread erstellen, der regelmaessig den prozess aufweckt, auch wenn sehr langlaufende steps gerade aktiv sind
    new Thread(new Runnable() {
        public void run() {

            // flag, ob dieser thread einen neuen gestartet hat
            boolean spawn = false;

            System.err.println(new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: start");
            while (!exit && !spawn) {

                long tatsaechlicheSleepDauer = (long) (factorSleepBecauseOfLoadAverage
                        * ((loopMinutes * 60 * 1000) + fuzzyness));
                try {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: sleeping " + tatsaechlicheSleepDauer / 1000
                            + " seconds (loopMinutes=" + loopMinutes + ", faktorSleepBecauseOfLoadAverage="
                            + factorSleepBecauseOfLoadAverage + ", fuzzyness=" + fuzzyness + ")");
                    Thread.sleep(tatsaechlicheSleepDauer);
                } catch (NumberFormatException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                // war der letzte zugriff laenger als der haelfte der regulaeren wartezeit her? Dann Prozess pushen
                if ((System.currentTimeMillis() - lastRun) > (0.5 * tatsaechlicheSleepDauer)) {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: last process push has been MORE than 0.5 * "
                            + tatsaechlicheSleepDauer / 1000 + " seconds ago at " + new Timestamp(lastRun));
                    System.err.println(
                            new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: waking up");

                    if (watcherThread != null) {
                        System.err.println(new Timestamp(System.currentTimeMillis())
                                + ": ---- alternative thread: interrupting watcherThread");

                        watcherThread.interrupt();
                        watcherThread = null;
                    }

                    // ein neuer 
                    startZyklischerThread(5);
                    spawn = true;

                    pushProcessAsFarAsPossible(line.getOptionValue("instance"), false);

                    System.err.println(
                            new Timestamp(System.currentTimeMillis()) + ": ----- alternative thread: end");
                } else {
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: last process push has been LESS than 0.5 * "
                            + tatsaechlicheSleepDauer / 1000 + " seconds ago at " + new Timestamp(lastRun));
                    System.err.println(new Timestamp(System.currentTimeMillis())
                            + ": ---- alternative thread: going to sleep again");

                }

            }

            // thread beenden
            System.err.println(new Timestamp(System.currentTimeMillis()) + ": ---- alternative thread: exit");
        }
    }).start();
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the numerical value of the text contained in the specified child element of the given element as a double
 * (if it denotes a double).//from w w  w.j av a 2s  .  c  om
 * <p>
 * 
 * @param name
 *          name of the child element
 * @param namespace
 *          namespace of the child element
 * @param node
 *          current element
 * @param defaultValue
 *          value to be used if the specified element is missing or it's value is not numerical
 * @return the textual contents of the element as a double-value
 */
public static double getDoubleValue(final String name, final String namespace, final Node node,
        final double defaultValue) {
    double value = defaultValue;
    final String textValue = getStringValue(name, namespace, node, null);

    if (textValue != null) {
        try {
            value = Double.parseDouble(textValue);
        } catch (final NumberFormatException e) {
            e.printStackTrace();
        }
    }

    return value;
}

From source file:com.laurencedawson.image_management.ImageManager.java

/**
 * Grab and save an image directly to disk
 * @param file The Bitmap file/*  w  ww .ja  v a2 s  . co m*/
 * @param url The URL of the image
 * @param imageCallback The callback associated with the request
 */
public static void cacheImage(final File file, ImageRequest imageCallback) {

    HttpURLConnection urlConnection = null;
    FileOutputStream fileOutputStream = null;
    InputStream inputStream = null;
    boolean isGif = false;

    try {
        // Setup the connection
        urlConnection = (HttpURLConnection) new URL(imageCallback.mUrl).openConnection();
        urlConnection.setConnectTimeout(ImageManager.LONG_CONNECTION_TIMEOUT);
        urlConnection.setReadTimeout(ImageManager.LONG_REQUEST_TIMEOUT);
        urlConnection.setUseCaches(true);
        urlConnection.setInstanceFollowRedirects(true);

        // Set the progress to 0
        imageCallback.sendProgressUpdate(imageCallback.mUrl, 0);

        // Connect
        inputStream = urlConnection.getInputStream();

        // Do not proceed if the file wasn't downloaded
        if (urlConnection.getResponseCode() == 404) {
            urlConnection.disconnect();
            return;
        }

        // Check if the image is a GIF
        String contentType = urlConnection.getHeaderField("Content-Type");
        if (contentType != null) {
            isGif = contentType.equals(GIF_MIME);
        }

        // Grab the length of the image
        int length = 0;
        try {
            String fileLength = urlConnection.getHeaderField("Content-Length");
            if (fileLength != null) {
                length = Integer.parseInt(fileLength);
            }
        } catch (NumberFormatException e) {
            if (ImageManager.DEBUG) {
                e.printStackTrace();
            }
        }

        // Write the input stream to disk
        fileOutputStream = new FileOutputStream(file, true);
        int byteRead = 0;
        int totalRead = 0;
        final byte[] buffer = new byte[8192];
        int frameCount = 0;

        // Download the image
        while ((byteRead = inputStream.read(buffer)) != -1) {

            // If the image is a gif, count the start of frames
            if (isGif) {
                for (int i = 0; i < byteRead - 3; i++) {
                    if (buffer[i] == 33 && buffer[i + 1] == -7 && buffer[i + 2] == 4) {
                        frameCount++;

                        // Once we have at least one frame, stop the download
                        if (frameCount > 1) {
                            fileOutputStream.write(buffer, 0, i);
                            fileOutputStream.close();

                            imageCallback.sendProgressUpdate(imageCallback.mUrl, 100);
                            imageCallback.sendCachedCallback(imageCallback.mUrl, true);

                            urlConnection.disconnect();
                            return;
                        }
                    }
                }
            }

            // Write the buffer to the file and update the total number of bytes
            // read so far (used for the callback)
            fileOutputStream.write(buffer, 0, byteRead);
            totalRead += byteRead;

            // Update the callback with the current progress
            if (length > 0) {
                imageCallback.sendProgressUpdate(imageCallback.mUrl,
                        (int) (((float) totalRead / (float) length) * 100));
            }
        }

        // Tidy up after the download
        if (fileOutputStream != null) {
            fileOutputStream.close();
        }

        // Sent the callback that the image has been downloaded
        imageCallback.sendCachedCallback(imageCallback.mUrl, true);

        if (inputStream != null) {
            inputStream.close();
        }

        // Disconnect the connection
        urlConnection.disconnect();
    } catch (final MalformedURLException e) {
        if (ImageManager.DEBUG) {
            e.printStackTrace();
        }

        // If the file exists and an error occurred, delete the file
        if (file != null) {
            file.delete();
        }

    } catch (final IOException e) {
        if (ImageManager.DEBUG) {
            e.printStackTrace();
        }

        // If the file exists and an error occurred, delete the file
        if (file != null) {
            file.delete();
        }

    }

}

From source file:org.apache.tika.parser.geo.topic.GeoNameResolver.java

/**
 * Index gazetteer's one line data by built-in Lucene Index functions
 * /*from   w w w  .ja v  a2 s  . c o m*/
 * @param indexWriter
 *            Lucene indexWriter to be loaded
 * @param line
 *            a line from the gazetteer file
 * @throws IOException
 * @throws NumberFormatException
 */
private static void addDoc(IndexWriter indexWriter, final String line) {
    String[] tokens = line.split("\t");

    int ID = Integer.parseInt(tokens[0]);
    String name = tokens[1];
    String alternatenames = tokens[3];

    Double latitude = -999999.0;
    try {
        latitude = Double.parseDouble(tokens[4]);
    } catch (NumberFormatException e) {
        latitude = OUT_OF_BOUNDS;
    }
    Double longitude = -999999.0;
    try {
        longitude = Double.parseDouble(tokens[5]);
    } catch (NumberFormatException e) {
        longitude = OUT_OF_BOUNDS;
    }

    Document doc = new Document();
    doc.add(new IntField("ID", ID, Field.Store.YES));
    doc.add(new TextField("name", name, Field.Store.YES));
    doc.add(new DoubleField("longitude", longitude, Field.Store.YES));
    doc.add(new DoubleField("latitude", latitude, Field.Store.YES));
    doc.add(new TextField("alternatenames", alternatenames, Field.Store.YES));
    try {
        indexWriter.addDocument(doc);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.n52.geoar.newdata.PluginLoader.java

/**
 * Extracts and parses the geoar-plugin.xml plugin-descriptor to create and
 * fill a {@link PluginInfo} instance./*  ww w  . j  av a2 s  . c om*/
 * 
 * @param pluginFile
 * @return
 */
private static PluginInfo readPluginInfoFromPlugin(File pluginFile) {
    try {
        ZipFile zipFile = new ZipFile(pluginFile);
        ZipEntry pluginDescriptorEntry = zipFile.getEntry("geoar-plugin.xml");
        if (pluginDescriptorEntry == null) {
            return null;
        }

        Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(zipFile.getInputStream(pluginDescriptorEntry));
        // Find name
        String name = null;
        NodeList nodeList = document.getElementsByTagName("name");
        if (nodeList != null && nodeList.getLength() >= 1) {
            name = nodeList.item(0).getTextContent();
        } else {
            LOG.warn("Plugin Descriptor for " + pluginFile.getName() + " does not specify a name");
        }

        // Find publisher
        String publisher = null;
        nodeList = document.getElementsByTagName("publisher");
        if (nodeList != null && nodeList.getLength() >= 1) {
            publisher = nodeList.item(0).getTextContent();
        } else {
            LOG.warn("Plugin Descriptor for " + pluginFile.getName() + " does not specify a publisher");
        }

        // Find description
        String description = null;
        nodeList = document.getElementsByTagName("description");
        if (nodeList != null && nodeList.getLength() >= 1) {
            description = nodeList.item(0).getTextContent();
        } else {
            LOG.warn("Plugin Descriptor for " + pluginFile.getName() + " does not specify a description");
        }

        // Find identifier
        String identifier = null;
        nodeList = document.getElementsByTagName("identifier");
        if (nodeList != null && nodeList.getLength() >= 1) {
            identifier = nodeList.item(0).getTextContent();
        } else {
            LOG.warn("Plugin Descriptor for " + pluginFile.getName() + " does not specify an identifier");
        }

        // Find version
        Long version = null;
        nodeList = document.getElementsByTagName("version");
        if (nodeList != null && nodeList.getLength() >= 1) {
            String versionString = "-" + nodeList.item(0).getTextContent();

            Matcher matcher = pluginVersionPattern.matcher(versionString);
            if (matcher.find() && matcher.group(1) != null) {
                try {
                    version = parseVersionNumber(matcher.group(1));
                } catch (NumberFormatException e) {
                    LOG.error("Plugin filename version invalid: " + matcher.group(1));
                }
            }
        } else {
            LOG.warn("Plugin Descriptor for " + pluginFile.getName() + " does not specify a version");
        }

        if (identifier == null) {
            identifier = name;
        }

        return new PluginInfo(pluginFile, name, description, version, identifier, publisher);
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:MyCounter.java

public void init(org.apache.xalan.extensions.XSLProcessorContext context, org.w3c.dom.Element elem) {
    String name = elem.getAttribute("name");
    String value = elem.getAttribute("value");
    int val;
    try {/*www .ja  v a  2s  .c o m*/
        val = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        val = 0;
    }
    counters.put(name, new Integer(val));
}

From source file:org.mifos.framework.util.helpers.MifosDoubleConverter.java

@Override
public Object convert(Class type, Object value) {
    Double returnValue = null;//from   w w w .ja va  2s  .  c o  m
    if (value != null && type != null && !"".equals(value)) {
        try {
            if (value instanceof String) {
                returnValue = new LocalizationConverter().getDoubleValueForCurrentLocale((String) value);
            } else {
                returnValue = new LocalizationConverter().getDoubleValueForCurrentLocale(value.toString());
            }
        } catch (NumberFormatException ne) {
            ne.printStackTrace();
        }
    }
    return returnValue;
}

From source file:com.sisrni.converter.PropuestaConvenioConverter.java

@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
    value = String.valueOf(value);
    if (JsfUtil.isDummySelectItem(component, value)) {
        return null;
    }/*from   ww w. j av  a 2  s . c o m*/

    if (value != null && value.trim().length() > 0 && !value.equalsIgnoreCase("null")) {
        try {
            return this.propuestaConvenioService.getByID(getKey(value));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new ConverterException(
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
        }
    } else {
        return null;
    }

}

From source file:com.sisrni.converter.TipoPropuestaConvenioConverter.java

@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
    value = String.valueOf(value);

    if (JsfUtil.isDummySelectItem(component, value)) {
        return null;
    }/*from www .j a v a2 s  .  c om*/

    if (value != null && value.trim().length() > 0 && !value.equalsIgnoreCase("null")) {
        try {
            return this.tipoPropuestaConvenioService.findById(getKey(value));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new ConverterException(
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
        }
    } else {
        return null;
    }
}

From source file:com.sisrni.converter.EscuelaDepartamentoConverter.java

@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
    value = String.valueOf(value);

    if (JsfUtil.isDummySelectItem(component, value)) {
        return null;
    }//from   w ww  .  ja  va2s.  co m

    if (value != null && value.trim().length() > 0 && !value.equalsIgnoreCase("null")) {
        try {
            return this.escuelaDepartamentoService.findById(getKey(value));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new ConverterException(
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid theme."));
        }
    } else {
        return null;
    }

}