KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > ComplexFileTable


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19
20 package org.apache.poi.hwpf.model;
21
22 import java.io.IOException JavaDoc;
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 JavaDoc
41   {
42     //skips through the prms before we reach the piece table. These contain data
43
//for actual fast saved files
44
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 JavaDoc("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 JavaDoc
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