Example usage for org.apache.poi.hpsf Variant VT_LPSTR

List of usage examples for org.apache.poi.hpsf Variant VT_LPSTR

Introduction

In this page you can find the example usage for org.apache.poi.hpsf Variant VT_LPSTR.

Prototype

int VT_LPSTR

To view the source code for org.apache.poi.hpsf Variant VT_LPSTR.

Click Source Link

Document

[T][P] null terminated string.

Usage

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

License:Apache License

/**
 * reads the data from the byte array.//from ww  w. j av  a  2  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));
    }
}

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

License:Apache License

@Test
public void testGetType() throws IllegalVariantTypeException, UnsupportedEncodingException {
    assertEquals("single-byte string type", Variant.VT_LPSTR, ansiInstance.getType());
    assertEquals("double-byte string type", Variant.VT_LPWSTR, unicodeInstance.getType());

}

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

License:Apache License

/**
 * reads the data array and fills in the StringVector values.
 * \warning the//from w ww.j  a va 2 s.  c om
 * <code>type</code> field <b>must</b> be populated/initialised
 * before this method is called.
 *
 * @param data   byte array containing a vector of strings.
 * @param offset the offset into the array at which the vector starts.
 * @throws IllegalVariantTypeException
 * @throws UnsupportedOperationException
 */
private void read(byte[] data, int offset) throws IllegalVariantTypeException, UnsupportedEncodingException {
    if ((type != (Variant.VT_VECTOR | Variant.VT_LPSTR)) && (type != (Variant.VT_VECTOR | Variant.VT_LPWSTR))) {
        throw new IllegalVariantTypeException(type, data);
    }

    numElements = (int) LittleEndian.getUInt(data, offset);
    offset += LittleEndian.INT_SIZE;
    elements = new StringProperty[numElements];
    for (int i = 0; i < numElements; i++) {
        elements[i] = new StringProperty(data, offset, type & 0x00ff);
        //because the strings are constructed with an already-read type field,
        //we only need to advance over the StringLength field and the string,
        //not the type field (there isn't one in this case).
        offset += elements[i].getSize() - LittleEndian.INT_SIZE;
    }
}

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

License:Apache License

@Before
public void setUp() throws IllegalVariantTypeException, UnsupportedEncodingException {
    ansiTypeGiven = new StringVector(ansiVector, 4, Variant.VT_VECTOR | Variant.VT_LPSTR);
    unicodeTypeGiven = new StringVector(unicodeVector, 4, Variant.VT_VECTOR | Variant.VT_LPWSTR);
    ansiTypeRead = new StringVector(ansiVector, 0);
    unicodeTypeRead = new StringVector(unicodeVector, 0);
}

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

License:Apache License

@Test
public void testVectorValueConstructors() throws IllegalVariantTypeException, UnsupportedEncodingException {
    ansiTypeGiven = new StringVector(ansiVector, 4, Variant.VT_VECTOR | Variant.VT_LPSTR);
    unicodeTypeGiven = new StringVector(unicodeVector, 4, Variant.VT_VECTOR | Variant.VT_LPWSTR);
}

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

License:Apache License

@Test
public void testGetAnsi() {
    StringProperty property = ansiTypeRead.get(0);
    assertEquals("[0] ansi, type = read ", property.getType(), Variant.VT_LPSTR);
    assertEquals("[0] ansi, type = read, value ", property.getValue(), "hello world");

    property = ansiTypeGiven.get(0);/*from w  w w. j a  v  a  2s. co  m*/
    assertEquals("[0] ansi, type = given ", property.getType(), Variant.VT_LPSTR);
    assertEquals("[0] ansi, type = given, value ", property.getValue(), "hello world");

    property = ansiTypeRead.get(1);
    assertEquals("[1] ansi, type = read ", property.getType(), Variant.VT_LPSTR);
    assertEquals("[1] ansi, type = read, value ", property.getValue(), "hello world, bla");

    property = ansiTypeGiven.get(1);
    assertEquals("[1] ansi, type = given ", property.getType(), Variant.VT_LPSTR);
    assertEquals("[1] ansi, type = given, value ", property.getValue(), "hello world, bla");
}