1 2 17 18 package org.apache.poi.hpsf.examples; 19 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 import org.apache.poi.hpsf.MutableProperty; 25 import org.apache.poi.hpsf.MutablePropertySet; 26 import org.apache.poi.hpsf.MutableSection; 27 import org.apache.poi.hpsf.SummaryInformation; 28 import org.apache.poi.hpsf.Variant; 29 import org.apache.poi.hpsf.WritingNotSupportedException; 30 import org.apache.poi.hpsf.wellknown.PropertyIDMap; 31 import org.apache.poi.hpsf.wellknown.SectionIDMap; 32 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 33 34 43 public class WriteTitle 44 { 45 54 public static void main(final String [] args) 55 throws WritingNotSupportedException, IOException 56 { 57 58 if (args.length != 1) 59 { 60 System.err.println("Usage: " + WriteTitle.class.getName() + 61 "destinationPOIFS"); 62 System.exit(1); 63 } 64 65 final String fileName = args[0]; 66 67 69 final MutablePropertySet mps = new MutablePropertySet(); 70 71 72 final MutableSection ms = (MutableSection) mps.getSections().get(0); 73 74 77 ms.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); 78 79 80 final MutableProperty p = new MutableProperty(); 81 82 84 p.setID(PropertyIDMap.PID_TITLE); 85 p.setType(Variant.VT_LPWSTR); 86 p.setValue("Sample title"); 87 88 89 ms.setProperty(p); 90 91 92 final POIFSFileSystem poiFs = new POIFSFileSystem(); 93 94 97 final InputStream is = mps.toInputStream(); 98 99 102 poiFs.createDocument(is, SummaryInformation.DEFAULT_STREAM_NAME); 103 104 105 poiFs.writeFilesystem(new FileOutputStream (fileName)); 106 } 107 108 } 109 | Popular Tags |