From 9d23910658d1ba99f9959661bc6706b525830e67 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Thu, 30 Oct 2008 22:13:56 +0000 Subject: [PATCH] Introduced Record.getDataSize() method git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@709264 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/record/BoundSheetRecord.java | 2 +- src/java/org/apache/poi/hssf/record/CFHeaderRecord.java | 2 +- src/java/org/apache/poi/hssf/record/CRNRecord.java | 2 +- .../org/apache/poi/hssf/record/ExternSheetRecord.java | 3 +-- .../org/apache/poi/hssf/record/ExternalNameRecord.java | 2 +- src/java/org/apache/poi/hssf/record/FormulaRecord.java | 2 +- src/java/org/apache/poi/hssf/record/ObjRecord.java | 2 +- src/java/org/apache/poi/hssf/record/PageBreakRecord.java | 2 +- src/java/org/apache/poi/hssf/record/Record.java | 9 +++++++++ src/java/org/apache/poi/hssf/record/SelectionRecord.java | 2 +- src/java/org/apache/poi/hssf/record/StyleRecord.java | 2 +- src/java/org/apache/poi/hssf/record/SupBookRecord.java | 2 +- .../org/apache/poi/hssf/record/TextObjectRecord.java | 2 +- 13 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java index 036de6b2df..ca369bd8b9 100644 --- a/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java +++ b/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java @@ -156,7 +156,7 @@ public final class BoundSheetRecord extends Record { return buffer.toString(); } - private int getDataSize() { + protected int getDataSize() { return 8 + field_5_sheetname.length() * (isMultibyte() ? 2 : 1); } diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java index 47fba0b955..8988e06526 100644 --- a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java +++ b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java @@ -130,7 +130,7 @@ public final class CFHeaderRecord extends Record { return buffer.toString(); } - private int getDataSize() { + protected int getDataSize() { return 4 // 2 short fields + CellRangeAddress.ENCODED_SIZE + field_4_cell_ranges.getSize(); diff --git a/src/java/org/apache/poi/hssf/record/CRNRecord.java b/src/java/org/apache/poi/hssf/record/CRNRecord.java index 050076cca2..fffefe2b45 100755 --- a/src/java/org/apache/poi/hssf/record/CRNRecord.java +++ b/src/java/org/apache/poi/hssf/record/CRNRecord.java @@ -63,7 +63,7 @@ public final class CRNRecord extends Record { sb.append("]"); return sb.toString(); } - private int getDataSize() { + protected int getDataSize() { return 4 + ConstantValueParser.getEncodedSize(field_4_constant_values); } diff --git a/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java b/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java index f6266cfa35..baa136c231 100644 --- a/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExternSheetRecord.java @@ -153,8 +153,7 @@ public class ExternSheetRecord extends Record { return sb.toString(); } - - private int getDataSize() { + protected int getDataSize() { return 2 + _list.size() * RefSubRecord.ENCODED_SIZE; } diff --git a/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java b/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java index a3dfe575c1..eb597aeb29 100755 --- a/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java @@ -83,7 +83,7 @@ public final class ExternalNameRecord extends Record { return field_4_name; } - private int getDataSize(){ + protected int getDataSize(){ int result = 3 * 2 // 3 short fields + 2 + field_4_name.length(); // nameLen and name if(hasFormula()) { diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index e51ed77a96..8c47811966 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -353,7 +353,7 @@ public final class FormulaRecord extends Record implements CellValueRecordInterf return sid; } - private int getDataSize() { + protected int getDataSize() { return FIXED_SIZE + field_8_parsed_expr.getEncodedSize(); } public int serialize(int offset, byte [] data) { diff --git a/src/java/org/apache/poi/hssf/record/ObjRecord.java b/src/java/org/apache/poi/hssf/record/ObjRecord.java index 538b1ae9f1..b96914e898 100644 --- a/src/java/org/apache/poi/hssf/record/ObjRecord.java +++ b/src/java/org/apache/poi/hssf/record/ObjRecord.java @@ -119,7 +119,7 @@ public final class ObjRecord extends Record { return sb.toString(); } - private int getDataSize() { + protected int getDataSize() { if (_uninterpretedData != null) { return _uninterpretedData.length; } diff --git a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java index 654439f316..c1b1767437 100644 --- a/src/java/org/apache/poi/hssf/record/PageBreakRecord.java +++ b/src/java/org/apache/poi/hssf/record/PageBreakRecord.java @@ -97,7 +97,7 @@ public abstract class PageBreakRecord extends Record { } - private int getDataSize() { + protected int getDataSize() { return 2 + _breaks.size() * Break.ENCODED_SIZE; } public int getRecordSize() { diff --git a/src/java/org/apache/poi/hssf/record/Record.java b/src/java/org/apache/poi/hssf/record/Record.java index 310cb28b2a..56f6deb6a2 100644 --- a/src/java/org/apache/poi/hssf/record/Record.java +++ b/src/java/org/apache/poi/hssf/record/Record.java @@ -54,6 +54,15 @@ public abstract class Record extends RecordBase { return retval; } + /** + * @return the size of the data portion of this record + * (does not include initial 4 bytes for sid and size) + */ + protected int getDataSize() { + // implementation is currently a hack + // will eventually swap this out + return getRecordSize() - 4; + } /** * get a string representation of the record (for biffview/debugging) */ diff --git a/src/java/org/apache/poi/hssf/record/SelectionRecord.java b/src/java/org/apache/poi/hssf/record/SelectionRecord.java index ca2bf22fc1..5dad6e1862 100644 --- a/src/java/org/apache/poi/hssf/record/SelectionRecord.java +++ b/src/java/org/apache/poi/hssf/record/SelectionRecord.java @@ -143,7 +143,7 @@ public final class SelectionRecord extends Record { buffer.append("[/SELECTION]\n"); return buffer.toString(); } - private int getDataSize() { + protected int getDataSize() { return 9 // 1 byte + 4 shorts + CellRangeAddress8Bit.getEncodedSize(field_6_refs.length); } diff --git a/src/java/org/apache/poi/hssf/record/StyleRecord.java b/src/java/org/apache/poi/hssf/record/StyleRecord.java index ad740e9b2e..f1ae0ab0fb 100644 --- a/src/java/org/apache/poi/hssf/record/StyleRecord.java +++ b/src/java/org/apache/poi/hssf/record/StyleRecord.java @@ -158,7 +158,7 @@ public final class StyleRecord extends Record { } - private int getDataSize() { + protected int getDataSize() { if (isBuiltin()) { return 4; // short, byte, byte } diff --git a/src/java/org/apache/poi/hssf/record/SupBookRecord.java b/src/java/org/apache/poi/hssf/record/SupBookRecord.java index 78d77c5cbf..067d9d07a7 100644 --- a/src/java/org/apache/poi/hssf/record/SupBookRecord.java +++ b/src/java/org/apache/poi/hssf/record/SupBookRecord.java @@ -138,7 +138,7 @@ public final class SupBookRecord extends Record { sb.append("]"); return sb.toString(); } - private int getDataSize() { + protected int getDataSize() { if(!isExternalReferences()) { return SMALL_RECORD_SIZE; } diff --git a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java index 4bb065e91e..3b4ac6bb7e 100644 --- a/src/java/org/apache/poi/hssf/record/TextObjectRecord.java +++ b/src/java/org/apache/poi/hssf/record/TextObjectRecord.java @@ -167,7 +167,7 @@ public final class TextObjectRecord extends Record { * Only for the current record. does not include any subsequent Continue * records */ - private int getDataSize() { + protected int getDataSize() { int result = 2 + 2 + 2 + 2 + 2 + 2 + 2 + 4; if (_linkRefPtg != null) { result += 2 // formula size -- 2.39.5