Example usage for java.lang Short toString

List of usage examples for java.lang Short toString

Introduction

In this page you can find the example usage for java.lang Short toString.

Prototype

public static String toString(short s) 

Source Link

Document

Returns a new String object representing the specified short .

Usage

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAst.CFAstISOCountryLanguageHPKey.java

public String toString() {
    String ret = "<CFAstISOCountryLanguageHPKey" + " RequiredISOCountryId=" + "\""
            + Short.toString(getRequiredISOCountryId()) + "\"" + " RequiredISOLanguageId=" + "\""
            + Short.toString(getRequiredISOLanguageId()) + "\"" + " RequiredRevision=\""
            + Integer.toString(getRequiredRevision()) + "\"" + "/>";
    return (ret);
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.CFAccISOCountryCurrencyHPKey.java

public String toString() {
    String ret = "<CFAccISOCountryCurrencyHPKey" + " RequiredISOCountryId=" + "\""
            + Short.toString(getRequiredISOCountryId()) + "\"" + " RequiredISOCurrencyId=" + "\""
            + Short.toString(getRequiredISOCurrencyId()) + "\"" + " RequiredRevision=\""
            + Integer.toString(getRequiredRevision()) + "\"" + "/>";
    return (ret);
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.CFAccISOCountryLanguageHPKey.java

public String toString() {
    String ret = "<CFAccISOCountryLanguageHPKey" + " RequiredISOCountryId=" + "\""
            + Short.toString(getRequiredISOCountryId()) + "\"" + " RequiredISOLanguageId=" + "\""
            + Short.toString(getRequiredISOLanguageId()) + "\"" + " RequiredRevision=\""
            + Integer.toString(getRequiredRevision()) + "\"" + "/>";
    return (ret);
}

From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java

@SuppressWarnings("StringBufferReplaceableByString")
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern,
        String columnNamePattern) throws SQLException {
    ResultSet resultSet = null;//from   w ww .  java  2  s .c o m
    VitessStatement vitessStatement = new VitessStatement(this.connection);
    ArrayList<ArrayList<String>> data = new ArrayList<>();
    //Null Matches All
    if (null == columnNamePattern) {
        columnNamePattern = "%";
    }
    if (null == catalog || catalog.length() == 0) {
        catalog = this.connection.getCatalog();
    }
    try {
        ArrayList<String> tableList = new ArrayList<>();
        ResultSet tables = null;
        if (null == tableNamePattern) {
            try {
                tables = getTables(catalog, schemaPattern, "%", new String[0]);
                while (tables.next()) {
                    String tableName = tables.getString("TABLE_NAME");
                    tableList.add(tableName);
                }
            } finally {
                if (null != tables) {
                    tables.close();
                }
            }
        } else {
            try {
                tables = getTables(catalog, schemaPattern, tableNamePattern, new String[0]);
                while (tables.next()) {
                    String tableName = tables.getString("TABLE_NAME");
                    tableList.add(tableName);
                }
            } finally {
                if (null != tables) {
                    tables.close();
                }
            }
        }
        for (String tableName : tableList) {
            resultSet = null;
            try {

                // Return correct ordinals if column name pattern is not '%'
                // Currently, MySQL doesn't show enough data to do this, so we do it the 'hard' way...Once
                // _SYSTEM tables are in, this should be
                // much easier
                boolean fixUpOrdinalsRequired = false;
                Map<String, Integer> ordinalFixUpMap = null;
                if (!columnNamePattern.equals("%")) {
                    fixUpOrdinalsRequired = true;
                    vitessStatement = new VitessStatement(this.connection);
                    resultSet = vitessStatement.executeQuery("SHOW FULL COLUMNS FROM " + this.quotedId
                            + tableName + this.quotedId + " FROM " + this.quotedId + catalog + this.quotedId);
                    ordinalFixUpMap = new HashMap<>();

                    int fullOrdinalPos = 1;
                    while (resultSet.next()) {
                        String fullOrdColName = resultSet.getString("Field");
                        ordinalFixUpMap.put(fullOrdColName, fullOrdinalPos++);
                    }
                }
                resultSet = vitessStatement.executeQuery("SHOW FULL COLUMNS FROM " + this.quotedId + tableName
                        + this.quotedId + " FROM " + this.quotedId + catalog + this.quotedId + " LIKE "
                        + Constants.LITERAL_SINGLE_QUOTE + columnNamePattern + Constants.LITERAL_SINGLE_QUOTE);
                int ordPos = 1;

                while (resultSet.next()) {
                    ArrayList<String> row = new ArrayList<>();
                    row.add(0, catalog);
                    row.add(1, null);
                    row.add(2, tableName);
                    row.add(3, resultSet.getString("Field"));
                    TypeDescriptor typeDesc = new TypeDescriptor(resultSet.getString("Type"),
                            resultSet.getString("Null"));

                    row.add(4, Short.toString(typeDesc.dataType));

                    // DATA_TYPE (jdbc)
                    row.add(5, typeDesc.typeName); // TYPE_NAME
                    // (native)
                    if (null == typeDesc.columnSize) {
                        row.add(6, null);
                    } else {
                        String collation = resultSet.getString("Collation");
                        int mbminlen = 1;
                        if (collation != null
                                && ("TEXT".equals(typeDesc.typeName) || "TINYTEXT".equals(typeDesc.typeName)
                                        || "MEDIUMTEXT".equals(typeDesc.typeName))) {
                            if (collation.indexOf("ucs2") > -1 || collation.indexOf("utf16") > -1) {
                                mbminlen = 2;
                            } else if (collation.indexOf("utf32") > -1) {
                                mbminlen = 4;
                            }
                        }
                        row.add(6, mbminlen == 1 ? typeDesc.columnSize.toString()
                                : Integer.toString(typeDesc.columnSize / mbminlen));
                    }
                    row.add(7, Integer.toString(typeDesc.bufferLength));
                    row.add(8, typeDesc.decimalDigits == null ? null : typeDesc.decimalDigits.toString());
                    row.add(9, Integer.toString(typeDesc.numPrecRadix));
                    row.add(10, Integer.toString(typeDesc.nullability));

                    //
                    // Doesn't always have this field, depending on version
                    //
                    //
                    // REMARK column
                    //
                    row.add(11, "Comment");

                    // COLUMN_DEF
                    row.add(12, resultSet.getString("Default") == null ? null : resultSet.getString("Default"));

                    row.add(13, Integer.toString(0));// SQL_DATA_TYPE
                    row.add(14, Integer.toString(0));// SQL_DATE_TIME_SUB

                    if (StringUtils.indexOfIgnoreCase(typeDesc.typeName, "CHAR") != -1
                            || StringUtils.indexOfIgnoreCase(typeDesc.typeName, "BLOB") != -1
                            || StringUtils.indexOfIgnoreCase(typeDesc.typeName, "TEXT") != -1
                            || StringUtils.indexOfIgnoreCase(typeDesc.typeName, "BINARY") != -1) {
                        row.add(15, row.get(6)); // CHAR_OCTET_LENGTH
                    } else {
                        row.add(15, Integer.toString(0));
                    }

                    // ORDINAL_POSITION
                    if (!fixUpOrdinalsRequired) {
                        row.add(16, Integer.toString(ordPos++));
                    } else {
                        String origColName = resultSet.getString("Field");
                        Integer realOrdinal = ordinalFixUpMap.get(origColName);

                        if (realOrdinal != null) {
                            row.add(16, realOrdinal.toString());
                        } else {
                            throw new SQLException(
                                    "Can not find column in full column list to determine true ordinal position.");
                        }
                    }

                    row.add(17, typeDesc.isNullable);

                    // We don't support REF or DISTINCT types
                    row.add(18, null);
                    row.add(19, null);
                    row.add(20, null);
                    row.add(21, null);
                    String extra = resultSet.getString("Extra");
                    if (null != extra) {
                        row.add(22,
                                StringUtils.indexOfIgnoreCase(extra, "auto_increment") != -1 ? "YES" : "NO");
                        row.add(23, StringUtils.indexOfIgnoreCase(extra, "generated") != -1 ? "YES" : "NO");
                    }
                    data.add(row);
                }
            } finally {
                if (null != resultSet) {
                    resultSet.close();
                }
            }
        }
    } finally {
        if (null != resultSet) {
            resultSet.close();
        }
        vitessStatement.close();
    }

    String[] columnNames = new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE",
            "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE",
            "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH",
            "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATALOG", "SCOPE_SCHEMA", "SCOPE_TABLE",
            "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN" };

    Query.Type[] columnType = new Query.Type[] { Query.Type.CHAR, Query.Type.CHAR, Query.Type.CHAR,
            Query.Type.CHAR, Query.Type.INT32, Query.Type.CHAR, Query.Type.INT32, Query.Type.INT32,
            Query.Type.INT32, Query.Type.INT32, Query.Type.INT32, Query.Type.CHAR, Query.Type.CHAR,
            Query.Type.INT32, Query.Type.INT32, Query.Type.INT32, Query.Type.INT32, Query.Type.CHAR,
            Query.Type.CHAR, Query.Type.CHAR, Query.Type.CHAR, Query.Type.INT16, Query.Type.CHAR,
            Query.Type.CHAR };

    return new VitessResultSet(columnNames, columnType, data, this.connection);
}

