Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:edu.cornell.med.icb.io.TestConditionsParser.java

private void checkMap(final Map<String, String> expected, final Map<String, String> found) {
    if (expected == null && found == null) {
        return;/* w  w w.j a v a 2s  . co  m*/
    }
    if (expected == null) {
        // Expected is null but source is not
        fail("Source should have been null, but it was " + ArrayUtils.toString(found));
        return;
    }
    if (found == null) {
        // Found is null but expected is not
        fail("Expected to find " + ArrayUtils.toString(expected) + " but found null");
        return;
    }

    if (expected.size() != found.size()) {
        fail("Incorrect length. Expected was " + ArrayUtils.toString(expected) + " and found was "
                + ArrayUtils.toString(found));
        return;
    }
    for (final String key : found.keySet()) {
        if (!expected.containsKey(key)) {
            fail("Missing Key. Expected keys were " + ArrayUtils.toString(expected.keySet())
                    + " and found keys were " + ArrayUtils.toString(found.keySet()));
        }
        final String foundValue = found.get(key);
        final String expectedValue = expected.get(key);
        if (!foundValue.equals(expectedValue)) {
            fail("Missing Key. Value at key " + key + " was incorrect. " + " Expected " + expectedValue
                    + " but found " + foundValue);
        }
    }
}

From source file:com.circle.utils.XMLSerializer.java

private Element processJSONValue(Object value, Element root, Element target, String[] expandableProperties) {
    if (target == null) {
        target = newElement(getElementName());
    }// w  w  w  .  j  a v a2 s . c  o  m
    if (JSONUtils.isBoolean(value)) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.BOOLEAN));
        }
        target.appendChild(value.toString());
    } else if (JSONUtils.isNumber(value)) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.NUMBER));
        }
        target.appendChild(value.toString());
    } else if (JSONUtils.isFunction(value)) {
        if (value instanceof String) {
            value = JSONFunction.parse((String) value);
        }
        JSONFunction func = (JSONFunction) value;
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.FUNCTION));
        }
        String params = ArrayUtils.toString(func.getParams());
        params = params.substring(1);
        params = params.substring(0, params.length() - 1);
        target.addAttribute(new Attribute(addJsonPrefix("params"), params));
        target.appendChild(new Text("<![CDATA[" + func.getText() + "]]>"));
    } else if (JSONUtils.isString(value)) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.STRING));
        }
        target.appendChild(value.toString());
    } else if (value instanceof JSONArray) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("class"), JSONTypes.ARRAY));
        }
        target = processJSONArray((JSONArray) value, target, expandableProperties);
    } else if (value instanceof JSONObject) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("class"), JSONTypes.OBJECT));
        }
        target = processJSONObject((JSONObject) value, target, expandableProperties, false);
    } else if (JSONUtils.isNull(value)) {
        if (isTypeHintsEnabled()) {
            target.addAttribute(new Attribute(addJsonPrefix("class"), JSONTypes.OBJECT));
        }
        target.addAttribute(new Attribute(addJsonPrefix("null"), "true"));
    }
    return target;
}

From source file:edu.cornell.med.icb.io.ConditionsParser.java

/**
 * When parseFieldBean is called and the field in question has
 * ConditionField.FieldType of VALUE and
 * ConditionField.valueBeanProperty is defined, this method
 * will be used to assign the value. Not only does this work
 * with values (ConditionField.list is false),
 * it also works arrays (ConditionField.list is true). The
 * The caveat is that the target object (bean) should define
 * the property to be an array, not a collection/list/set.
 * @param field the field (not fieldName as seen elsewhere)
 * we are setting the bean value for//  w ww.  j a va2 s. c o m
 * @param targetObject the object to set the bean values on
 * or null to create a new object using class defined
 * in the key that matches ConditionField.classnameKey.
 * @param valuesMap this OPTIONAL map can be provided
 * and all values that are set on the bean will be
 * placed in this map. It is fine to pass null for this
 * paramter.
 * @throws ConditionsParsingException no data to parse,
 * beginParse or hasNext probably wasn't called (or called
 * passed the end of the data). Also thrown if there is
 * a catastrphic BeanUtils problem or a problem creating
 * an object.
 */
