List of usage examples for org.apache.poi.hpsf IllegalVariantTypeException IllegalVariantTypeException
public IllegalVariantTypeException(final long variantType, final Object value, final String msg)
Constructor
From source file:org.ddt.listener.dsi.StringProperty.java
License:Apache License
/** * reads the data from the byte array.//from w ww.j a v a 2s . 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)); } }