From source file:net.sf.taverna.t2.activities.apiconsumer.ApiConsumerActivity.java

/**
 * Converts an object into its string representation.
 *
 * @param resultObject//from  w w  w .j a va  2  s  . co  m
 * @return
 */
private String convertObjectToString(Object resultObject) {

    if (resultObject instanceof String) {
        return (String) resultObject;
    } else if (resultObject instanceof BigInteger) {
        return new String(((BigInteger) resultObject).toString());
    } else if (resultObject instanceof BigDecimal) {
        return new String(((BigDecimal) resultObject).toString());
    } else if (resultObject instanceof Double) {
        return new String(Double.toString((Double) resultObject));
    } else if (resultObject instanceof Float) {
        return new String(Float.toString((Float) resultObject));
    } else if (resultObject instanceof Integer) {
        return new String(Integer.toString((Integer) resultObject));
    } else if (resultObject instanceof Long) {
        return new String(Long.toString((Long) resultObject));
    } else if (resultObject instanceof Short) {
        return new String(Short.toString((Short) resultObject));
    } else if (resultObject instanceof Boolean) {
        return new String(Boolean.toString((Boolean) resultObject));
    }
    if (resultObject instanceof char[]) {
        return new String((char[]) resultObject);
    } else {// Should not happen
        return "Error";
    }
}