private void parseFieldBeanValue(final ConditionField field, final Object targetObject,
        final Map<String, String> valuesMap) throws ConditionsParsingException {
    final Object fieldValue;
    boolean isClassname = false;
    if (field.isList()) {
        fieldValue = parseFieldValueStringArray(field.getFieldName());
    } else {
        if (field.isClassname()) {
            isClassname = true;
        }
        fieldValue = parseFieldValueString(field.getFieldName());
    }
    try {
        if (isClassname) {
            final Object newObject = Class.forName((String) fieldValue).newInstance();
            BeanUtils.setProperty(targetObject, field.getValueBeanProperty(), newObject);
        } else {
            BeanUtils.setProperty(targetObject, field.getValueBeanProperty(), fieldValue);
            if (valuesMap != null) {
                valuesMap.put(field.getValueBeanProperty(), ArrayUtils.toString(fieldValue));
            }
        }
    } catch (InvocationTargetException e) {
        throw new ConditionsParsingException("BeanUtils problem " + " - InvocationTargetException for line "
                + lineNumber + " key = " + field.getValueBeanProperty() + " / value = " + fieldValue, e);
    } catch (InstantiationException e) {
        throw new ConditionsParsingException("BeanUtils problem " + " - InstantiationException for line "
                + lineNumber + " key = " + field.getValueBeanProperty() + " / value = " + fieldValue, e);
    } catch (IllegalAccessException e) {
        throw new ConditionsParsingException("BeanUtils problem " + " - IllegalAccessException for line "
                + lineNumber + " key = " + field.getValueBeanProperty() + " / value = " + fieldValue, e);
    } catch (ClassNotFoundException e) {
        throw new ConditionsParsingException(
                "Could not create new object " + " - ClassNotFoundException for line " + lineNumber + " key = "
                        + field.getValueBeanProperty() + " / value = " + fieldValue,
                e);
    }
}

From source file:com.flexive.core.storage.GenericDivisionExporter.java

/**
 * Export information about the exported division
 *
 * @param con an open and valid connection to read the data from
 * @param out destination zip output stream
 * @param sb  string builder to reuse//from w w  w .j  a  v  a2 s. c o m
 * @throws Exception on errors
 */
public void exportBuildInfos(Connection con, ZipOutputStream out, StringBuilder sb) throws Exception {
    Statement stmt = null;
    try {
        stmt = con.createStatement();
        startEntry(out, FILE_BUILD_INFOS);
        sb.setLength(0);
        sb.append("<flexive>\n");
        sb.append("  <division>").append(FxContext.get().getDivisionId()).append("</division>\n");
        sb.append("  <schema>").append(FxSharedUtils.getDBVersion()).append("</schema>\n");
        sb.append("  <build>").append(FxSharedUtils.getBuildNumber()).append("</build>\n");
        sb.append("  <verbose>")
                .append(StringEscapeUtils.escapeXml(FxSharedUtils.getFlexiveEditionFull() + " "
                        + FxSharedUtils.getFlexiveVersion() + "/build #" + FxSharedUtils.getBuildNumber()
                        + " - " + FxSharedUtils.getBuildDate()))
                .append("</verbose>\n");
        sb.append("  <appserver>").append(StringEscapeUtils.escapeXml(FxSharedUtils.getApplicationServerName()))
                .append("</appserver>\n");
        final DivisionData divisionData = FxContext.get().getDivisionData();
        sb.append("  <database>")
                .append(StringEscapeUtils
                        .escapeXml(divisionData.getDbVendor() + " - " + divisionData.getDbVersion()))
                .append("</database>\n");
        sb.append("  <dbdriver>").append(StringEscapeUtils.escapeXml(divisionData.getDbDriverVersion()))
                .append("</dbdriver>\n");
        sb.append("  <domain>").append(StringEscapeUtils.escapeXml(divisionData.getDomainRegEx()))
                .append("</domain>\n");
        sb.append("  <drops>")
                .append(StringEscapeUtils.escapeXml(ArrayUtils.toString(FxSharedUtils.getDrops())))
                .append("</drops>\n");
        sb.append("  <user>").append(FxContext.getUserTicket().getLoginName()).append("</user>\n");
        sb.append("  <date>").append(
                FxFormatUtils.getDateTimeFormat().format(new java.util.Date(System.currentTimeMillis())))
                .append("</date>\n");
        sb.append("</flexive>\n");
        write(out, sb);
        endEntry(out);
    } finally {
        Database.closeObjects(GenericDivisionExporter.class, stmt);
    }
}

