List of usage examples for org.apache.poi.hpsf IllegalVariantTypeException IllegalVariantTypeException
public IllegalVariantTypeException(final long variantType, final Object value)
Constructor
From source file:org.ddt.listener.dsi.HeadingPairProperty.java
License:Apache License
/** * the constructor.// w w w . j a va 2 s . c om * * * @param data the data to read from. * @param dataOffset the offset into the * <code>data</code> byte array. * @param docPartsOffset the offset of the corresponding docparts. * @throws IllegalVariantTypeException if the data is malformed. * @throws UnsupportedEncodingException */ HeadingPairProperty(byte[] data, int dataOffset, int docPartsOffset) throws IllegalVariantTypeException, UnsupportedEncodingException { int off = dataOffset; name = new StringProperty(data, off); off += name.getSize(); long type = LittleEndian.getUInt(data, off); if (type != Variant.VT_I4) { log.log(Level.WARNING, "Not a proper VT_I4 type."); throw new IllegalVariantTypeException(type, name); } off += LittleEndian.INT_SIZE; //this is a horrible workaround, around the bug in HPSF, that returns //cutoff byte arrays from Section.getProperty() (HPFS Bug #52337) //It hopes that there aren't too many parts per heading (i.e. worst //case it can be store in one byte...) int left = data.length - off; if (left >= LittleEndian.INT_SIZE) { partsCount = (int) LittleEndian.getUInt(data, off); off += LittleEndian.INT_SIZE; } else if (left >= LittleEndian.SHORT_SIZE) { partsCount = LittleEndian.getShort(data, off); off += left; } else if (left >= LittleEndian.BYTE_SIZE) { partsCount = LittleEndian.getUByte(data, off); off += left; } else { partsCount = 1; //default... maybe not a good idea. } size = off - dataOffset; this.docPartsOffset = docPartsOffset; }
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 v a2 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; } }