From 882abc5e3e9c4e7f32b4565f4809c0d9b660fd9d Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 1 Oct 2011 16:56:05 +0000 Subject: [PATCH] move cbRgFcLcb from FIBFieldHandler to FIB git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1178045 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hwpf/model/FIBFieldHandler.java | 20 ++++++------ .../poi/hwpf/model/FileInformationBlock.java | 31 ++++++++++++------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java index a3b4f398a0..1ef29fdd65 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FIBFieldHandler.java @@ -149,14 +149,12 @@ public final class FIBFieldHandler private int[] _fields; - public FIBFieldHandler(byte[] mainStream, int startOffset, byte[] tableStream, + FIBFieldHandler(byte[] mainStream, int offset, int cbRgFcLcb, byte[] tableStream, HashSet offsetList, boolean areKnown) { - int numFields = LittleEndian.getShort(mainStream, startOffset); - int offset = startOffset + LittleEndian.SHORT_SIZE; - _fields = new int[numFields * 2]; + _fields = new int[cbRgFcLcb * 2]; - for (int x = 0; x < numFields; x++) + for (int x = 0; x < cbRgFcLcb; x++) { int fieldOffset = (x * FIELD_SIZE) + offset; int dsOffset = LittleEndian.getInt(mainStream, fieldOffset); @@ -213,17 +211,17 @@ public final class FIBFieldHandler public int sizeInBytes() { - return (_fields.length * LittleEndian.INT_SIZE) + LittleEndian.SHORT_SIZE; + return (_fields.length * LittleEndian.INT_SIZE); } + public int getFieldsCount() { + return _fields.length / 2; + } + void writeTo(byte[] mainStream, int offset, HWPFOutputStream tableStream) throws IOException { - int length = _fields.length/2; - LittleEndian.putShort(mainStream, offset, (short)length); - offset += LittleEndian.SHORT_SIZE; - - for (int x = 0; x < length; x++) + for (int x = 0; x < _fields.length/2; x++) { UnhandledDataStructure ds = _unknownMap.get(Integer.valueOf(x)); if (ds != null) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index b7902cfc40..123f3ab1d7 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -51,8 +51,8 @@ public final class FileInformationBlock implements Cloneable private FibRgW97 _fibRgW; private int _cslw; private FibRgLw97 _fibRgLw; - - FIBFieldHandler _fieldHandler; + private int _cbRgFcLcb; + private FIBFieldHandler _fieldHandler; /** Creates a new instance of FileInformationBlock */ public FileInformationBlock( byte[] mainDocument ) @@ -64,7 +64,7 @@ public final class FileInformationBlock implements Cloneable assert offset == 32; _csw = LittleEndian.getUShort( mainDocument, offset ); - offset += 2; + offset += LittleEndian.SHORT_SIZE; assert offset == 34; _fibRgW = new FibRgW97( mainDocument, offset ); @@ -72,12 +72,16 @@ public final class FileInformationBlock implements Cloneable assert offset == 62; _cslw = LittleEndian.getUShort( mainDocument, offset ); - offset += 2; + offset += LittleEndian.SHORT_SIZE; assert offset == 64; _fibRgLw = new FibRgLw97( mainDocument, offset ); offset += FibRgLw97.getSize(); assert offset == 152; + + _cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); + offset += LittleEndian.SHORT_SIZE; + assert offset == 154; } public void fillVariableFields( byte[] mainDocument, byte[] tableStream ) @@ -120,8 +124,8 @@ public final class FileInformationBlock implements Cloneable knownFieldSet.add( Integer.valueOf( FIBFieldHandler.STTBSAVEDBY ) ); knownFieldSet.add( Integer.valueOf( FIBFieldHandler.MODIFIED ) ); - _fieldHandler = new FIBFieldHandler( mainDocument, 152, tableStream, - knownFieldSet, true ); + _fieldHandler = new FIBFieldHandler( mainDocument, 154, _cbRgFcLcb, + tableStream, knownFieldSet, true ); } @Override @@ -866,31 +870,34 @@ public final class FileInformationBlock implements Cloneable public void writeTo( byte[] mainStream, HWPFOutputStream tableStream ) throws IOException { - // HWPFOutputStream mainDocument = sys.getStream("WordDocument"); - // HWPFOutputStream tableStream = sys.getStream("1Table"); + _cbRgFcLcb = _fieldHandler.getFieldsCount(); _fibBase.serialize( mainStream, 0 ); int offset = FibBase.getSize(); LittleEndian.putUShort( mainStream, offset, _csw ); - offset += 2; + offset += LittleEndian.SHORT_SIZE; _fibRgW.serialize( mainStream, offset ); offset += FibRgW97.getSize(); LittleEndian.putUShort( mainStream, offset, _cslw ); - offset += 2; + offset += LittleEndian.SHORT_SIZE; _fibRgLw.serialize( mainStream, offset ); offset += FibRgLw97.getSize(); + LittleEndian.putUShort( mainStream, offset, _cbRgFcLcb ); + offset += LittleEndian.SHORT_SIZE; + _fieldHandler.writeTo( mainStream, offset, tableStream ); } public int getSize() { - return FibBase.getSize() + 2 + FibRgW97.getSize() + 2 - + FibRgLw97.getSize() + _fieldHandler.sizeInBytes(); + return FibBase.getSize() + LittleEndian.SHORT_SIZE + FibRgW97.getSize() + + LittleEndian.SHORT_SIZE + FibRgLw97.getSize() + + LittleEndian.SHORT_SIZE + _fieldHandler.sizeInBytes(); } public FibBase getFibBase()