From source file:edu.cornell.med.icb.goby.alignments.ExportableAlignmentEntryData.java

/**
 * For used during debugging, logging. Output the contents of a sequence variation.
 *
 * @param seqvar a sequence variation// ww w. ja  v  a  2s .c o  m
 * @return return a description of a sequence variation as a string
 */
public String seqVarToString(final Alignments.SequenceVariation seqvar) {
    final byte[] toQuals = seqvar.hasToQuality() ? seqvar.getToQuality().toByteArray() : null;
    return String.format("seqvar=[from/ref:%s, to/read:%s%s, readIndex:%d, position:%d]%n", seqvar.getFrom(),
            seqvar.getTo(), toQuals == null ? "" : " " + ArrayUtils.toString(toQuals), seqvar.getReadIndex(),
            seqvar.getPosition());
}

From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java

protected void testOrderByCreateDate(final AssetEntryQuery assetEntryQuery, String orderByType, String[] titles,
        final String[] orderedTitles) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(_group1, serviceContext);

    final SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    long createDate = 0;

    BaseModel<?>[] baseModels = new BaseModel[titles.length];

    for (int i = 0; i < titles.length; i++) {
        long delta = 1000 - (System.currentTimeMillis() - createDate);

        if (delta > 0) {
            Thread.sleep(delta);//ww w .  j  a  v a  2  s .  com
        }

        createDate = System.currentTimeMillis();

        baseModels[i] = addBaseModel(parentBaseModel, titles[i], serviceContext);
    }

    assetEntryQuery.setOrderByCol1("createDate");
    assetEntryQuery.setOrderByType1(orderByType);

    List<AssetEntry> assetEntries = search(assetEntryQuery, searchContext);

    Assert.assertEquals(ArrayUtils.toString(orderedTitles),
            ArrayUtils.toString(getTitles(assetEntries, LocaleUtil.getDefault())));
}

From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java

protected void testOrderByExpirationDate(final AssetEntryQuery assetEntryQuery, final String orderByType,
        final Date[] expirationDates) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(_group1, serviceContext);

    final SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    for (Date expirationDate : expirationDates) {
        addBaseModel(parentBaseModel, RandomTestUtil.randomString(), expirationDate, serviceContext);
    }//ww w .j  a  v  a2 s  .  co  m

    assetEntryQuery.setOrderByCol1("expirationDate");
    assetEntryQuery.setOrderByType1(orderByType);

    Arrays.sort(expirationDates);

    final DateFormat dateFormat = DateFormatFactoryUtil
            .getSimpleDateFormat(PropsValues.INDEX_DATE_FORMAT_PATTERN);

    List<AssetEntry> assetEntries = search(assetEntryQuery, searchContext);

    Assert.assertEquals(ArrayUtils.toString(format(expirationDates, dateFormat)),
            ArrayUtils.toString(format(getExpirationDates(assetEntries, orderByType), dateFormat)));
}

From source file:com.novartis.opensource.yada.util.QueryUtils.java

/**
 * This method uses a variety of variables from {@code yq} to determine the
 * number of jdbc positional parameters which must be included in the SQL
 * {@code in} clause in the stored query. Once the parameter count is
 * determined, the original SQL is amended with additional jdbc parameter
 * placeholders (i.e., {@code ?}), and the amended SQL is stored in the
 * {@code yq}.//from  w  ww  . j  a v  a2s  . c om
 * 
 * @param yq
 *          the query being processed
 * @param row
 *          the index of the list of value lists in the query containing the
 *          data to evaluate
 * @return modified SQL code
 * @deprecated as of 7.1.0
 */
