Example usage for org.apache.poi.util StringUtil getFromUnicodeLE

List of usage examples for org.apache.poi.util StringUtil getFromUnicodeLE

Introduction

In this page you can find the example usage for org.apache.poi.util StringUtil getFromUnicodeLE.

Prototype

public static String getFromUnicodeLE(final byte[] string, final int offset, final int len)
        throws ArrayIndexOutOfBoundsException, IllegalArgumentException 

Source Link

Document

Given a byte array of 16-bit unicode characters in Little Endian format (most important byte last), return a Java String representation of it.

Usage

From source file:org.ddt.listener.dsi.StringProperty.java

License:Apache License

/**
 * reads the data from the byte array.//from w w w .j  a  v a2 s. c om
 *
 * @param data   byte array to read from
 * @param offset offset into the data array
 * @throws IllegalVariantTypeException
 */
private void read(final byte data[], final int offset)
        throws IllegalVariantTypeException, UnsupportedEncodingException {
    int o = offset;
    charCount = LittleEndian.getUInt(data, o);
    length = charCount;
    o += LittleEndian.INT_SIZE;
    if (type == Variant.VT_LPWSTR) {
        //the smallest number of bytes to pad it to a multiple of 4... there must be a nicer way
        paddingBytes = (int) (4 - (length % 4)) % 4;
    } else if (type == Variant.VT_LPSTR) {
        paddingBytes = 0;
    } else {
        throw new IllegalVariantTypeException(type, value,
                "At offset " + o + ": Not a string, type = " + Long.toHexString(type) + " should be "
                        + Integer.toHexString(Variant.VT_LPSTR) + " or "
                        + Integer.toHexString(Variant.VT_LPWSTR));
    }

    length = Math.min(length, data.length - o);
    if (type == Variant.VT_LPWSTR) {
        //            value = new String(LittleEndian.getByteArray(data, o,
        //                    (int) (length - 2)), "UTF-16LE");
        value = StringUtil.getFromUnicodeLE(data, o, (int) (length - 1));
    } else {
        //            value = new String(LittleEndian.getByteArray(data, o, (int) (length - 1)));
        value = StringUtil.getFromCompressedUnicode(data, o, (int) (length - 1));
    }
}