Example usage for java.util IllegalFormatException printStackTrace

List of usage examples for java.util IllegalFormatException printStackTrace

Introduction

In this page you can find the example usage for java.util IllegalFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:edu.hawaii.soest.pacioos.text.SimpleTextSource.java

/**
 * Constructor: create an instance of the simple SimpleTextSource
 * @param xmlConfig /* w w w  .  j a  va  2s  .  c om*/
 */
public SimpleTextSource(XMLConfiguration xmlConfig) throws ConfigurationException {

    this.xmlConfig = xmlConfig;
    // Pull the general configuration from the properties file
    Configuration config = new PropertiesConfiguration("textsource.properties");
    this.archiveMode = config.getString("textsource.archive_mode");
    this.rbnbChannelName = config.getString("textsource.rbnb_channel");
    this.serverName = config.getString("textsource.server_name ");
    this.delimiter = config.getString("textsource.delimiter");
    this.pollInterval = config.getInt("textsource.poll_interval");
    this.retryInterval = config.getInt("textsource.retry_interval");
    this.defaultDateFormat = new SimpleDateFormat(config.getString("textsource.default_date_format"));

    // parse the record delimiter from the config file
    // set the XML configuration in the simple text source for later use
    this.setConfiguration(xmlConfig);

    // set the common configuration fields
    String connectionType = this.xmlConfig.getString("connectionType");
    this.setConnectionType(connectionType);
    String channelName = xmlConfig.getString("channelName");
    this.setChannelName(channelName);
    String identifier = xmlConfig.getString("identifier");
    this.setIdentifier(identifier);
    String rbnbName = xmlConfig.getString("rbnbName");
    this.setRBNBClientName(rbnbName);
    String rbnbServer = xmlConfig.getString("rbnbServer");
    this.setServerName(rbnbServer);
    int rbnbPort = xmlConfig.getInt("rbnbPort");
    this.setServerPort(rbnbPort);
    int archiveMemory = xmlConfig.getInt("archiveMemory");
    this.setCacheSize(archiveMemory);
    int archiveSize = xmlConfig.getInt("archiveSize");
    this.setArchiveSize(archiveSize);

    // set the default channel information 
    Object channels = xmlConfig.getList("channels.channel.name");
    int totalChannels = 1;
    if (channels instanceof Collection) {
        totalChannels = ((Collection<?>) channels).size();

    }
    // find the default channel with the ASCII data string
    for (int i = 0; i < totalChannels; i++) {
        boolean isDefaultChannel = xmlConfig.getBoolean("channels.channel(" + i + ")[@default]");
        if (isDefaultChannel) {
            String name = xmlConfig.getString("channels.channel(" + i + ").name");
            this.setChannelName(name);
            String dataPattern = xmlConfig.getString("channels.channel(" + i + ").dataPattern");
            this.setPattern(dataPattern);
            String fieldDelimiter = xmlConfig.getString("channels.channel(" + i + ").fieldDelimiter");
            // handle hex-encoded field delimiters
            if (fieldDelimiter.startsWith("0x") || fieldDelimiter.startsWith("\\x")) {

                Byte delimBytes = Byte.parseByte(fieldDelimiter.substring(2), 16);
                byte[] delimAsByteArray = new byte[] { delimBytes.byteValue() };
                String delim = null;
                try {
                    delim = new String(delimAsByteArray, 0, delimAsByteArray.length, "ASCII");

                } catch (UnsupportedEncodingException e) {
                    throw new ConfigurationException("There was an error parsing the field delimiter."
                            + " The message was: " + e.getMessage());
                }
                this.setDelimiter(delim);

            } else {
                this.setDelimiter(fieldDelimiter);

            }
            String[] recordDelimiters = xmlConfig
                    .getStringArray("channels.channel(" + i + ").recordDelimiters");
            this.setRecordDelimiters(recordDelimiters);
            // set the date formats list
            List<String> dateFormats = (List<String>) xmlConfig
                    .getList("channels.channel(" + i + ").dateFormats.dateFormat");
            if (dateFormats.size() != 0) {
                for (String dateFormat : dateFormats) {

                    // validate the date format string
                    try {
                        SimpleDateFormat format = new SimpleDateFormat(dateFormat);

                    } catch (IllegalFormatException ife) {
                        String msg = "There was an error parsing the date format " + dateFormat
                                + ". The message was: " + ife.getMessage();
                        if (log.isDebugEnabled()) {
                            ife.printStackTrace();
                        }
                        throw new ConfigurationException(msg);
                    }
                }
                setDateFormats(dateFormats);
            } else {
                log.warn("No date formats have been configured for this instrument.");
            }

            // set the date fields list
            List<String> dateFieldList = xmlConfig.getList("channels.channel(" + i + ").dateFields.dateField");
            List<Integer> dateFields = new ArrayList<Integer>();
            if (dateFieldList.size() != 0) {
                for (String dateField : dateFieldList) {
                    try {
                        Integer newDateField = new Integer(dateField);
                        dateFields.add(newDateField);
                    } catch (NumberFormatException e) {
                        String msg = "There was an error parsing the dateFields. The message was: "
                                + e.getMessage();
                        throw new ConfigurationException(msg);
                    }
                }
                setDateFields(dateFields);

            } else {
                log.warn("No date fields have been configured for this instrument.");
            }
            String timeZone = xmlConfig.getString("channels.channel(" + i + ").timeZone");
            this.setTimezone(timeZone);
            break;
        }

    }

    // Check the record delimiters length and set the first and optionally second delim characters
    if (this.recordDelimiters.length == 1) {
        this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue();
    } else if (this.recordDelimiters.length == 2) {
        this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue();
        this.secondDelimiterByte = (byte) Integer.decode(this.recordDelimiters[1]).byteValue();

    } else {
        throw new ConfigurationException("The recordDelimiter must be one or two characters, "
                + "separated by a pipe symbol (|) if there is more than one delimiter character.");
    }
    byte[] delimiters = new byte[] {};

}

