refactoring Record.serialize
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@713894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a4b5d9ff2e
commit
ed5c2dac01
@ -26,13 +26,14 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.util.BitField;
|
||||
import org.apache.poi.util.BitFieldFactory;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
||||
/**
|
||||
* Conditional Formatting Rule Record.
|
||||
* Conditional Formatting Rule Record (0x01B1).<br/>
|
||||
*
|
||||
* @author Dmitriy Kumshayev
|
||||
*/
|
||||
public final class CFRuleRecord extends Record {
|
||||
public final class CFRuleRecord extends StandardRecord {
|
||||
|
||||
public static final short sid = 0x01B1;
|
||||
|
||||
@ -441,17 +442,11 @@ public final class CFRuleRecord extends Record {
|
||||
* @param data byte array containing instance data
|
||||
* @return number of bytes written
|
||||
*/
|
||||
public int serialize(int pOffset, byte [] data) {
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
|
||||
int formula1Len=getFormulaSize(field_17_formula1);
|
||||
int formula2Len=getFormulaSize(field_18_formula2);
|
||||
|
||||
int recordsize = getRecordSize();
|
||||
|
||||
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, pOffset, recordsize);
|
||||
|
||||
out.writeShort(sid);
|
||||
out.writeShort(recordsize-4);
|
||||
out.writeByte(field_1_condition_type);
|
||||
out.writeByte(field_2_comparison_operator);
|
||||
out.writeShort(formula1Len);
|
||||
@ -474,12 +469,6 @@ public final class CFRuleRecord extends Record {
|
||||
|
||||
field_17_formula1.serializeTokens(out);
|
||||
field_18_formula2.serializeTokens(out);
|
||||
|
||||
if(out.getWriteIndex() - pOffset != recordsize) {
|
||||
throw new IllegalStateException("write mismatch ("
|
||||
+ (out.getWriteIndex() - pOffset) + "!=" + recordsize + ")");
|
||||
}
|
||||
return recordsize;
|
||||
}
|
||||
|
||||
protected int getDataSize() {
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.hssf.record.constant.ConstantValueParser;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
||||
/**
|
||||
@ -28,7 +27,7 @@ import org.apache.poi.util.LittleEndianOutput;
|
||||
*
|
||||
* @author josh micich
|
||||
*/
|
||||
public final class CRNRecord extends Record {
|
||||
public final class CRNRecord extends StandardRecord {
|
||||
public final static short sid = 0x005A;
|
||||
|
||||
private int field_1_last_column_index;
|
||||
@ -67,17 +66,11 @@ public final class CRNRecord extends Record {
|
||||
return 4 + ConstantValueParser.getEncodedSize(field_4_constant_values);
|
||||
}
|
||||
|
||||
public int serialize(int offset, byte [] data) {
|
||||
int dataSize = getDataSize();
|
||||
int recSize = 4 + dataSize;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
out.writeByte(field_1_last_column_index);
|
||||
out.writeByte(field_2_first_column_index);
|
||||
out.writeShort(field_3_row_index);
|
||||
ConstantValueParser.encode(out, field_4_constant_values);
|
||||
return recSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,13 +17,11 @@
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.usermodel.DVConstraint;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.util.BitField;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
|
||||
@ -36,7 +34,7 @@ import org.apache.poi.util.StringUtil;
|
||||
* @author Dragos Buleandra (dragos.buleandra@trade2b.ro)
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class DVRecord extends Record {
|
||||
public final class DVRecord extends StandardRecord {
|
||||
public final static short sid = 0x01BE;
|
||||
|
||||
/** the unicode string used for error/prompt title/text when not present */
|
||||
@ -253,12 +251,7 @@ public final class DVRecord extends Record {
|
||||
}
|
||||
}
|
||||
|
||||
public int serialize(int offset, byte [] data) {
|
||||
int recSize = getRecordSize();
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
|
||||
out.writeShort(sid);
|
||||
out.writeShort(recSize-4);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
|
||||
out.writeInt(_option_flags);
|
||||
|
||||
@ -275,7 +268,6 @@ public final class DVRecord extends Record {
|
||||
_formula2.serializeTokens(out);
|
||||
|
||||
_regions.serialize(out);
|
||||
return recSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
||||
@ -29,7 +28,7 @@ import org.apache.poi.util.LittleEndianOutput;
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class DrawingSelectionRecord extends Record {
|
||||
public final class DrawingSelectionRecord extends StandardRecord {
|
||||
public static final short sid = 0x00ED;
|
||||
|
||||
/**
|
||||
@ -101,12 +100,7 @@ public final class DrawingSelectionRecord extends Record {
|
||||
+ _shapeIds.length * 4;
|
||||
}
|
||||
|
||||
public int serialize(int offset, byte[] data) {
|
||||
int dataSize = getDataSize();
|
||||
int recSize = 4 + dataSize;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
_header.serialize(out);
|
||||
out.writeInt(_cpsp);
|
||||
out.writeInt(_dgslk);
|
||||
@ -114,7 +108,6 @@ public final class DrawingSelectionRecord extends Record {
|
||||
for (int i = 0; i < _shapeIds.length; i++) {
|
||||
out.writeInt(_shapeIds[i]);
|
||||
}
|
||||
return recSize;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
|
@ -27,7 +27,7 @@ import org.apache.poi.util.StringUtil;
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public final class ExternalNameRecord extends Record {
|
||||
public final class ExternalNameRecord extends StandardRecord {
|
||||
|
||||
public final static short sid = 0x0023; // as per BIFF8. (some old versions used 0x223)
|
||||
|
||||
@ -92,22 +92,7 @@ public final class ExternalNameRecord extends Record {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* called by the class that is responsible for writing this sucker.
|
||||
* Subclasses should implement this so that their data is passed back in a
|
||||
* byte array.
|
||||
*
|
||||
* @param offset to begin writing at
|
||||
* @param data byte array containing instance data
|
||||
* @return number of bytes written
|
||||
*/
|
||||
public int serialize( int offset, byte[] data ) {
|
||||
int dataSize = getDataSize();
|
||||
int recSize = dataSize + 4;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
out.writeShort(field_1_option_flag);
|
||||
out.writeShort(field_2_index);
|
||||
out.writeShort(field_3_not_used);
|
||||
@ -117,7 +102,6 @@ public final class ExternalNameRecord extends Record {
|
||||
if (hasFormula()) {
|
||||
field_5_name_definition.serialize(out);
|
||||
}
|
||||
return recSize;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ import org.apache.poi.util.LittleEndianOutput;
|
||||
* @author Jason Height (jheight at chariot dot net dot au)
|
||||
* @version 2.0-pre
|
||||
*/
|
||||
public final class FormulaRecord extends Record implements CellValueRecordInterface {
|
||||
public final class FormulaRecord extends StandardRecord implements CellValueRecordInterface {
|
||||
|
||||
public static final short sid = 0x0006; // docs say 406...because of a bug Microsoft support site article #Q184647)
|
||||
private static int FIXED_SIZE = 20;
|
||||
@ -360,13 +360,8 @@ public final class FormulaRecord extends Record implements CellValueRecordInterf
|
||||
protected int getDataSize() {
|
||||
return FIXED_SIZE + field_8_parsed_expr.getEncodedSize();
|
||||
}
|
||||
public int serialize(int offset, byte [] data) {
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
|
||||
int dataSize = getDataSize();
|
||||
int recSize = 4 + dataSize;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
out.writeShort(getRow());
|
||||
out.writeShort(getColumn());
|
||||
out.writeShort(getXFIndex());
|
||||
@ -381,7 +376,6 @@ public final class FormulaRecord extends Record implements CellValueRecordInterf
|
||||
|
||||
out.writeInt(field_6_zero); // may as well write original data back so as to minimise differences from original
|
||||
field_8_parsed_expr.serialize(out);
|
||||
return recSize;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -30,8 +30,8 @@ import org.apache.poi.hssf.util.RangeAddress;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.ss.util.AreaReference;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ import org.apache.poi.util.StringUtil;
|
||||
* @author Glen Stampoultzis (glens at apache.org)
|
||||
* @version 1.0-pre
|
||||
*/
|
||||
public final class NameRecord extends Record {
|
||||
public final class NameRecord extends StandardRecord {
|
||||
public final static short sid = 0x0018;
|
||||
/**Included for completeness sake, not implemented */
|
||||
public final static byte BUILTIN_CONSOLIDATE_AREA = 1;
|
||||
@ -334,35 +334,13 @@ public final class NameRecord extends Record {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called by the class that is responsible for writing this sucker.
|
||||
* Subclasses should implement this so that their data is passed back in a
|
||||
* @param offset to begin writing at
|
||||
* @param data byte array containing instance data
|
||||
* @return number of bytes written
|
||||
*/
|
||||
public int serialize( int offset, byte[] data ) {
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
|
||||
int field_7_length_custom_menu = field_14_custom_menu_text.length();
|
||||
int field_8_length_description_text = field_15_description_text.length();
|
||||
int field_9_length_help_topic_text = field_16_help_topic_text.length();
|
||||
int field_10_length_status_bar_text = field_17_status_bar_text.length();
|
||||
int rawNameSize = getNameRawSize();
|
||||
|
||||
int formulaTotalSize = field_13_name_definition.getEncodedSize();
|
||||
int dataSize = 13 // 3 shorts + 7 bytes
|
||||
+ rawNameSize
|
||||
+ field_7_length_custom_menu
|
||||
+ field_8_length_description_text
|
||||
+ field_9_length_help_topic_text
|
||||
+ field_10_length_status_bar_text
|
||||
+ formulaTotalSize;
|
||||
|
||||
int recSize = 4 + dataSize;
|
||||
LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
|
||||
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
// size defined below
|
||||
out.writeShort(getOptionFlag());
|
||||
out.writeByte(getKeyboardShortcut());
|
||||
@ -395,8 +373,6 @@ public final class NameRecord extends Record {
|
||||
StringUtil.putCompressedUnicode( getDescriptionText(), out);
|
||||
StringUtil.putCompressedUnicode( getHelpTopicText(), out);
|
||||
StringUtil.putCompressedUnicode( getStatusBarText(), out);
|
||||
|
||||
return recSize;
|
||||
}
|
||||
private int getNameRawSize() {
|
||||
if (isBuiltInName()) {
|
||||
|
@ -28,7 +28,7 @@ import org.apache.poi.util.StringUtil;
|
||||
*
|
||||
* @author Andrew C. Oliver (acoliver at apache.org)
|
||||
*/
|
||||
public final class SeriesTextRecord extends Record {
|
||||
public final class SeriesTextRecord extends StandardRecord {
|
||||
public final static short sid = 0x100D;
|
||||
|
||||
/** the actual text cannot be longer than 255 characters */
|
||||
@ -65,12 +65,7 @@ public final class SeriesTextRecord extends Record {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public int serialize(int offset, byte[] data) {
|
||||
int dataSize = getDataSize();
|
||||
int recordSize = 4 + dataSize;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recordSize);
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
|
||||
out.writeShort(field_1_id);
|
||||
out.writeByte(field_4_text.length());
|
||||
@ -83,7 +78,6 @@ public final class SeriesTextRecord extends Record {
|
||||
out.writeByte(0x00);
|
||||
StringUtil.putCompressedUnicode(field_4_text, out);
|
||||
}
|
||||
return recordSize;
|
||||
}
|
||||
|
||||
protected int getDataSize() {
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
||||
@ -28,7 +27,7 @@ import org.apache.poi.util.LittleEndianOutput;
|
||||
*
|
||||
* @author Josh Micich
|
||||
*/
|
||||
public abstract class SharedValueRecordBase extends Record {
|
||||
public abstract class SharedValueRecordBase extends StandardRecord {
|
||||
|
||||
private CellRangeAddress8Bit _range;
|
||||
|
||||
@ -75,17 +74,9 @@ public abstract class SharedValueRecordBase extends Record {
|
||||
|
||||
protected abstract void serializeExtraData(LittleEndianOutput out);
|
||||
|
||||
public final int serialize(int offset, byte[] data) {
|
||||
int dataSize = CellRangeAddress8Bit.ENCODED_SIZE + getExtraDataSize();
|
||||
|
||||
int totalRecSize = dataSize + 4;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, totalRecSize);
|
||||
out.writeShort(getSid());
|
||||
out.writeShort(dataSize);
|
||||
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
_range.serialize(out);
|
||||
serializeExtraData(out);
|
||||
return totalRecSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
import org.apache.poi.util.StringUtil;
|
||||
|
||||
@ -30,7 +29,7 @@ import org.apache.poi.util.StringUtil;
|
||||
* @author Andrew C. Oliver (acoliver@apache.org)
|
||||
*
|
||||
*/
|
||||
public final class SupBookRecord extends Record {
|
||||
public final class SupBookRecord extends StandardRecord {
|
||||
|
||||
public final static short sid = 0x01AE;
|
||||
|
||||
@ -150,22 +149,8 @@ public final class SupBookRecord extends Record {
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
/**
|
||||
* called by the class that is responsible for writing this sucker.
|
||||
* Subclasses should implement this so that their data is passed back in a
|
||||
* byte array.
|
||||
*
|
||||
* @param offset to begin writing at
|
||||
* @param data byte array containing instance data
|
||||
* @return number of bytes written
|
||||
*/
|
||||
public int serialize(int offset, byte [] data) {
|
||||
int dataSize = getDataSize();
|
||||
int recordSize = 4 + dataSize;
|
||||
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recordSize);
|
||||
|
||||
out.writeShort(sid);
|
||||
out.writeShort(dataSize);
|
||||
public void serialize(LittleEndianOutput out) {
|
||||
out.writeShort(field_1_number_of_sheets);
|
||||
|
||||
if(isExternalReferences()) {
|
||||
@ -179,7 +164,6 @@ public final class SupBookRecord extends Record {
|
||||
|
||||
out.writeShort(field2val);
|
||||
}
|
||||
return recordSize;
|
||||
}
|
||||
|
||||
public void setNumberOfSheets(short number){
|
||||
@ -223,6 +207,6 @@ public final class SupBookRecord extends Record {
|
||||
*/
|
||||
}
|
||||
public String[] getSheetNames() {
|
||||
return (String[]) field_3_sheet_names.clone();
|
||||
return field_3_sheet_names.clone();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user