@Deprecated
public String processInColumns(YADAQuery yq, int row) {
    String[] inColumns = yq.getIns();
    String coreSql = yq.getYADACode();
    LinkedHashMap<String, String[]> newData = new LinkedHashMap<>(); // to be i.e., YADA_1:[],YADA_2:[]
    if (inColumns.length > 0) {
        String[] columns = yq.getParameterizedColumns();
        Map<String, String[]> data = yq.getDataRow(row);
        char[] dataTypes = yq.getDataTypes(row);
        Matcher matcher;

        l.debug("Processing inColumns [" + StringUtils.join(inColumns, ",") + "]");
        for (String in : inColumns) {
            int colIndex = -1, j = 0;
            String inCol = in.toUpperCase(); // TODO case sensitivity

            // get the index of the 'incolumn' in the 'JDBCcolumns' array
            l.debug("Looking for column [" + inCol + "] in columns array " + ArrayUtils.toString(columns));
            while (j < columns.length && colIndex != j) {
                if (inCol.contains(columns[j])) {
                    colIndex = j;
                    l.debug("Found column [" + inCol + "] at index [" + String.valueOf(colIndex)
                            + "] of columns array.");
                    break;
                }
                j++;
            }

            // get the value list associated to the column in the data hash
            String colName = "";
            String[] inData = null;
            int inLen = 0;
            if (data.containsKey(columns[colIndex])) // JSONParams
            {
                colName = columns[colIndex];
                if (data.get(colName).length == 1) {
                    inData = data.get(colName)[0].split(",");
                    for (int m = 0; m < columns.length; m++) {
                        if (columns[m].equals(colName)) {
                            // add the new data for the column
                            newData.put(colName, inData);
                        } else {
                            // add the existing data for the column
                            newData.put(columns[m], data.get(columns[m]));
                        }
                        // add data row
                        yq.getData().set(row, newData);
                    }
                    yq.getData().set(row, newData);
                } else
                    inData = data.get(colName);
                l.debug("Splitting in args [" + data.get(colName) + "]");
            } else
            // Standard Params
            {

                // Get an array of keys to compare and potentially manipulate
                String[] colNames = new String[data.size()];
                int k = 0;
                for (String col : data.keySet()) {
                    colNames[k] = col;
                    k++;
                }

                // if colNames and columns array are of equal size,
                // then there is no param value manipulation required
                if (colNames.length == columns.length) {
                    colName = QueryUtils.YADA_COLUMN + (colIndex + 1);
                    inData = data.get(colName);
                } else
                // there is a length discrepancy
                {
                    for (int m = colIndex; m < colNames.length; m++) {
                        if (m == colIndex) // it's the first index
                            inData = data.get(colNames[m]);
                        else
                            // further indexes must build aggregate array
                            inData = (String[]) ArrayUtils.addAll(inData, data.get(colNames[m]));
                    }

                    for (int m = 0; m < columns.length; m++) {
                        if (m == columns.length - 1) {
                            // it's the last index, so add the aggregrate inData array
                            newData.put(colNames[m], inData);
                        } else {
                            // not the last index, add the existing array
                            newData.put(colNames[m], data.get(colNames[m]));
                        }
                        // add data row
                        yq.getData().set(row, newData);
                    }
                }
                l.debug("Setting IN args [" + ArrayUtils.toString(inData) + "]");
            }
            if (inData != null) {
                inLen = inData.length;
            }

            if (inLen > 1) // there's an aggregate of multiple values
            {
                l.debug("Length of value list [" + String.valueOf(inLen) + "]");
                l.debug("Getting data type of [" + columns[colIndex] + "]");
                char dt = dataTypes[colIndex];
                String dtStr = "?" + String.valueOf(dt);

                // generate the new parameter string with data type markers
                String[] pList = new String[inLen];
                for (int k = 0; k < inLen; k++) {
                    pList[k] = dtStr;
                }
                String pListStr = StringUtils.join(pList, ",");
                l.debug("New parameter list [" + pListStr + "]");

                // add additional parameters to coreSql
                String rx = "(.+)(" + inCol + "\\s+in\\s+\\(\\" + dtStr + "\\))(.*)";
                String repl = inCol + " IN (" + pListStr + ")";
                String sql = coreSql.replaceAll(NEWLINE, " ");
                l.debug("Attempting to replace part of [" + sql + "] with [" + repl + "]");
                matcher = Pattern.compile(rx, Pattern.CASE_INSENSITIVE).matcher(sql);
                if (matcher.matches()) {
                    coreSql = matcher.group(1) + repl + matcher.group(3);
                }
                l.debug("Matched clause in coreSql [" + matcher.toString() + "]");
            } // end current incolumn processing
        } // end all incolumn processing
    }
    // reset datatype and param count with new coreSql
    yq.addDataTypes(row, this.getDataTypes(coreSql));
    yq.addParamCount(row, yq.getDataTypes(row).length);

    return coreSql;
}

