1 2 17 18 19 20 package org.apache.poi.hwpf.model; 21 22 import java.io.IOException ; 23 24 import org.apache.poi.util.LittleEndian; 25 import org.apache.poi.hwpf.model.io.*; 26 27 public class ComplexFileTable 28 { 29 30 private static final byte GRPPRL_TYPE = 1; 31 private static final byte TEXT_PIECE_TABLE_TYPE = 2; 32 33 protected TextPieceTable _tpt; 34 35 public ComplexFileTable() 36 { 37 _tpt = new TextPieceTable(); 38 } 39 40 public ComplexFileTable(byte[] documentStream, byte[] tableStream, int offset, int fcMin) throws IOException 41 { 42 while (tableStream[offset] == GRPPRL_TYPE) 45 { 46 offset++; 47 int skip = LittleEndian.getShort(tableStream, offset); 48 offset += LittleEndian.SHORT_SIZE + skip; 49 } 50 if(tableStream[offset] != TEXT_PIECE_TABLE_TYPE) 51 { 52 throw new IOException ("The text piece table is corrupted"); 53 } 54 else 55 { 56 int pieceTableSize = LittleEndian.getInt(tableStream, ++offset); 57 offset += LittleEndian.INT_SIZE; 58 _tpt = new TextPieceTable(documentStream, tableStream, offset, pieceTableSize, fcMin); 59 } 60 } 61 62 public TextPieceTable getTextPieceTable() 63 { 64 return _tpt; 65 } 66 67 public void writeTo(HWPFFileSystem sys) 68 throws IOException 69 { 70 HWPFOutputStream docStream = sys.getStream("WordDocument"); 71 HWPFOutputStream tableStream = sys.getStream("1Table"); 72 73 tableStream.write(TEXT_PIECE_TABLE_TYPE); 74 75 byte[] table = _tpt.writeTo(docStream); 76 77 byte[] numHolder = new byte[LittleEndian.INT_SIZE]; 78 LittleEndian.putInt(numHolder, table.length); 79 tableStream.write(numHolder); 80 tableStream.write(table); 81 } 82 83 } 84 | Popular Tags |