From source file:gov.llnl.lc.smt.command.node.SmtNode.java

public static String getStatus(OpenSmMonitorService OMService) {
    // return a string representation of the node statistics, similar to the smt-console
    if (OMService == null) {
        logger.severe("Crap, its null!");
        return "Can't get status from a null object";
    }//from   www  .j av a2s.  co  m
    OSM_Fabric Fabric = OMService.getFabric();
    StringBuffer buff = new StringBuffer();
    OSM_Nodes AllNodes = (Fabric == null) ? null : Fabric.getOsmNodes();

    BinList<PFM_Node> pNodes = new BinList<PFM_Node>();
    ArrayList<PFM_Node> pmna = new ArrayList<PFM_Node>();
    int totalSW = 0;
    int totalSWp = 0;
    int totalCA = 0;
    int totalCAp = 0;
    int totalNodes = 0;
    int cumPorts = 0;
    int totalPorts = 0;

    if (AllNodes != null) {
        PFM_Node[] pna = AllNodes.getPerfMgrNodes();
        SBN_Node[] sna = AllNodes.getSubnNodes();

        // the perfmgr may not have returned data due to start-up delay, check
        if ((pna != null) && (sna != null)) {
            pmna = new ArrayList<PFM_Node>(Arrays.asList(pna));

            String key = null;
            for (PFM_Node pn : pmna) {
                key = Short.toString(pn.getNum_ports()) + Boolean.toString(pn.isEsp0());
                pNodes.add(pn, key);
            }

            totalNodes = totalCA + totalSW;
            totalPorts = totalCAp + totalSWp;

            // total nodes, ports and links, broken down by type
            OsmServerStatus RStatus = OMService.getRemoteServerStatus();

            buff.append(String.format("                 Node Status\n"));
            buff.append(SmtConstants.NEW_LINE);
            buff.append(String.format("Fabric Name:                %20s\n", Fabric.getFabricName()));
            if (RStatus != null)
                buff.append(String.format("Up since:                   %20s\n",
                        OMService.getRemoteServerStatus().Server.getStartTime().toString()));
            buff.append(String.format("timestamp:                  %20s\n", Fabric.getTimeStamp().toString()));
            buff.append(SmtConstants.NEW_LINE);

            buff.append("---node type--------# nodes--# ports---cum ports" + SmtConstants.NEW_LINE);
            // totals per type
            int pn_type = 0;
            int nports = 0;
            String esp = "";
            for (ArrayList<PFM_Node> pn : pNodes) {
                // each node in the bin looks identical, so just use the first one
                PFM_Node p = pn.get(0);
                pn_type = p.getNum_ports() > 2 ? 2 : 1;
                esp = p.isEsp0() ? " (w. esp0)" : "";

                cumPorts = pn.size() * p.num_ports;
                nports = p.isEsp0() ? p.num_ports - 1 : p.num_ports;
                cumPorts = pn.size() * nports;

                buff.append(getStatLine(OSM_NodeType.get(pn_type).getFullName() + esp, pn.size(), p.num_ports,
                        cumPorts) + SmtConstants.NEW_LINE);

                totalNodes += pn.size();
                totalPorts += cumPorts;
            }
            buff.append(SmtConstants.NEW_LINE);
            String stringFormat1 = "%-17s %7s  %7s  %9s";
            buff.append(String.format(stringFormat1, "all (excl. esp0):", Integer.toString(totalNodes), "",
                    Integer.toString(totalPorts)) + SmtConstants.NEW_LINE);
        }
    } else {
        logger.warning("The OSM_Nodes seems to be null");
    }
    return buff.toString();
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatterMgr.java

/**
 * Constructs a the fields for a numeric formatter.
 * //w  ww .j  av  a 2s  . c o  m
 * @param formatter the formatter to be augmented
 */
protected void addFieldsForNumeric(final UIFieldFormatter formatter) {
    int len;
    Class<?> cls = formatter.getDataClass();
    if (cls == BigDecimal.class) {
        len = formatter.getPrecision() + formatter.getScale() + 1;
    } else {
        if (cls == Long.class) {
            len = Long.toString(Long.MAX_VALUE).length();
        } else if (cls == Integer.class) {
            len = Integer.toString(Integer.MAX_VALUE).length();
        } else if (cls == Short.class) {
            len = Short.toString(Short.MAX_VALUE).length();
        } else if (cls == Byte.class) {
            len = Byte.toString(Byte.MAX_VALUE).length();
        } else if (cls == Double.class) {
            len = String.format("%f", Double.MAX_VALUE).length();
        } else if (cls == Float.class) {
            len = String.format("%f", Float.MAX_VALUE).length();

        } else {
            len = formatter.getLength();
            //throw new RuntimeException("Missing case for numeric class ["+ cls.getName() + "]");
        }
        len = Math.min(len, 10);
    }
    StringBuilder sb = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
        sb.append(' ');
    }
    formatter.getFields()
            .add(new UIFieldFormatterField(UIFieldFormatterField.FieldType.numeric, len, sb.toString(), false));
}