From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java

protected void testOrderByTitle(final AssetEntryQuery assetEntryQuery, String orderByType,
        List<Map<Locale, String>> titleMaps, final List<Map<Locale, String>> orderedTitleMaps, Locale[] locales)
        throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1.getGroupId());

    BaseModel<?> parentBaseModel = getParentBaseModel(_group1, serviceContext);

    for (Map<Locale, String> titleMap : titleMaps) {
        addBaseModel(parentBaseModel, titleMap, serviceContext);
    }//from  w  w  w.j  ava2  s.c  om

    assetEntryQuery.setOrderByCol1("title");
    assetEntryQuery.setOrderByType1(orderByType);

    final SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    for (final Locale locale : locales) {
        searchContext.setLocale(locale);

        List<AssetEntry> assetEntries = search(assetEntryQuery, searchContext);

        Assert.assertEquals(ArrayUtils.toString(getOrderedTitles(orderedTitleMaps, locale)),
                ArrayUtils.toString(getTitles(assetEntries, locale)));
    }
}

From source file:edu.harvard.iq.dvn.ingest.statdataio.impl.plugins.sav.SAVFileReader.java

void decodeRecordType3and4(BufferedInputStream stream) throws IOException {
    dbgLog.fine("***** decodeRecordType3and4(): start *****");
    Map<String, Map<String, String>> valueLabelTable = new LinkedHashMap<String, Map<String, String>>();

    int safteyCounter = 0;
    while (true) {
        try {//ww  w  .j  av a2  s. c o m
            if (stream == null) {
                throw new IllegalArgumentException("stream == null!");
            }
            // this secton may not exit so first check the 4-byte header value
            //if (stream.markSupported()){
            stream.mark(1000);
            //}
            // 3.0 check the first 4 bytes
            byte[] headerCode = new byte[LENGTH_RECORD_TYPE3_CODE];

            int nbytes_rt3 = stream.read(headerCode, 0, LENGTH_RECORD_TYPE3_CODE);
            // to-do check against nbytes
            //printHexDump(headerCode, "RT3 header test");
            ByteBuffer bb_header_code = ByteBuffer.wrap(headerCode, 0, LENGTH_RECORD_TYPE3_CODE);
            if (isLittleEndian) {
                bb_header_code.order(ByteOrder.LITTLE_ENDIAN);
            }

            int intRT3test = bb_header_code.getInt();
            dbgLog.fine("header test value: RT3=" + intRT3test);
            if (intRT3test != 3) {
                //if (stream.markSupported()){
                dbgLog.fine("iteration=" + safteyCounter);

                // We have encountered a record that's not type 3. This means we've
                // processed all the type 3/4 record pairs. So we want to rewind
                // the stream and return -- so that the appropriate record type
                // reader can be called on it.
                // But before we return, we need to save all the value labels
                // we have found:

                smd.setValueLabelTable(valueLabelTable);

                stream.reset();
                return;
                //}
            }
            // 3.1 how many value-label pairs follow
            byte[] number_of_labels = new byte[LENGTH_RT3_HOW_MANY_LABELS];

            int nbytes_3_1 = stream.read(number_of_labels);
            if (nbytes_3_1 == 0) {
                throw new IOException("RT 3: reading recordType3.1: no byte was read");
            }
            ByteBuffer bb_number_of_labels = ByteBuffer.wrap(number_of_labels, 0, LENGTH_RT3_HOW_MANY_LABELS);
            if (isLittleEndian) {
                bb_number_of_labels.order(ByteOrder.LITTLE_ENDIAN);
            }

            int numberOfValueLabels = bb_number_of_labels.getInt();
            dbgLog.fine("number of value-label pairs=" + numberOfValueLabels);

            ByteBuffer[] tempBB = new ByteBuffer[numberOfValueLabels];

            String valueLabel[] = new String[numberOfValueLabels];

            for (int i = 0; i < numberOfValueLabels; i++) {

                // read 8-byte as value          
                byte[] value = new byte[LENGTH_RT3_VALUE];
                int nbytes_3_value = stream.read(value);

                if (nbytes_3_value == 0) {
                    throw new IOException("RT 3: reading recordType3 value: no byte was read");
                }
                // note these 8 bytes are interpreted later
                // currently no information about which variable's (=> type unknown)
                ByteBuffer bb_value = ByteBuffer.wrap(value, 0, LENGTH_RT3_VALUE);
                if (isLittleEndian) {
                    bb_value.order(ByteOrder.LITTLE_ENDIAN);
                }
                tempBB[i] = bb_value;
                dbgLog.fine("bb_value=" + Hex.encodeHex(bb_value.array()));
                /*
                  double valueD = bb_value.getDouble();                
                  dbgLog.fine("value="+valueD);
                */
                // read 1st byte as unsigned integer = label_length

                // read label_length byte as label
                byte[] labelLengthByte = new byte[LENGTH_RT3_LABEL_LENGTH];

                int nbytes_3_label_length = stream.read(labelLengthByte);

                // add check-routine here

                dbgLog.fine("labelLengthByte" + Hex.encodeHex(labelLengthByte));
                dbgLog.fine("label length = " + labelLengthByte[0]);
                // the net-length of a value label is saved as
                // unsigned byte; however, the length is less than 127
                // byte should be ok
                int rawLabelLength = labelLengthByte[0] & 0xFF;
                dbgLog.fine("rawLabelLength=" + rawLabelLength);
                // -1 =>1-byte already read
                int labelLength = getSAVobsAdjustedBlockLength(rawLabelLength + 1) - 1;
                byte[] valueLabelBytes = new byte[labelLength];
                int nbytes_3_value_label = stream.read(valueLabelBytes);

                // ByteBuffer bb_label = ByteBuffer.wrap(valueLabel,0,labelLength);

                valueLabel[i] = StringUtils.stripEnd(
                        new String(Arrays.copyOfRange(valueLabelBytes, 0, rawLabelLength), defaultCharSet),
                        " ");
                dbgLog.fine(i + "-th valueLabel=" + valueLabel[i] + "<-");

            } // iter rt3

            dbgLog.fine("end of RT3 block");
            dbgLog.fine("start of RT4 block");

            // 4.0 check the first 4 bytes
            byte[] headerCode4 = new byte[LENGTH_RECORD_TYPE4_CODE];

            int nbytes_rt4 = stream.read(headerCode4, 0, LENGTH_RECORD_TYPE4_CODE);

            if (nbytes_rt4 == 0) {
                throw new IOException("RT4: reading recordType4 value: no byte was read");
            }

            //printHexDump(headerCode4, "RT4 header test");

            ByteBuffer bb_header_code_4 = ByteBuffer.wrap(headerCode4, 0, LENGTH_RECORD_TYPE4_CODE);
            if (isLittleEndian) {
                bb_header_code_4.order(ByteOrder.LITTLE_ENDIAN);
            }

            int intRT4test = bb_header_code_4.getInt();
            dbgLog.fine("header test value: RT4=" + intRT4test);

            if (intRT4test != 4) {
                throw new IOException("RT 4: reading recordType4 header: no byte was read");
            }

            // 4.1 read the how-many-variables bytes
            byte[] howManyVariablesfollow = new byte[LENGTH_RT4_HOW_MANY_VARIABLES];

            int nbytes_rt4_1 = stream.read(howManyVariablesfollow, 0, LENGTH_RT4_HOW_MANY_VARIABLES);

            ByteBuffer bb_howManyVariablesfollow = ByteBuffer.wrap(howManyVariablesfollow, 0,
                    LENGTH_RT4_HOW_MANY_VARIABLES);
            if (isLittleEndian) {
                bb_howManyVariablesfollow.order(ByteOrder.LITTLE_ENDIAN);
            }

            int howManyVariablesRT4 = bb_howManyVariablesfollow.getInt();
            dbgLog.fine("how many variables follow: RT4=" + howManyVariablesRT4);

            int length_indicies = LENGTH_RT4_VARIABLE_INDEX * howManyVariablesRT4;
            byte[] variableIdicesBytes = new byte[length_indicies];

            int nbytes_rt4_2 = stream.read(variableIdicesBytes, 0, length_indicies);

            // !!!!! Caution: variableIndex in RT4 starts from 1 NOT ** 0 **
            int[] variableIndex = new int[howManyVariablesRT4];
            int offset = 0;
            for (int i = 0; i < howManyVariablesRT4; i++) {

                ByteBuffer bb_variable_index = ByteBuffer.wrap(variableIdicesBytes, offset,
                        LENGTH_RT4_VARIABLE_INDEX);
                offset += LENGTH_RT4_VARIABLE_INDEX;

                if (isLittleEndian) {
                    bb_variable_index.order(ByteOrder.LITTLE_ENDIAN);
                }

                variableIndex[i] = bb_variable_index.getInt();
                dbgLog.fine(i + "-th variable index number=" + variableIndex[i]);
            }

            dbgLog.fine("variable index set=" + ArrayUtils.toString(variableIndex));
            dbgLog.fine("subtract 1 from variableIndex for getting a variable info");

            boolean isNumeric = OBSwiseTypelList.get(variableIndex[0] - 1) == 0 ? true : false;

            Map<String, String> valueLabelPair = new LinkedHashMap<String, String>();
            if (isNumeric) {
                // numeric variable
                dbgLog.fine("processing of a numeric value-label table");
                for (int j = 0; j < numberOfValueLabels; j++) {
                    valueLabelPair.put(doubleNumberFormatter.format(tempBB[j].getDouble()), valueLabel[j]);
                }
            } else {
                // String variable
                dbgLog.fine("processing of a string value-label table");
                for (int j = 0; j < numberOfValueLabels; j++) {
                    valueLabelPair.put(
                            StringUtils.stripEnd(new String((tempBB[j].array()), defaultCharSet), " "),
                            valueLabel[j]);
                }
            }

            dbgLog.fine("valueLabePair=" + valueLabelPair);
            dbgLog.fine("key variable's (raw) index =" + variableIndex[0]);

            valueLabelTable.put(OBSIndexToVariableName.get(variableIndex[0] - 1), valueLabelPair);

            dbgLog.fine("valueLabelTable=" + valueLabelTable);

            // create a mapping table that finds the key variable for this mapping table
            String keyVariableName = OBSIndexToVariableName.get(variableIndex[0] - 1);
            for (int vn : variableIndex) {
                valueVariableMappingTable.put(OBSIndexToVariableName.get(vn - 1), keyVariableName);
            }

            dbgLog.fine("valueVariableMappingTable:\n" + valueVariableMappingTable);
        } catch (IOException ex) {
            //ex.printStackTrace();
            throw ex;
        }

        safteyCounter++;
        if (safteyCounter >= 1000000) {
            break;
        }
    } //while

    smd.setValueLabelTable(valueLabelTable);

    dbgLog.fine("***** decodeRecordType3and4(): end *****");
}