poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r713894 - /poi/trunk/src/java/org/apache/poi/hssf/record/
Date Fri, 14 Nov 2008 01:25:16 GMT
Author: josh
Date: Thu Nov 13 17:25:16 2008
New Revision: 713894

URL: http://svn.apache.org/viewvc?rev=713894&view=rev
Log:
refactoring Record.serialize

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java
    poi/trunk/src/java/org/apache/poi/hssf/record/SupBookRecord.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java Thu Nov 13 17:25:16 2008
@@ -26,13 +26,14 @@
 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 @@
 	 * @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 @@
 		
 		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() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/CRNRecord.java Thu Nov 13 17:25:16 2008
@@ -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 @@
  *
  * @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 @@
 		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;
 	}
 
 	/**

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DVRecord.java Thu Nov 13 17:25:16 2008
@@ -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 @@
  * @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 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 @@
 		_formula2.serializeTokens(out);
 		
 		_regions.serialize(out);
-		return recSize;
 	}
 
 	/**

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/DrawingSelectionRecord.java Thu Nov 13 17:25:16
2008
@@ -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 @@
  * 
  * @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 @@
 			+ _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 @@
 		for (int i = 0; i < _shapeIds.length; i++) {
 			out.writeInt(_shapeIds[i]);
 		}
-		return recSize;
 	}
 
 	public Object clone() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/ExternalNameRecord.java Thu Nov 13 17:25:16
2008
@@ -27,7 +27,7 @@
  * 
  * @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 @@
 		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 @@
 		if (hasFormula()) {
 			field_5_name_definition.serialize(out);
 		}
-		return recSize;
 	}
 
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/FormulaRecord.java Thu Nov 13 17:25:16 2008
@@ -35,7 +35,7 @@
  * @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 @@
 	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 @@
 
 		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() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/NameRecord.java Thu Nov 13 17:25:16 2008
@@ -30,8 +30,8 @@
 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 @@
  * @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 @@
 	}
 
 
-	/**
-	 * 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 @@
 		StringUtil.putCompressedUnicode( getDescriptionText(), out);
 		StringUtil.putCompressedUnicode( getHelpTopicText(), out);
 		StringUtil.putCompressedUnicode( getStatusBarText(), out);
-
-		return recSize;
 	}
 	private int getNameRawSize() {
 		if (isBuiltInName()) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SeriesTextRecord.java Thu Nov 13 17:25:16
2008
@@ -28,7 +28,7 @@
  * 
  * @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 @@
 		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 @@
 			out.writeByte(0x00);
 			StringUtil.putCompressedUnicode(field_4_text, out);
 		}
-		return recordSize;
 	}
 
 	protected int getDataSize() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SharedValueRecordBase.java Thu Nov 13 17:25:16
2008
@@ -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 @@
  * 
  * @author Josh Micich
  */
-public abstract class SharedValueRecordBase extends Record {
+public abstract class SharedValueRecordBase extends StandardRecord {
 
 	private CellRangeAddress8Bit _range;
 
@@ -75,17 +74,9 @@
 
 	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;
 	}
 
 	/**

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/SupBookRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/SupBookRecord.java?rev=713894&r1=713893&r2=713894&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/SupBookRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/SupBookRecord.java Thu Nov 13 17:25:16 2008
@@ -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 @@
  * @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 @@
         }
         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 @@
 
             out.writeShort(field2val);
         }
-        return recordSize;
     }
 
     public void setNumberOfSheets(short number){
@@ -223,6 +207,6 @@
         */
     }
     public String[] getSheetNames() {
-        return (String[]) field_3_sheet_names.clone();
+        return field_3_sheet_names.clone();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message