1 2 17 18 package org.apache.poi.hwpf; 19 20 import java.io.FileInputStream ; 21 22 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 23 import org.apache.poi.poifs.filesystem.DocumentEntry; 24 25 import org.apache.poi.hwpf.model.*; 26 import java.io.File ; 27 28 29 public class HWPFDocFixture 30 { 31 public byte[] _tableStream; 32 public byte[] _mainStream; 33 public FileInformationBlock _fib; 34 35 public HWPFDocFixture(Object obj) 36 { 37 38 } 39 40 public void setUp() 41 { 42 try 43 { 44 String filename = System.getProperty("HWPF.testdata.path"); 45 if (filename == null) 46 { 47 filename = "c:"; 48 } 49 50 filename = filename + "/blankplus.doc"; 51 52 53 POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream ( 54 new File (filename))); 55 56 DocumentEntry documentProps = 57 (DocumentEntry) filesystem.getRoot().getEntry("WordDocument"); 58 _mainStream = new byte[documentProps.getSize()]; 59 filesystem.createDocumentInputStream("WordDocument").read(_mainStream); 60 61 _fib = new FileInformationBlock(_mainStream); 63 64 String name = "0Table"; 65 if (_fib.isFWhichTblStm()) 66 { 67 name = "1Table"; 68 } 69 70 DocumentEntry tableProps = 72 (DocumentEntry) filesystem.getRoot().getEntry(name); 73 _tableStream = new byte[tableProps.getSize()]; 74 filesystem.createDocumentInputStream(name).read(_tableStream); 75 76 _fib.fillVariableFields(_mainStream, _tableStream); 77 } 78 catch (Throwable t) 79 { 80 t.printStackTrace(); 81 } 82 } 83 84 public void tearDown() 85 { 86 } 87 88 } 89 | Popular Tags |