From source file:io.vitess.jdbc.VitessMySQLDatabaseMetadata.java

public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException {
    if (null == table) {
        throw new SQLException("Table cannot be null");
    }/*from   ww w  .j  av  a  2 s.  co  m*/
    ResultSet resultSet = null;
    VitessStatement vitessStatement = null;
    ArrayList<ArrayList<String>> data = new ArrayList<>();

    StringBuilder getVersionColumnsQB = new StringBuilder();
    getVersionColumnsQB.append("SHOW COLUMNS FROM ");
    getVersionColumnsQB.append(this.quotedId);
    getVersionColumnsQB.append(table);
    getVersionColumnsQB.append(this.quotedId);
    getVersionColumnsQB.append(" FROM ");
    getVersionColumnsQB.append(this.quotedId);
    getVersionColumnsQB.append(catalog);
    getVersionColumnsQB.append(this.quotedId);
    getVersionColumnsQB.append(" WHERE Extra LIKE '%on update CURRENT_TIMESTAMP%'");

    try {
        vitessStatement = new VitessStatement(this.connection);
        resultSet = vitessStatement.executeQuery(getVersionColumnsQB.toString());
        ArrayList<String> row;
        while (resultSet.next()) {
            row = new ArrayList<>();
            TypeDescriptor typeDesc = new TypeDescriptor(resultSet.getString("Type"),
                    resultSet.getString("Null"));
            row.add(0, null);
            row.add(1, resultSet.getString("Field"));
            row.add(2, Short.toString(typeDesc.dataType));
            row.add(3, typeDesc.typeName);
            row.add(4, typeDesc.columnSize == null ? null : typeDesc.columnSize.toString());
            row.add(5, Integer.toString(typeDesc.bufferLength));
            row.add(6, typeDesc.decimalDigits == null ? null : typeDesc.decimalDigits.toString());
            row.add(7, Integer.toString(java.sql.DatabaseMetaData.versionColumnNotPseudo));
            data.add(row);
        }
    } finally {
        if (null != resultSet) {
            resultSet.close();
            vitessStatement.close();
        }
    }
    String[] columnNames = new String[] { "SCOPE", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE",
            "BUFFER_LENGTH", "DECIMAL_DIGITS", "PSEUDO_COLUMN" };

    Query.Type[] columnType = new Query.Type[] { Query.Type.INT16, Query.Type.CHAR, Query.Type.INT32,
            Query.Type.CHAR, Query.Type.INT32, Query.Type.INT32, Query.Type.INT16, Query.Type.INT16 };
    return new VitessResultSet(columnNames, columnType, data, this.connection);
}