From source file:edu.cmu.tetrad.sem.SemIm.java

/**
 * Returns a string representation of the Sem (pretty detailed).
 *///from w w  w .  j av  a 2 s.  co m
public String toString() {
    List<String> varNames = new ArrayList<String>();

    for (Node node : variableNodes)
        varNames.add(node.getName());

    StringBuilder buf = new StringBuilder();

    buf.append("\nVariable nodes:\n\n");
    buf.append(getVariableNodes());

    buf.append("\n\nMeasured nodes:\n\n");
    buf.append(getMeasuredNodes());

    buf.append("\n\nEdge coefficient matrix:\n");
    buf.append(MatrixUtils.toStringSquare(edgeCoef().toArray(), varNames));

    buf.append("\n\nError covariance matrix:\n");
    buf.append(MatrixUtils.toStringSquare(getErrCovar().toArray(), varNames));

    buf.append("\n\nVariable means:\n");

    for (int i = 0; i < getVariableNodes().size(); i++) {
        buf.append("\nMean(");
        buf.append(getVariableNodes().get(i));
        buf.append(") = ");
        buf.append(variableMeans[i]);
    }

    buf.append("\n\nSample size = ");
    buf.append(this.sampleSize);

    if (sampleCovarC == null) {
        buf.append("\n\nSample covaraince matrix not specified**");
    } else {
        buf.append("\n\nsample cov:\n");
        buf.append(MatrixUtils.toString(getSampleCovar().toArray()));
    }

    buf.append("\n\nimplCovar:\n");

    try {
        buf.append(MatrixUtils.toString(implCovar().toArray()));
    } catch (IllegalFormatException e) {
        e.printStackTrace();
    }

    buf.append("\n\nimplCovarMeas:\n");
    buf.append(MatrixUtils.toString(implCovarMeas().toArray()));

    if (sampleCovarC != null) {
        buf.append("\n\nmodel chi square = ");
        buf.append(getChiSquare());

        buf.append("\nmodel dof = ");
        buf.append(semPm.getDof());

        buf.append("\nmodel p-value = ");
        buf.append(getPValue());
    }

    buf.append("\n\nfree mappings:\n");
    for (int i = 0; i < this.freeMappings.size(); i++) {
        Mapping iMapping = this.freeMappings.get(i);
        buf.append("\n");
        buf.append(i);
        buf.append(". ");
        buf.append(iMapping);
    }

    buf.append("\n\nfixed mappings:\n");
    for (int i = 0; i < this.fixedMappings.size(); i++) {
        Mapping iMapping = this.fixedMappings.get(i);
        buf.append("\n");
        buf.append(i);
        buf.append(". ");
        buf.append(iMapping);
    }

    return buf.toString();
}