List of usage examples for org.apache.poi.hpsf Variant VT_LPWSTR
int VT_LPWSTR
To view the source code for org.apache.poi.hpsf Variant VT_LPWSTR.
Click Source Link
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)); } }
From source file:org.ddt.listener.dsi.StringProperty.java
License:Apache License
/** * @todo make this function return different things, depending on whether it's * representing a Lpwstr/UnalignedLpstr or a VtUnalignedString structure. * (VtUnaligneString contains a TYPE field, the others don't.) * <p/>// www . ja va 2 s .co m * @return the size in bytes of the structure. */ int getSize() { int sz = (LittleEndian.INT_SIZE //type field + LittleEndian.INT_SIZE //char count field + paddingBytes); //padding sz += (int) ((type == Variant.VT_LPWSTR) ? length * 2 : length); //string length return sz; }
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 www. j a va2 s . co m * <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 testGetUnicode() { StringProperty property = unicodeTypeRead.get(0); assertEquals("[0] unicode, type = read ", property.getType(), Variant.VT_LPWSTR); assertEquals("[0] unicode, type = read, value", "hello world", property.getValue()); property = unicodeTypeGiven.get(0);/*from w w w. j av a2 s . c o m*/ assertEquals("[0] unicode, type = given ", property.getType(), Variant.VT_LPWSTR); assertEquals("[0] unicode, type = given, value ", "hello world", property.getValue()); property = unicodeTypeGiven.get(1); assertEquals("[1] unicode, type = given ", property.getType(), Variant.VT_LPWSTR); assertEquals("[1] unicode, type = given, value ", "soup", property.getValue()); property = unicodeTypeRead.get(1); assertEquals("[1] unicode, type = read, value", property.getType(), Variant.VT_LPWSTR); assertEquals("[1] unicode, type = read, value", "soup", property.getValue()); }
From source file:poi.hpsf.examples.WriteTitle.java
License:Apache License
/** * <p>Runs the example program.</p> * * @param args Command-line arguments. The first and only command-line * argument is the name of the POI file system to create. * @throws java.io.IOException if any I/O exception occurs. * @throws WritingNotSupportedException if HPSF does not (yet) support * writing a certain property type.//from ww w . ja va 2 s.co m */ public static void main(final String[] args) throws WritingNotSupportedException, IOException { /* Check whether we have exactly one command-line argument. */ if (args.length != 1) { System.err.println("Usage: " + WriteTitle.class.getName() + "destinationPOIFS"); System.exit(1); } final String fileName = args[0]; /* Create a mutable property set. Initially it contains a single section * with no properties. */ final MutablePropertySet mps = new MutablePropertySet(); /* Retrieve the section the property set already contains. */ final MutableSection ms = (MutableSection) mps.getSections().get(0); /* Turn the property set into a summary information property. This is * done by setting the format ID of its first section to * SectionIDMap.SUMMARY_INFORMATION_ID. */ ms.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); /* Create an empty property. */ final MutableProperty p = new MutableProperty(); /* Fill the property with appropriate settings so that it specifies the * document's title. */ p.setID(PropertyIDMap.PID_TITLE); p.setType(Variant.VT_LPWSTR); p.setValue("Sample title"); /* Place the property into the section. */ ms.setProperty(p); /* Create the POI file system the property set is to be written to. */ final POIFSFileSystem poiFs = new POIFSFileSystem(); /* For writing the property set into a POI file system it has to be * handed over to the POIFS.createDocument() method as an input stream * which produces the bytes making out the property set stream. */ final InputStream is = mps.toInputStream(); /* Create the summary information property set in the POI file * system. It is given the default name most (if not all) summary * information property sets have. */ poiFs.createDocument(is, SummaryInformation.DEFAULT_STREAM_NAME); /* Write the whole POI file system to a disk file. */ poiFs.writeFilesystem(new FileOutputStream(fileName)); }