From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTA117FileReader.java

private void readData(DataReader reader) throws IOException {
    logger.fine("Data section; at offset " + reader.getByteOffset() + "; dta map offset: "
            + dtaMap.getOffset_data());//from  w  ww. java  2 s.co m
    logger.fine("readData(): start");
    reader.readOpeningTag(TAG_DATA);
    // TODO: 
    // check that we are at the right byte offset!

    int nvar = dataTable.getVarQuantity().intValue();
    int nobs = dataTable.getCaseQuantity().intValue();

    int[] variableByteLengths = getVariableByteLengths(variableTypes);
    int bytes_per_row = calculateBytesPerRow(variableByteLengths);

    logger.fine("data dimensions[observations x variables] = (" + nobs + "x" + nvar + ")");
    logger.fine("bytes per row=" + bytes_per_row + " bytes");
    logger.fine("variableTypes=" + Arrays.deepToString(variableTypes));

    // create a File object to save the tab-delimited data file
    FileOutputStream fileOutTab = null;
    PrintWriter pwout = null;
    File tabDelimitedDataFile = File.createTempFile("tempTabfile.", ".tab");

    // save the temp tab-delimited file in the return ingest object:        
    ingesteddata.setTabDelimitedFile(tabDelimitedDataFile);

    fileOutTab = new FileOutputStream(tabDelimitedDataFile);
    pwout = new PrintWriter(new OutputStreamWriter(fileOutTab, "utf8"), true);

    logger.fine("Beginning to read data stream.");

    for (int i = 0; i < nobs; i++) {
        //byte[] dataRowBytes = new byte[bytes_per_row];
        Object[] dataRow = new Object[nvar];

        //int nbytes = stream.read(dataRowBytes, 0, bytes_per_row);
        //dataRowBytes = reader.readBytes(bytes_per_row);
        // TODO: 
        // maybe intercept any potential exceptions here, and add more 
        // diagnostic info, before re-throwing...
        int byte_offset = 0;
        for (int columnCounter = 0; columnCounter < nvar; columnCounter++) {

            String varType = variableTypes[columnCounter];

            // 4.0 Check if this is a time/date variable: 
            boolean isDateTimeDatum = false;
            // TODO: 
            // make sure the formats are properly set! -- use the old 
            // plugin as a model... 
            String formatCategory = dataTable.getDataVariables().get(columnCounter).getFormatCategory();
            if (formatCategory != null && (formatCategory.equals("time") || formatCategory.equals("date"))) {
                isDateTimeDatum = true;
            }

            // TODO: 
            // ditto
            String variableFormat = dateVariableFormats[columnCounter];

            if (varType == null || varType.equals("")) {
                throw new IOException("Undefined variable type encountered in readData()");
            }

            // TODO: 
            // double-check that the missing values constants are still correct!
            if (varType.equals("Byte")) {
                // (signed) Byte
                byte byte_datum = reader.readSignedByte();

                logger.fine(i + "-th row " + columnCounter + "=th column byte =" + byte_datum);
                if (byte_datum >= BYTE_MISSING_VALUE) {
                    logger.fine(i + "-th row " + columnCounter + "=th column byte MV=" + byte_datum);
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;
                } else {
                    dataRow[columnCounter] = byte_datum;
                    logger.fine(i + "-th row " + columnCounter + "-th column byte value=" + byte_datum);
                }

                byte_offset++;
            } else if (varType.equals("Integer")) {
                short short_datum = (short) reader.readShortSignedInteger();

                logger.fine(i + "-th row " + columnCounter + "=th column stata int =" + short_datum);

                if (short_datum >= INT_MISSIG_VALUE) {
                    logger.fine(i + "-th row " + columnCounter + "=th column stata long missing value="
                            + short_datum);
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;
                } else {

                    if (isDateTimeDatum) {

                        DecodedDateTime ddt = decodeDateTimeData("short", variableFormat,
                                Short.toString(short_datum));
                        logger.fine(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format="
                                + ddt.format);
                        dataRow[columnCounter] = ddt.decodedDateTime;
                        //dateFormat[columnCounter][i] = ddt.format;
                        dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format);

                    } else {
                        dataRow[columnCounter] = short_datum;
                        logger.fine(
                                i + "-th row " + columnCounter + "-th column \"integer\" value=" + short_datum);
                    }
                }
                byte_offset += 2;
            } else if (varType.equals("Long")) {
                // stata-Long (= java's int: 4 byte), signed.

                int int_datum = reader.readSignedInteger();

                if (int_datum >= LONG_MISSING_VALUE) {
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;
                } else {
                    if (isDateTimeDatum) {
                        DecodedDateTime ddt = decodeDateTimeData("int", variableFormat,
                                Integer.toString(int_datum));
                        logger.fine(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format="
                                + ddt.format);
                        dataRow[columnCounter] = ddt.decodedDateTime;
                        dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format);

                    } else {
                        dataRow[columnCounter] = int_datum;
                        logger.fine(i + "-th row " + columnCounter + "-th column \"long\" value=" + int_datum);
                    }

                }
                byte_offset += 4;
            } else if (varType.equals("Float")) {
                // STATA float 
                // same as Java float - 4-byte

                float float_datum = reader.readFloat();

                logger.fine(i + "-th row " + columnCounter + "=th column float =" + float_datum);
                if (FLOAT_MISSING_VALUE_SET.contains(float_datum)) {
                    logger.fine(
                            i + "-th row " + columnCounter + "=th column float missing value=" + float_datum);
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;

                } else {

                    if (isDateTimeDatum) {
                        DecodedDateTime ddt = decodeDateTimeData("float", variableFormat,
                                doubleNumberFormatter.format(float_datum));
                        logger.fine(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format="
                                + ddt.format);
                        dataRow[columnCounter] = ddt.decodedDateTime;
                        dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format);
                    } else {
                        dataRow[columnCounter] = float_datum;
                        logger.fine(i + "-th row " + columnCounter + "=th column float value:" + float_datum);
                        // This may be temporary - but for now (as in, while I'm testing 
                        // 4.0 ingest against 3.* ingest, I need to be able to tell if a 
                        // floating point value was a single, or double float in the 
                        // original STATA file: -- L.A. Jul. 2014
                        dataTable.getDataVariables().get(columnCounter).setFormat("float");
                        // ?
                    }

                }
                byte_offset += 4;
            } else if (varType.equals("Double")) {
                // STATA double
                // same as Java double - 8-byte

                double double_datum = reader.readDouble();

                if (DOUBLE_MISSING_VALUE_SET.contains(double_datum)) {
                    logger.finer(
                            i + "-th row " + columnCounter + "=th column double missing value=" + double_datum);
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;
                } else {

                    if (isDateTimeDatum) {
                        DecodedDateTime ddt = decodeDateTimeData("double", variableFormat,
                                doubleNumberFormatter.format(double_datum));
                        logger.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format="
                                + ddt.format);
                        dataRow[columnCounter] = ddt.decodedDateTime;
                        dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format);
                    } else {
                        logger.fine(i + "-th row " + columnCounter + "=th column double value:" + double_datum); //doubleNumberFormatter.format(double_datum));

                        dataRow[columnCounter] = double_datum; //doubleNumberFormatter.format(double_datum);
                    }

                }
                byte_offset += 8;
            } else if (varType.matches("^STR[1-9][0-9]*")) {
                // String case
                int strVarLength = variableByteLengths[columnCounter];
                logger.fine(
                        i + "-th row " + columnCounter + "=th column is a string (" + strVarLength + " bytes)");
                //String raw_datum = new String(Arrays.copyOfRange(dataRowBytes, byte_offset,
                //        (byte_offset + strVarLength)), "ISO-8859-1");
                // (old) TODO: 
                // is it the right thing to do, to default to "ISO-8859-1"?
                // (it may be; since there's no mechanism for specifying
                // alternative encodings in Stata, this may be their default;
                // it just needs to be verified. -- L.A. Jul. 2014)
                // ACTUALLY, in STATA13, it appears that STRF *MUST*
                // be limited to ASCII. Binary strings can be stored as 
                // STRLs. (Oct. 6 2014)

                //String string_datum = getNullStrippedString(raw_datum);
                String string_datum = reader.readString(strVarLength);
                if (string_datum.length() < 64) {
                    logger.fine(i + "-th row " + columnCounter + "=th column string =" + string_datum);
                } else {
                    logger.fine(i + "-th row " + columnCounter + "=th column string ="
                            + string_datum.substring(0, 64) + "... (truncated)");
                }
                if (string_datum.equals("")) {

                    logger.fine(
                            i + "-th row " + columnCounter + "=th column string missing value=" + string_datum);

                    // TODO: 
                    /* Is this really a missing value case? 
                     * Or is it an honest empty string? 
                     * Is there such a thing as a missing value for a String in Stata?
                     * -- L.A. 4.0
                     */
                    dataRow[columnCounter] = MissingValueForTabDelimitedFile;
                } else {
                    /*
                     * Some special characters, like new lines and tabs need to 
                     * be escaped - otherwise they will break our TAB file 
                     * structure! 
                     */

                    dataRow[columnCounter] = escapeCharacterString(string_datum);
                }
                byte_offset += strVarLength;
            } else if (varType.equals("STRL")) {
                //throw new IOException("<Support for STRLs not yet implemented>");
                logger.fine("STRL encountered.");

                if (cachedGSOs == null) {
                    cachedGSOs = new LinkedHashMap<>();
                }

                // Reading the (v,o) pair: 
                long v = 0;
                long o = 0;
                String voPair = null;
                // first v:

                v = reader.readInteger();
                byte_offset += 4;

                // then o:

                o = reader.readInteger();
                byte_offset += 4;

                // create v,o pair; save, for now:

                voPair = v + "," + o;
                dataRow[columnCounter] = voPair;

                // TODO: 
                // Validate v and o? 
                // Making sure v <= varNum and o < numbObs; 
                // or, if o == numObs, v <= columnCounter; 
                // -- per the Stata 13 spec...

                if (!(v == columnCounter + 1 && o == i + 1)) {
                    if (!cachedGSOs.containsKey(voPair)) {
                        cachedGSOs.put(voPair, "");
                        // this means we need to cache this GSO, when 
                        // we read the STRLS section later on. 
                    }
                }

            } else {
                logger.warning("unknown variable type found: " + varType);
                String errorMessage = "unknown variable type encounted when reading data section: " + varType;
                //throw new InvalidObjectException(errorMessage);
                throw new IOException(errorMessage);

            }
        } // for (columnCounter)

        if (byte_offset != bytes_per_row) {
            throw new IOException("Unexpected number of bytes read for data row " + i + "; " + bytes_per_row
                    + " expected, " + byte_offset + " read.");
        }

        // Dump the row of data to the tab-delimited file:
        pwout.println(StringUtils.join(dataRow, "\t"));

        logger.fine("finished reading " + i + "-th row");

    } // for (rows)

    pwout.close();

    reader.readClosingTag(TAG_DATA);
    logger.fine("DTA117 Ingest: readData(): end.");

}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmDb2LUW.CFCrmDb2LUWISOCountryCurrencyTable.java

public CFCrmCursor openISOCountryCurrencyCursorByCountryIdx(CFCrmAuthorization Authorization,
        short ISOCountryId) {
    String sql = getSqlSelectISOCountryCurrencyBuff() + "WHERE " + "iccy.ISOCountryId = "
            + Short.toString(ISOCountryId) + " " + "ORDER BY " + "iccy.ISOCountryId ASC" + ", "
            + "iccy.ISOCurrencyId ASC";
    CFCrmCursor cursor = new CFCrmDb2LUWCursor(Authorization, schema, sql);
    return (cursor);
}