poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r707486 - in /poi/trunk/src/java/org/apache/poi: hssf/record/ hssf/record/formula/ util/
Date Thu, 23 Oct 2008 22:28:07 GMT
Author: josh
Date: Thu Oct 23 15:28:05 2008
New Revision: 707486

URL: http://svn.apache.org/viewvc?rev=707486&view=rev
Log:
Converted Ptgs to use LittleEndianOutput

Added:
    poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataFormulaField.java
    poi/trunk/src/java/org/apache/poi/hssf/record/TextObjectRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataFormulaField.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataFormulaField.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataFormulaField.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/LinkedDataFormulaField.java Thu Oct 23 15:28:05 2008
@@ -51,7 +51,7 @@
                     .append( "=" )
                     .append(ptg.toString() )
                     .append( "\n" )
-                    .append(ptg.toDebugString() )
+                    .append(ptg.toString())
                     .append( "\n" );
         }
     }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/TextObjectRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/TextObjectRecord.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/TextObjectRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/TextObjectRecord.java Thu Oct 23 15:28:05 2008
@@ -25,6 +25,8 @@
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * The TXO record (0x01B6) is used to define the properties of a text box. It is
@@ -190,36 +192,31 @@
 
 	private int serializeTXORecord(int offset, byte[] data) {
 		int dataSize = getDataSize();
+		int recSize = dataSize+4;
+		LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
 		
-		LittleEndian.putUShort(data, 0 + offset, TextObjectRecord.sid);
-		LittleEndian.putUShort(data, 2 + offset, dataSize);
-
+		out.writeShort(TextObjectRecord.sid);
+		out.writeShort(dataSize);
 		
-		LittleEndian.putUShort(data, 4 + offset, field_1_options);
-		LittleEndian.putUShort(data, 6 + offset, field_2_textOrientation);
-		LittleEndian.putUShort(data, 8 + offset, field_3_reserved4);
-		LittleEndian.putUShort(data, 10 + offset, field_4_reserved5);
-		LittleEndian.putUShort(data, 12 + offset, field_5_reserved6);
-		LittleEndian.putUShort(data, 14 + offset, _text.length());
-		LittleEndian.putUShort(data, 16 + offset, getFormattingDataLength());
-		LittleEndian.putInt(data, 18 + offset, field_8_reserved7);
+		out.writeShort(field_1_options);
+		out.writeShort(field_2_textOrientation);
+		out.writeShort(field_3_reserved4);
+		out.writeShort(field_4_reserved5);
+		out.writeShort(field_5_reserved6);
+		out.writeShort(_text.length());
+		out.writeShort(getFormattingDataLength());
+		out.writeInt(field_8_reserved7);
 		
 		if (_linkRefPtg != null) {
-			int pos = offset+22;
 			int formulaSize = _linkRefPtg.getSize();
-			LittleEndian.putUShort(data, pos, formulaSize);
-			pos += LittleEndian.SHORT_SIZE;
-			LittleEndian.putInt(data, pos, _unknownPreFormulaInt);
-			pos += LittleEndian.INT_SIZE;
-			_linkRefPtg.writeBytes(data, pos);
-			pos += formulaSize;
+			out.writeShort(formulaSize);
+			out.writeInt(_unknownPreFormulaInt);
+			_linkRefPtg.write(out);
 			if (_unknownPostFormulaByte != null) {
-				LittleEndian.putByte(data, pos, _unknownPostFormulaByte.byteValue());
-				pos += LittleEndian.BYTE_SIZE;
+				out.writeByte(_unknownPostFormulaByte.byteValue());
 			}
 		}
-		
-		return 4 + dataSize;
+		return recSize;
 	}
 
 	private int serializeTrailingRecords(int offset, byte[] data) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java Thu Oct 23 15:28:05 2008
@@ -98,7 +98,6 @@
         buf.append(")");
     }
 
-    public abstract void writeBytes(byte[] array, int offset);
     public abstract int getSize();
 
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java Thu Oct 23 15:28:05 2008
@@ -18,41 +18,47 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Common superclass of 2-D area refs 
+ * Common superclass of 2-D area refs
  */
 public abstract class Area2DPtgBase extends AreaPtgBase {
-	private final static int  SIZE = 9;
+	private final static int SIZE = 9;
 
 	protected Area2DPtgBase(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
 		super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
 	}
+
 	protected Area2DPtgBase(RecordInputStream in) {
 		readCoordinates(in);
 	}
+
 	protected abstract byte getSid();
 
-	public final void writeBytes(byte [] array, int offset) {
-		LittleEndian.putByte(array, offset+0, getSid() + getPtgClass());
-		writeCoordinates(array, offset+1);       
+	public final void write(LittleEndianOutput out) {
+		out.writeByte(getSid() + getPtgClass());
+		writeCoordinates(out);
 	}
+
 	public Area2DPtgBase(String arearef) {
-    	super(arearef);
+		super(arearef);
 	}
+
 	public final int getSize() {
 		return SIZE;
 	}
+
 	public final String toFormulaString() {
-    	return formatReferenceAsString();
+		return formatReferenceAsString();
+	}
+
+	public final String toString() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(getClass().getName());
+		sb.append(" [");
+		sb.append(formatReferenceAsString());
+		sb.append("]");
+		return sb.toString();
 	}
-    public final String toString() {
-        StringBuffer sb = new StringBuffer();
-        sb.append(getClass().getName());
-        sb.append(" [");
-        sb.append(formatReferenceAsString());
-        sb.append("]");
-        return sb.toString();
-    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java Thu Oct 23 15:28:05 2008
@@ -21,7 +21,7 @@
 import org.apache.poi.ss.formula.ExternSheetReferenceToken;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
 import org.apache.poi.ss.formula.WorkbookDependentFormula;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * Title:        Area 3D Ptg - 3D reference (Sheet + Area)<P>
@@ -67,10 +67,10 @@
 		return sb.toString();
 	}
 
-	public void writeBytes(byte[] array, int offset) {
-		LittleEndian.putByte(array, offset + 0, sid + getPtgClass());
-		LittleEndian.putUShort(array, 1 + offset, field_1_index_extern_sheet);
-		writeCoordinates(array, offset+3);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(field_1_index_extern_sheet);
+		writeCoordinates(out);
 	}
 
 	public int getSize() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java Thu Oct 23 15:28:05 2008
@@ -19,7 +19,7 @@
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * AreaErr - handles deleted cell area references.
@@ -42,10 +42,10 @@
 		unused2 = in.readInt();
 	}
 
-	public void writeBytes(byte[] array, int offset) {
-		LittleEndian.putByte(array, offset + 0, sid + getPtgClass());
-		LittleEndian.putInt(array, offset + 1, unused1);
-		LittleEndian.putInt(array, offset + 5, unused2);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeInt(unused1);
+		out.writeInt(unused2);
 	}
 
 	public String toFormulaString() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java Thu Oct 23 15:28:05 2008
@@ -22,7 +22,7 @@
 import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * Specifies a rectangular area of cells A1:A4 for instance.
@@ -46,7 +46,7 @@
 	private int             field_3_first_column;
 	/** zero based, unsigned 8 bit */
 	private int             field_4_last_column;
-	
+
 	private final static BitField   rowRelative = BitFieldFactory.getInstance(0x8000);
 	private final static BitField   colRelative = BitFieldFactory.getInstance(0x4000);
 	private final static BitField   columnMask      = BitFieldFactory.getInstance(0x3FFF);
@@ -54,7 +54,7 @@
 	protected AreaPtgBase() {
 		// do nothing
 	}
-	
+
 	protected AreaPtgBase(String arearef) {
 		AreaReference ar = new AreaReference(arearef);
 		CellReference firstCell = ar.getFirstCell();
@@ -66,17 +66,17 @@
 		setFirstColRelative(!firstCell.isColAbsolute());
 		setLastColRelative(!lastCell.isColAbsolute());
 		setFirstRowRelative(!firstCell.isRowAbsolute());
-		setLastRowRelative(!lastCell.isRowAbsolute());        
+		setLastRowRelative(!lastCell.isRowAbsolute());
 	}
-	
+
 	protected AreaPtgBase(int firstRow, int lastRow, int firstColumn, int lastColumn,
 			boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
-		
+
 		checkColumnBounds(firstColumn);
 		checkColumnBounds(lastColumn);
 		checkRowBounds(firstRow);
 		checkRowBounds(lastRow);
-		
+
 		if (lastRow > firstRow) {
 			setFirstRow(firstRow);
 			setLastRow(lastRow);
@@ -88,7 +88,7 @@
 			setFirstRowRelative(lastRowRelative);
 			setLastRowRelative(firstRowRelative);
 		}
-			
+
 		if (lastColumn > firstColumn) {
 			setFirstColumn(firstColumn);
 			setLastColumn(lastColumn);
@@ -100,7 +100,7 @@
 			setFirstColRelative(lastColRelative);
 			setLastColRelative(firstColRelative);
 		}
-	}    
+	}
 
 	private static void checkColumnBounds(int colIx) {
 		if((colIx & 0x0FF) != colIx) {
@@ -119,11 +119,11 @@
 		field_3_first_column = in.readUShort();
 		field_4_last_column = in.readUShort();
 	}
-	protected final void writeCoordinates(byte[] array, int offset) {
-		LittleEndian.putUShort(array, offset + 0, field_1_first_row);
-		LittleEndian.putUShort(array, offset + 2, field_2_last_row);
-		LittleEndian.putUShort(array, offset + 4, field_3_first_column);
-		LittleEndian.putUShort(array, offset + 6, field_4_last_column);        
+	protected final void writeCoordinates(LittleEndianOutput out) {
+		out.writeShort(field_1_first_row);
+		out.writeShort(field_2_last_row);
+		out.writeShort(field_3_first_column);
+		out.writeShort(field_4_last_column);
 	}
 
 	/**
@@ -150,7 +150,7 @@
 	}
 
 	/**
-	 * @param rowIx last row number in the area 
+	 * @param rowIx last row number in the area
 	 */
 	public final void setLastRow(int rowIx) {
 		checkRowBounds(rowIx);
@@ -177,7 +177,7 @@
 	public final boolean isFirstRowRelative() {
 		return rowRelative.isSet(field_3_first_column);
 	}
-	
+
 	/**
 	 * sets the first row to relative or not
 	 * @param rel is relative or not.
@@ -192,9 +192,9 @@
 	public final boolean isFirstColRelative() {
 		return colRelative.isSet(field_3_first_column);
 	}
-	
+
 	/**
-	 * set whether the first column is relative 
+	 * set whether the first column is relative
 	 */
 	public final void setFirstColRelative(boolean rel) {
 		field_3_first_column=colRelative.setBoolean(field_3_first_column,rel);
@@ -235,7 +235,7 @@
 	public final boolean isLastRowRelative() {
 		return rowRelative.isSet(field_4_last_column);
 	}
-	
+
 	/**
 	 * set whether the last row is relative or not
 	 * @param rel <code>true</code> if the last row relative, else
@@ -251,14 +251,14 @@
 	public final boolean isLastColRelative() {
 		return colRelative.isSet(field_4_last_column);
 	}
-	
+
 	/**
 	 * set whether the last column should be relative or not
 	 */
 	public final void setLastColRelative(boolean rel) {
 		field_4_last_column=colRelative.setBoolean(field_4_last_column,rel);
 	}
-	
+
 	/**
 	 * set the last column in the area
 	 */
@@ -276,13 +276,13 @@
 	protected final String formatReferenceAsString() {
 		CellReference topLeft = new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative());
 		CellReference botRight = new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative());
-		
+
 		if(AreaReference.isWholeColumnReference(topLeft, botRight)) {
 			return (new AreaReference(topLeft, botRight)).formatAsString();
 		}
-		return topLeft.formatAsString() + ":" + botRight.formatAsString(); 
+		return topLeft.formatAsString() + ":" + botRight.formatAsString();
 	}
-	
+
 	public String toFormulaString() {
 		return formatReferenceAsString();
 	}

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java Thu Oct 23 15:28:05 2008
@@ -22,6 +22,7 @@
 import org.apache.poi.hssf.record.constant.ConstantValueParser;
 import org.apache.poi.hssf.record.constant.ErrorConstant;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * ArrayPtg - handles arrays
@@ -153,10 +154,9 @@
 		return rowIx * token_1_columns + colIx;
 	}
 
-	public void writeBytes(byte[] data, int offset) {
-		
-		LittleEndian.putByte(data, offset + 0, sid + getPtgClass());
-		System.arraycopy(field_1_reserved, 0, data, offset+1, RESERVED_FIELD_LEN);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.write(field_1_reserved);
 	}
 
 	public int writeTokenValueBytes(byte[] data, int offset) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java Thu Oct 23 15:28:05 2008
@@ -21,6 +21,7 @@
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * "Special Attributes"
@@ -213,19 +214,16 @@
         return sb.toString();
     }
 
-    public void writeBytes(byte [] array, int offset)
-    {
-        LittleEndian.putByte(array, offset+0, sid);
-        LittleEndian.putByte(array, offset+1, field_1_options);
-        LittleEndian.putShort(array,offset+2, field_2_data);
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeByte(field_1_options);
+        out.writeShort(field_2_data);
         int[] jt = _jumpTable;
         if (jt != null) {
-            int joff = offset+4;
             for (int i = 0; i < jt.length; i++) {
-                LittleEndian.putUShort(array, joff, jt[i]);
-                joff+=2;
+                out.writeShort(jt[i]);
             }
-            LittleEndian.putUShort(array, joff, _chooseFuncOffset);
+            out.writeShort(_chooseFuncOffset);
         }
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java Thu Oct 23 15:28:05 2008
@@ -18,41 +18,42 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Boolean (boolean)
- * Stores a (java) boolean value in a formula.
+ * Boolean (boolean) Stores a (java) boolean value in a formula.
+ * 
  * @author Paul Krause (pkrause at soundbite dot com)
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class BoolPtg extends ScalarConstantPtg {
-    public final static int  SIZE = 2;
-    public final static byte sid  = 0x1d;
-    private final boolean _value;
-
-    public BoolPtg(RecordInputStream in) {
-        _value = (in.readByte() == 1);
-    }
-
-    public BoolPtg(String formulaToken) {
-        _value = (formulaToken.equalsIgnoreCase("TRUE"));
-    }
-
-    public boolean getValue() {
-        return _value;
-    }
-
-    public void writeBytes(byte [] array, int offset) {
-        array[ offset + 0 ] = sid;
-        array[ offset + 1 ] = (byte) (_value ? 1 : 0);
-    }
-
-    public int getSize() {
-        return SIZE;
-    }
-
-    public String toFormulaString() {
-        return _value ? "TRUE" : "FALSE";
-    }
+	public final static int SIZE = 2;
+	public final static byte sid = 0x1D;
+	private final boolean _value;
+
+	public BoolPtg(RecordInputStream in) {
+		_value = (in.readByte() == 1);
+	}
+
+	public BoolPtg(String formulaToken) {
+		_value = (formulaToken.equalsIgnoreCase("TRUE"));
+	}
+
+	public boolean getValue() {
+		return _value;
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeByte(_value ? 1 : 0);
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return _value ? "TRUE" : "FALSE";
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java Thu Oct 23 15:28:05 2008
@@ -19,9 +19,9 @@
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
-import org.apache.poi.ss.formula.WorkbookDependentFormula;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * Title:        Deleted Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
@@ -60,10 +60,10 @@
 	public int getSize() {
 		return 11;
 	}
-	public void writeBytes(byte[] data, int offset) {
-		LittleEndian.putByte(data, 0 + offset, sid + getPtgClass());
-		LittleEndian.putUShort(data, 1 + offset, field_1_index_extern_sheet);
-		LittleEndian.putInt(data, 3 + offset, unused1);
-		LittleEndian.putInt(data, 7 + offset, unused2);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(field_1_index_extern_sheet);
+		out.writeInt(unused1);
+		out.writeInt(unused2);
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java Thu Oct 23 15:28:05 2008
@@ -20,9 +20,9 @@
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
-import org.apache.poi.ss.formula.WorkbookDependentFormula;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * Title:        Deleted Reference 3D Ptg <P>
@@ -60,9 +60,9 @@
 	public int getSize() {
 		return 7;
 	}
-	public void writeBytes(byte[] data, int offset) {
-		LittleEndian.putByte(data, 0 + offset, sid + getPtgClass());
-		LittleEndian.putUShort(data, 1 + offset, field_1_index_extern_sheet);
-		LittleEndian.putInt(data, 3 + offset, unused1);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(field_1_index_extern_sheet);
+		out.writeInt(unused1);
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java Thu Oct 23 15:28:05 2008
@@ -19,6 +19,7 @@
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author Daniel Noll (daniel at nuix dot com dot au)
@@ -61,10 +62,9 @@
         return valueOf(in.readByte());
     }
 
-    public void writeBytes(byte [] array, int offset)
-    {
-        array[offset] = (byte) (sid + getPtgClass());
-        array[offset + 1] = (byte)field_1_error_code;
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeByte(field_1_error_code);
     }
 
     public String toFormulaString() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java Thu Oct 23 15:28:05 2008
@@ -19,7 +19,7 @@
 
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  *
@@ -38,37 +38,36 @@
       field_1_first_row = in.readShort();
       field_2_first_col = in.readShort();
     }
-    
-    public void writeBytes(byte [] array, int offset)
-    {
-      array[offset+0]= (byte) (sid);
-      LittleEndian.putShort(array,offset+1,field_1_first_row);
-      LittleEndian.putShort(array,offset+3,field_2_first_col);
+
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeShort(field_1_first_row);
+        out.writeShort(field_2_first_col);
     }
 
     public int getSize()
     {
         return SIZE;
     }
-    
+
     public short getRow() {
       return field_1_first_row;
     }
 
     public short getColumn() {
       return field_2_first_col;
-    }    
+    }
 
     public String toFormulaString()
     {
         throw new RecordFormatException("Coding Error: Expected ExpPtg to be converted from Shared to Non-Shared Formula by ValueRecordsAggregate, but it wasn't");
     }
-    
+
     public String toString()
     {
         StringBuffer buffer = new StringBuffer("[Array Formula or Shared Formula]\n");
         buffer.append("row = ").append(getRow()).append("\n");
         buffer.append("col = ").append(getColumn()).append("\n");
         return buffer.toString();
-    }    
+    }
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java Thu Oct 23 15:28:05 2008
@@ -16,10 +16,10 @@
 ==================================================================== */
 
 package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author aviks
@@ -55,9 +55,9 @@
         paramClass = fm.getParameterClassCodes();
     }
 
-    public void writeBytes(byte[] array, int offset) {
-        array[offset+0]= (byte) (sid + getPtgClass());
-        LittleEndian.putShort(array,offset+1,field_2_fnc_index);
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeShort(field_2_fnc_index);
     }
 
     public int getNumberOfOperands() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java Thu Oct 23 15:28:05 2008
@@ -16,10 +16,10 @@
 ==================================================================== */
 
 package org.apache.poi.hssf.record.formula;
-import org.apache.poi.util.LittleEndian;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
 import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  *
@@ -64,10 +64,10 @@
         }
     }
 
-     public void writeBytes(byte[] array, int offset) {
-        array[offset+0]=(byte) (sid + getPtgClass());
-        array[offset+1]=field_1_num_args;
-        LittleEndian.putShort(array,offset+2,field_2_fnc_index);
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeByte(field_1_num_args);
+        out.writeShort(field_2_fnc_index);
     }
 
      public int getNumberOfOperands() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntPtg.java Thu Oct 23 15:28:05 2008
@@ -18,57 +18,59 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Integer (unsigned short integer)
- * Stores an unsigned short value (java int) in a formula
- * @author  Andrew C. Oliver (acoliver at apache dot org)
+ * Integer (unsigned short integer) Stores an unsigned short value (java int) in
+ * a formula
+ * 
+ * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class IntPtg extends ScalarConstantPtg {
-    // 16 bit unsigned integer
-    private static final int MIN_VALUE = 0x0000;
-    private static final int MAX_VALUE = 0xFFFF;
-    
-    /**
-     * Excel represents integers 0..65535 with the tInt token. 
-     * @return <code>true</code> if the specified value is within the range of values 
-     * <tt>IntPtg</tt> can represent. 
-     */
-    public static boolean isInRange(int i) {
-        return i>=MIN_VALUE && i <=MAX_VALUE;
-    }
-
-    public final static int  SIZE = 3;
-    public final static byte sid  = 0x1e;
-    private final int field_1_value;
-  
-    public IntPtg(RecordInputStream in) {
-        this(in.readUShort());
-    }
-
-    public IntPtg(int value) {
-        if(!isInRange(value)) {
-            throw new IllegalArgumentException("value is out of range: " + value);
-        }
-        field_1_value = value;
-    }
-
-    public int getValue() {
-        return field_1_value;
-    }
-
-    public void writeBytes(byte [] array, int offset) {
-        array[ offset + 0 ] = sid;
-        LittleEndian.putUShort(array, offset + 1, getValue());
-    }
-
-    public int getSize() {
-        return SIZE;
-    }
-
-    public String toFormulaString() {
-        return String.valueOf(getValue());
-    }
+	// 16 bit unsigned integer
+	private static final int MIN_VALUE = 0x0000;
+	private static final int MAX_VALUE = 0xFFFF;
+
+	/**
+	 * Excel represents integers 0..65535 with the tInt token.
+	 * 
+	 * @return <code>true</code> if the specified value is within the range of values 
+	 * <tt>IntPtg</tt> can represent.
+	 */
+	public static boolean isInRange(int i) {
+		return i >= MIN_VALUE && i <= MAX_VALUE;
+	}
+
+	public final static int SIZE = 3;
+	public final static byte sid = 0x1e;
+	private final int field_1_value;
+
+	public IntPtg(RecordInputStream in) {
+		this(in.readUShort());
+	}
+
+	public IntPtg(int value) {
+		if (!isInRange(value)) {
+			throw new IllegalArgumentException("value is out of range: " + value);
+		}
+		field_1_value = value;
+	}
+
+	public int getValue() {
+		return field_1_value;
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(getValue());
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return String.valueOf(getValue());
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java Thu Oct 23 15:28:05 2008
@@ -17,54 +17,46 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
 public final class IntersectionPtg extends OperationPtg {
-    public final static byte sid  = 0x0f;
+	public final static byte sid = 0x0f;
 
-    public static final OperationPtg instance = new IntersectionPtg();
-
-    private IntersectionPtg() {
-    	// enforce singleton
-    }
-
-    public final boolean isBaseToken() {
-        return true;
-    }
-
-    public int getSize()
-    {
-        return 1;
-    }
-
-    public void writeBytes( byte[] array, int offset )
-    {
-        array[ offset + 0 ] = sid;
-    }
-
-    /** Implementation of method from Ptg */
-    public String toFormulaString()
-    {
-        return " ";
-    }
-
-
-    /** implementation of method from OperationsPtg*/
-    public String toFormulaString(String[] operands)
-    {
-         StringBuffer buffer = new StringBuffer();
-
-         buffer.append(operands[ 0 ]);
-         buffer.append(" ");
-         buffer.append(operands[ 1 ]);
-         return buffer.toString();
-     }
-
-    public int getNumberOfOperands()
-    {
-        return 2;
-    }
+	public static final OperationPtg instance = new IntersectionPtg();
 
+	private IntersectionPtg() {
+		// enforce singleton
+	}
+
+	public final boolean isBaseToken() {
+		return true;
+	}
+
+	public int getSize() {
+		return 1;
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+	}
+
+	public String toFormulaString() {
+		return " ";
+	}
+
+	public String toFormulaString(String[] operands) {
+		StringBuffer buffer = new StringBuffer();
+
+		buffer.append(operands[0]);
+		buffer.append(" ");
+		buffer.append(operands[1]);
+		return buffer.toString();
+	}
+
+	public int getNumberOfOperands() {
+		return 2;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java Thu Oct 23 15:28:05 2008
@@ -18,67 +18,44 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
 public class MemAreaPtg extends OperandPtg {
-    public final static short sid  = 0x26;
-    private final static int  SIZE = 7;
-    private int               field_1_reserved;
-    private short             field_2_subex_len;
-
-    /** Creates new MemAreaPtg */
-
-    public MemAreaPtg()
-    {
-    }
-
-    public MemAreaPtg(RecordInputStream in)
-    {
-        field_1_reserved  = in.readInt();
-        field_2_subex_len = in.readShort();
-    }
-
-    public void setReserved(int res)
-    {
-        field_1_reserved = res;
-    }
-
-    public int getReserved()
-    {
-        return field_1_reserved;
-    }
-
-    public void setSubexpressionLength(short subexlen)
-    {
-        field_2_subex_len = subexlen;
-    }
-
-    public short getSubexpressionLength()
-    {
-        return field_2_subex_len;
-    }
-
-    public void writeBytes(byte [] array, int offset)
-    {
-        array[offset] = (byte) (sid + getPtgClass());
-        LittleEndian.putInt(array, offset + 1, field_1_reserved);
-        LittleEndian.putShort(array, offset + 5, field_2_subex_len);
-    }
-
-    public int getSize()
-    {
-        return SIZE;
-    }
-
-    public String toFormulaString()
-    {
-        return ""; // TODO: Not sure how to format this. -- DN
-    }
-
-    public byte getDefaultOperandClass() {
-    	return Ptg.CLASS_VALUE;
-    }
+	public final static short sid = 0x26;
+	private final static int SIZE = 7;
+	private final int field_1_reserved;
+	private final int field_2_subex_len;
+
+	/** Creates new MemAreaPtg */
+
+	public MemAreaPtg(int subexLen) {
+		field_1_reserved = 0;
+		field_2_subex_len = subexLen;
+	}
+
+	public MemAreaPtg(RecordInputStream in) {
+		field_1_reserved = in.readInt();
+		field_2_subex_len = in.readShort();
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeInt(field_1_reserved);
+		out.writeShort(field_2_subex_len);
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return ""; // TODO: Not sure how to format this. -- DN
+	}
+
+	public byte getDefaultOperandClass() {
+		return Ptg.CLASS_VALUE;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java Thu Oct 23 15:28:05 2008
@@ -18,35 +18,40 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- *
- * @author  andy
+ * 
+ * @author andy
  * @author Jason Height (jheight at chariot dot net dot au)
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
-
-public final class MemErrPtg extends MemAreaPtg {
-    public final static short sid  = 0x27;
-
-    /** Creates new MemErrPtg */
-
-    public MemErrPtg()
-    {
-    }
-
-    public MemErrPtg(RecordInputStream in) {
-        super(in);
-    }
-
-    public void writeBytes(byte [] array, int offset) {
-        super.writeBytes(array, offset);
-        array[offset] = (byte) (sid + getPtgClass());
-    }
-
-    public String toFormulaString()
-    {
-        return "ERR#";
-    }
+public final class MemErrPtg extends OperandPtg {
+	public final static short sid = 0x27;
+	private final static int SIZE = 7;
+	private int field_1_reserved;
+	private short field_2_subex_len;
+
+	public MemErrPtg(RecordInputStream in) {
+		field_1_reserved = in.readInt();
+		field_2_subex_len = in.readShort();
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeInt(field_1_reserved);
+		out.writeShort(field_2_subex_len);
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return "ERR#";
+	}
+
+	public byte getDefaultOperandClass() {
+		return Ptg.CLASS_VALUE;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java Thu Oct 23 15:28:05 2008
@@ -18,55 +18,50 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author Glen Stampoultzis (glens at apache.org)
  */
 public final class MemFuncPtg extends OperandPtg {
 
-    public final static byte sid = 0x29;
-    private final int field_1_len_ref_subexpression;
+	public final static byte sid = 0x29;
+	private final int field_1_len_ref_subexpression;
 
-    /**Creates new function pointer from a byte array
-     * usually called while reading an excel file.
-     */
-    public MemFuncPtg(RecordInputStream in) {
-        this(in.readUShort());
-    }
-
-    public MemFuncPtg(int subExprLen) {
-    	field_1_len_ref_subexpression = subExprLen;
-	}
-
-	public int getSize()
-    {
-        return 3;
-    }
-
-    public void writeBytes( byte[] array, int offset )
-    {
-        array[offset + 0] =  sid ;
-        LittleEndian.putUShort( array, offset + 1, field_1_len_ref_subexpression );
-    }
-
-    public String toFormulaString()
-    {
-        return "";
-    }
-
-    public byte getDefaultOperandClass()
-    {
-        return Ptg.CLASS_REF;
-    }
-
-    public int getNumberOfOperands()
-    {
-        return field_1_len_ref_subexpression;
-    }
-
-    public int getLenRefSubexpression()
-    {
-        return field_1_len_ref_subexpression;
-    }
+	/**
+	 * Creates new function pointer from a byte array usually called while
+	 * reading an excel file.
+	 */
+	public MemFuncPtg(RecordInputStream in) {
+		this(in.readUShort());
+	}
+
+	public MemFuncPtg(int subExprLen) {
+		field_1_len_ref_subexpression = subExprLen;
+	}
+
+	public int getSize() {
+		return 3;
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(field_1_len_ref_subexpression);
+	}
+
+	public String toFormulaString() {
+		return "";
+	}
+
+	public byte getDefaultOperandClass() {
+		return Ptg.CLASS_REF;
+	}
+
+	public int getNumberOfOperands() {
+		return field_1_len_ref_subexpression;
+	}
+
+	public int getLenRefSubexpression() {
+		return field_1_len_ref_subexpression;
+	}
 }
\ No newline at end of file

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java Thu Oct 23 15:28:05 2008
@@ -17,32 +17,35 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.util.LittleEndianOutput;
+
 /**
  * Missing Function Arguments
- *
+ * 
  * Avik Sengupta &lt;avik at apache.org&gt;
+ * 
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class MissingArgPtg extends ScalarConstantPtg {
-   
-    private final static int SIZE = 1;
-    public final static byte sid  = 0x16;
-   
-    public static final Ptg instance = new MissingArgPtg();
-
-    private MissingArgPtg() {
-    	// enforce singleton
-    }
-     
-    public void writeBytes(byte [] array, int offset) {
-        array[ offset + 0 ] = sid;
-    }
-
-    public int getSize() {
-        return SIZE;
-    }
-   
-    public String toFormulaString() {
-        return " ";
-    }
+
+	private final static int SIZE = 1;
+	public final static byte sid = 0x16;
+
+	public static final Ptg instance = new MissingArgPtg();
+
+	private MissingArgPtg() {
+		// enforce singleton
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return " ";
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/NamePtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/NamePtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/NamePtg.java Thu Oct 23 15:28:05 2008
@@ -18,62 +18,62 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.ss.formula.WorkbookDependentFormula;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- *
- * @author  andy
+ * 
+ * @author andy
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class NamePtg extends OperandPtg implements WorkbookDependentFormula {
-    public final static short sid  = 0x23;
-    private final static int  SIZE = 5;
-    /** one-based index to defined name record */
-    private int  field_1_label_index;
-    private short             field_2_zero;   // reserved must be 0
-
-    /**
-     * @param nameIndex zero-based index to name within workbook
-     */
-    public NamePtg(int nameIndex) {
-        field_1_label_index = 1+nameIndex; // convert to 1-based
-    }
-
-    /** Creates new NamePtg */
-
-    public NamePtg(RecordInputStream in) {
-        field_1_label_index = in.readShort();
-        field_2_zero        = in.readShort();
-    }
-    
-    /**
-     * @return zero based index to a defined name record in the LinkTable
-     */
-    public int getIndex() {
-        return field_1_label_index-1; // convert to zero based
-    }
-
-    public void writeBytes(byte [] array, int offset) {
-    	LittleEndian.putByte(array, offset + 0, sid + getPtgClass());
-		LittleEndian.putUShort(array, offset + 1, field_1_label_index);
-		LittleEndian.putUShort(array, offset + 3, field_2_zero);
-    }
-
-    public int getSize() {
-        return SIZE;
-    }
-
-    public String toFormulaString(FormulaRenderingWorkbook book)
-    {
-    	return book.getNameText(this);
-    }
+	public final static short sid = 0x23;
+	private final static int SIZE = 5;
+	/** one-based index to defined name record */
+	private int field_1_label_index;
+	private short field_2_zero; // reserved must be 0
+
+	/**
+	 * @param nameIndex zero-based index to name within workbook
+	 */
+	public NamePtg(int nameIndex) {
+		field_1_label_index = 1 + nameIndex; // convert to 1-based
+	}
+
+	/** Creates new NamePtg */
+
+	public NamePtg(RecordInputStream in) {
+		field_1_label_index = in.readShort();
+		field_2_zero = in.readShort();
+	}
+
+	/**
+	 * @return zero based index to a defined name record in the LinkTable
+	 */
+	public int getIndex() {
+		return field_1_label_index - 1; // convert to zero based
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(field_1_label_index);
+		out.writeShort(field_2_zero);
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString(FormulaRenderingWorkbook book) {
+		return book.getNameText(this);
+	}
+
 	public String toFormulaString() {
 		throw new RuntimeException("3D references need a workbook to determine formula text");
 	}
-    
-    public byte getDefaultOperandClass() {
+
+	public byte getDefaultOperandClass() {
 		return Ptg.CLASS_REF;
 	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java Thu Oct 23 15:28:05 2008
@@ -18,9 +18,9 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.ss.formula.WorkbookDependentFormula;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * 
@@ -55,11 +55,11 @@
 		this(in.readUShort(), in.readUShort(), in.readUShort());
 	}
 
-	public void writeBytes(byte[] array, int offset) {
-		LittleEndian.putByte(array, offset + 0, sid + getPtgClass());
-		LittleEndian.putUShort(array, offset + 1, _sheetRefIndex);
-		LittleEndian.putUShort(array, offset + 3, _nameNumber);
-		LittleEndian.putUShort(array, offset + 5, _reserved);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeShort(_sheetRefIndex);
+		out.writeShort(_nameNumber);
+		out.writeShort(_reserved);
 	}
 
 	public int getSize() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java Thu Oct 23 15:28:05 2008
@@ -18,53 +18,54 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Number
- * Stores a floating point value in a formula
- * value stored in a 8 byte field using IEEE notation
- * @author  Avik Sengupta
+ * Number Stores a floating point value in a formula value stored in a 8 byte
+ * field using IEEE notation
+ * 
+ * @author Avik Sengupta
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class NumberPtg extends ScalarConstantPtg {
-    public final static int  SIZE = 9;
-    public final static byte sid  = 0x1f;
-    private final double field_1_value;
-        
-    /** Create a NumberPtg from a byte array read from disk */
-    public NumberPtg(RecordInputStream in) {
-        this(in.readDouble());
-    }
-    
-    /** Create a NumberPtg from a string representation of  the number
-     *  Number format is not checked, it is expected to be validated in the parser
-     *   that calls this method. 
-     *  @param value : String representation of a floating point number
-     */
-    public NumberPtg(String value) {
-        this(Double.parseDouble(value));
-    }
-    
-    public NumberPtg(double value) {
-        field_1_value = value;
-    }
-    
-    public double getValue() {
-        return field_1_value;
-    }
-
-    public void writeBytes(byte [] array, int offset) {
-        array[ offset + 0 ] = sid;
-        LittleEndian.putDouble(array, offset + 1, getValue());
-    }
-
-    public int getSize() {
-        return SIZE;
-    }
-
-    public String toFormulaString() {
-        // TODO - java's rendering of double values is not quite same as excel's
-        return String.valueOf(field_1_value);
-    }
+	public final static int SIZE = 9;
+	public final static byte sid = 0x1f;
+	private final double field_1_value;
+
+	public NumberPtg(RecordInputStream in) {
+		this(in.readDouble());
+	}
+
+	/**
+	 * Create a NumberPtg from a string representation of the number Number
+	 * format is not checked, it is expected to be validated in the parser that
+	 * calls this method.
+	 * 
+	 * @param value String representation of a floating point number
+	 */
+	public NumberPtg(String value) {
+		this(Double.parseDouble(value));
+	}
+
+	public NumberPtg(double value) {
+		field_1_value = value;
+	}
+
+	public double getValue() {
+		return field_1_value;
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+		out.writeDouble(getValue());
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		// TODO - java's rendering of double values is not quite same as excel's
+		return String.valueOf(field_1_value);
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java Thu Oct 23 15:28:05 2008
@@ -15,46 +15,44 @@
    limitations under the License.
 ==================================================================== */
 
-
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * While formula tokens are stored in RPN order and thus do not need parenthesis for 
- * precedence reasons, Parenthesis tokens ARE written to ensure that user entered
- * parenthesis are displayed as-is on reading back
- *
- * Avik Sengupta &lt;lists@aviksengupta.com&gt;
- * Andrew C. Oliver (acoliver at apache dot org)
+ * While formula tokens are stored in RPN order and thus do not need parenthesis
+ * for precedence reasons, Parenthesis tokens ARE written to ensure that user
+ * entered parenthesis are displayed as-is on reading back
+ * 
+ * Avik Sengupta &lt;lists@aviksengupta.com&gt; Andrew C. Oliver (acoliver at
+ * apache dot org)
+ * 
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public final class ParenthesisPtg extends ControlPtg {
-   
-    private final static int SIZE = 1;
-    public final static byte sid  = 0x15;
-   
-    public static final ControlPtg instance = new ParenthesisPtg();
-    private ParenthesisPtg() {
-    	// enforce singleton
-    }
-    
-    public void writeBytes(byte [] array, int offset)
-    {
-        array[ offset + 0 ] = sid;
-    }
-
-    public int getSize()
-    {
-        return SIZE;
-    }
-
-    public String toFormulaString()
-    {
-        return "()";
-    }
-
-          
-    public String toFormulaString(String[] operands) {
-        return "("+operands[0]+")";
-    }  
+
+	private final static int SIZE = 1;
+	public final static byte sid = 0x15;
+
+	public static final ControlPtg instance = new ParenthesisPtg();
+
+	private ParenthesisPtg() {
+		// enforce singleton
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+	}
+
+	public int getSize() {
+		return SIZE;
+	}
+
+	public String toFormulaString() {
+		return "()";
+	}
+
+	public String toFormulaString(String[] operands) {
+		return "(" + operands[0] + ")";
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ptg.java Thu Oct 23 15:28:05 2008
@@ -21,7 +21,7 @@
 import java.util.List;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.HexDump;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
 import org.apache.poi.util.LittleEndianOutput;
 
 /**
@@ -128,7 +128,7 @@
 
 	private static Ptg createBasePtg(byte id, RecordInputStream in) {
 		switch(id) {
-			case 0x00:                return new UnknownPtg(); // TODO - not a real Ptg
+			case 0x00:                return new UnknownPtg(id); // TODO - not a real Ptg
 			case ExpPtg.sid:          return new ExpPtg(in);          // 0x01
 			case TblPtg.sid:          return new TblPtg(in);          // 0x02
 			case AddPtg.sid:          return AddPtg.instance;         // 0x03
@@ -229,14 +229,16 @@
 	 */
 	public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
 		int pos = 0;
-		int size = ptgs.length;
+		int nTokens = ptgs.length;
+		
+		LittleEndianOutput out = new LittleEndianByteArrayOutputStream(array, offset);
 
 		List arrayPtgs = null;
 
-		for (int k = 0; k < size; k++) {
+		for (int k = 0; k < nTokens; k++) {
 			Ptg ptg = ptgs[k];
 
-			ptg.writeBytes(array, pos + offset);
+			ptg.write(out);
 			if (ptg instanceof ArrayPtg) {
 				if (arrayPtgs == null) {
 					arrayPtgs = new ArrayList(5);
@@ -266,38 +268,12 @@
 	 */
 //    public abstract int getDataSize();
 
-	public final byte[] getBytes()
-	{
-		int    size  = getSize();
-		byte[] bytes = new byte[ size ];
-
-		writeBytes(bytes, 0);
-		return bytes;
-	}
-	/** write this Ptg to a byte array*/
-	public abstract void writeBytes(byte [] array, int offset);
-
-	public void write(LittleEndianOutput out) {
-		out.write(getBytes()); // TODO - optimise - just a hack for the moment
-	}
+	public abstract void write(LittleEndianOutput out);
 	
 	/**
 	 * return a string representation of this token alone
 	 */
 	public abstract String toFormulaString();
-	/**
-	 * dump a debug representation (hexdump) to a string
-	 */
-	public final String toDebugString() {
-		byte[] ba = new byte[getSize()];
-		writeBytes(ba,0);
-		try {
-			return HexDump.dump(ba,0,0);
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
 
 	/** Overridden toString method to ensure object hash is not printed.
 	 * This helps get rid of gratuitous diffs when comparing two dumps

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/RangePtg.java Thu Oct 23 15:28:05 2008
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.util.LittleEndianOutput;
+
 
 /**
  * @author Daniel Noll (daniel at nuix dot com dot au)
@@ -40,9 +42,8 @@
         return SIZE;
     }
 
-    public void writeBytes( byte[] array, int offset )
-    {
-        array[ offset + 0 ] = sid;
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
     }
 
     public String toFormulaString()

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java Thu Oct 23 15:28:05 2008
@@ -18,50 +18,54 @@
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * @author Josh Micich
  */
 abstract class Ref2DPtgBase extends RefPtgBase {
-    private final static int SIZE = 5;
+	private final static int SIZE = 5;
 
-    /**
-     * Takes in a String representation of a cell reference and fills out the
-     * numeric fields.
-     */
-    protected Ref2DPtgBase(String cellref) {
-    	super(cellref);
-    }
-
-    protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
-      setRow(row);
-      setColumn(column);
-      setRowRelative(isRowRelative);
-      setColRelative(isColumnRelative);
-    }
-
-    protected Ref2DPtgBase(RecordInputStream in) {
-        readCoordinates(in);
-    }
-    public final void writeBytes(byte [] array, int offset) {
-    	LittleEndian.putByte(array, offset+0, getSid() + getPtgClass());
-    	writeCoordinates(array, offset+1);
-    }
-    public final String toFormulaString() {
-    	return formatReferenceAsString();
-    }
+	/**
+	 * Takes in a String representation of a cell reference and fills out the
+	 * numeric fields.
+	 */
+	protected Ref2DPtgBase(String cellref) {
+		super(cellref);
+	}
+
+	protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
+		setRow(row);
+		setColumn(column);
+		setRowRelative(isRowRelative);
+		setColRelative(isColumnRelative);
+	}
+
+	protected Ref2DPtgBase(RecordInputStream in) {
+		readCoordinates(in);
+	}
+
+	public void write(LittleEndianOutput out) {
+		out.writeByte(getSid() + getPtgClass());
+		writeCoordinates(out);
+	}
+
+	public final String toFormulaString() {
+		return formatReferenceAsString();
+	}
 
 	protected abstract byte getSid();
-    public final int getSize() {
-        return SIZE;
-    }
-    public final String toString() {
-        StringBuffer sb = new StringBuffer();
-        sb.append(getClass().getName());
-        sb.append(" [");
-        sb.append(formatReferenceAsString());
-        sb.append("]");
-        return sb.toString();
-    }
+
+	public final int getSize() {
+		return SIZE;
+	}
+
+	public final String toString() {
+		StringBuffer sb = new StringBuffer();
+		sb.append(getClass().getName());
+		sb.append(" [");
+		sb.append(formatReferenceAsString());
+		sb.append("]");
+		return sb.toString();
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Thu Oct 23 15:28:05 2008
@@ -22,7 +22,7 @@
 import org.apache.poi.ss.formula.ExternSheetReferenceToken;
 import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
 import org.apache.poi.ss.formula.WorkbookDependentFormula;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * Title:        Reference 3D Ptg <P>
@@ -66,10 +66,10 @@
         return sb.toString();
     }
 
-    public void writeBytes(byte [] array, int offset) {
-        LittleEndian.putByte(array, 0 + offset, sid + getPtgClass());
-        LittleEndian.putUShort(array, 1 + offset, getExternSheetIndex());
-        writeCoordinates(array, offset + 3);
+	public void write(LittleEndianOutput out) {
+		out.writeByte(sid + getPtgClass());
+        out.writeShort(getExternSheetIndex());
+        writeCoordinates(out);
     }
 
     public int getSize() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java Thu Oct 23 15:28:05 2008
@@ -19,8 +19,7 @@
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * RefError - handles deleted cell reference
@@ -43,9 +42,9 @@
         return getClass().getName();
     }
 
-    public void writeBytes(byte [] array, int offset) {
-        LittleEndian.putByte(array, offset+0, sid + getPtgClass());
-        LittleEndian.putInt(array,offset+1,field_1_reserved);
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeInt(field_1_reserved);
     }
 
     public int getSize()

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java Thu Oct 23 15:28:05 2008
@@ -21,108 +21,110 @@
 import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * ReferencePtgBase - handles references (such as A1, A2, IA4)
- * @author  Andrew C. Oliver (acoliver@apache.org)
+ * 
+ * @author Andrew C. Oliver (acoliver@apache.org)
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 public abstract class RefPtgBase extends OperandPtg {
 
-    private final static int MAX_ROW_NUMBER = 65536;
+	private final static int MAX_ROW_NUMBER = 65536;
 
-   /** The row index - zero based unsigned 16 bit value */
-    private int            field_1_row;
-    /** Field 2
-     * - lower 8 bits is the zero based unsigned byte column index
-     * - bit 16 - isRowRelative
-     * - bit 15 - isColumnRelative
-     */
-    private int            field_2_col;
-    private static final BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
-    private static final BitField         colRelative = BitFieldFactory.getInstance(0x4000);
-    private static final BitField         column      = BitFieldFactory.getInstance(0x00FF);
-
-    protected RefPtgBase() {
-      //Required for clone methods
-    }
-
-    /**
-     * Takes in a String representation of a cell reference and fills out the
-     * numeric fields.
-     */
-    protected RefPtgBase(String cellref) {
-        CellReference c= new CellReference(cellref);
-        setRow(c.getRow());
-        setColumn(c.getCol());
-        setColRelative(!c.isColAbsolute());
-        setRowRelative(!c.isRowAbsolute());
-    }
-
-    protected RefPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
-      setRow(row);
-      setColumn(column);
-      setRowRelative(isRowRelative);
-      setColRelative(isColumnRelative);
-    }
-
-    protected final void readCoordinates(RecordInputStream in) {
-        field_1_row = in.readUShort();
-        field_2_col = in.readUShort();
-    }
-    protected final void writeCoordinates(byte[] array, int offset) {
-        LittleEndian.putUShort(array, offset + 0, field_1_row);
-        LittleEndian.putUShort(array, offset + 2, field_2_col);
-    }
-
-    public final void setRow(int row) {
-        if(row < 0 || row >= MAX_ROW_NUMBER) {
-           throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
-        }
-        field_1_row = row;
-    }
-
-    /**
-     * @return the row number as an int, between 0 and 65535
-     */
-    public final int getRow(){
-        return field_1_row;
-    }
-
-    public final boolean isRowRelative() {
-        return rowRelative.isSet(field_2_col);
-    }
-
-    public final void setRowRelative(boolean rel) {
-        field_2_col=rowRelative.setBoolean(field_2_col,rel);
-    }
-
-    public final boolean isColRelative() {
-        return colRelative.isSet(field_2_col);
-    }
-
-    public final void setColRelative(boolean rel) {
-        field_2_col=colRelative.setBoolean(field_2_col,rel);
-    }
-
-    public final void setColumn(int col) {
-        if(col < 0 || col >= 0x100) {
-            throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
-        }
-       field_2_col = column.setValue(field_2_col, col);
-    }
-
-    public final int getColumn() {
-       return column.getValue(field_2_col);
-    }
-    protected final String formatReferenceAsString() {
-        // Only make cell references as needed. Memory is an issue
-        CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(), !isColRelative());
-        return cr.formatAsString();
-    }
-
-    public final byte getDefaultOperandClass() {
-        return Ptg.CLASS_REF;
-    }
+	/** The row index - zero based unsigned 16 bit value */
+	private int field_1_row;
+	/**
+	 * Field 2 - lower 8 bits is the zero based unsigned byte column index - bit
+	 * 16 - isRowRelative - bit 15 - isColumnRelative
+	 */
+	private int field_2_col;
+	private static final BitField rowRelative = BitFieldFactory.getInstance(0x8000);
+	private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
+	private static final BitField column = BitFieldFactory.getInstance(0x00FF);
+
+	protected RefPtgBase() {
+		// Required for clone methods
+	}
+
+	/**
+	 * Takes in a String representation of a cell reference and fills out the
+	 * numeric fields.
+	 */
+	protected RefPtgBase(String cellref) {
+		CellReference c = new CellReference(cellref);
+		setRow(c.getRow());
+		setColumn(c.getCol());
+		setColRelative(!c.isColAbsolute());
+		setRowRelative(!c.isRowAbsolute());
+	}
+
+	protected RefPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
+		setRow(row);
+		setColumn(column);
+		setRowRelative(isRowRelative);
+		setColRelative(isColumnRelative);
+	}
+
+	protected final void readCoordinates(RecordInputStream in) {
+		field_1_row = in.readUShort();
+		field_2_col = in.readUShort();
+	}
+
+	protected final void writeCoordinates(LittleEndianOutput out) {
+		out.writeShort(field_1_row);
+		out.writeShort(field_2_col);
+	}
+
+	public final void setRow(int rowIndex) {
+		if (rowIndex < 0 || rowIndex >= MAX_ROW_NUMBER) {
+			throw new IllegalArgumentException("rowIndex must be between 0 and " + MAX_ROW_NUMBER);
+		}
+		field_1_row = rowIndex;
+	}
+
+	/**
+	 * @return the row number as an int, between 0 and 65535
+	 */
+	public final int getRow() {
+		return field_1_row;
+	}
+
+	public final boolean isRowRelative() {
+		return rowRelative.isSet(field_2_col);
+	}
+
+	public final void setRowRelative(boolean rel) {
+		field_2_col = rowRelative.setBoolean(field_2_col, rel);
+	}
+
+	public final boolean isColRelative() {
+		return colRelative.isSet(field_2_col);
+	}
+
+	public final void setColRelative(boolean rel) {
+		field_2_col = colRelative.setBoolean(field_2_col, rel);
+	}
+
+	public final void setColumn(int col) {
+		if (col < 0 || col >= 0x100) {
+			throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
+		}
+		field_2_col = column.setValue(field_2_col, col);
+	}
+
+	public final int getColumn() {
+		return column.getValue(field_2_col);
+	}
+
+	protected final String formatReferenceAsString() {
+		// Only make cell references as needed. Memory is an issue
+		CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(), !isColRelative());
+		return cr.formatAsString();
+	}
+
+	public final byte getDefaultOperandClass() {
+		return Ptg.CLASS_REF;
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/StringPtg.java Thu Oct 23 15:28:05 2008
@@ -20,6 +20,7 @@
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.StringUtil;
 
 /**
@@ -78,14 +79,14 @@
         return field_3_string;
     }
 
-    public void writeBytes(byte[] array, int offset) {
-        array[offset + 0] = sid;
-        array[offset + 1] = (byte) field_1_length;
-        array[offset + 2] = field_2_options;
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeByte(field_1_length);
+        out.writeByte(field_2_options);
         if (fHighByte.isSet(field_2_options)) {
-            StringUtil.putUnicodeLE(getValue(), array, offset + 3);
+            StringUtil.putUnicodeLE(getValue(), out);
         } else {
-            StringUtil.putCompressedUnicode(getValue(), array, offset + 3);
+            StringUtil.putCompressedUnicode(getValue(), out);
         }
     }
 

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/TblPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/TblPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/TblPtg.java Thu Oct 23 15:28:05 2008
@@ -19,7 +19,7 @@
 
 import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  * This ptg indicates a data table.
@@ -48,10 +48,10 @@
       field_2_first_col = in.readUShort();
     }
 
-    public void writeBytes(byte [] array, int offset) {
-      LittleEndian.putByte(array, offset+0, sid);
-      LittleEndian.putUShort(array, offset+1, field_1_first_row);
-      LittleEndian.putUShort(array, offset+3, field_2_first_col);
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
+        out.writeShort(field_1_first_row);
+        out.writeShort(field_2_first_col);
     }
 
     public int getSize() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnionPtg.java Thu Oct 23 15:28:05 2008
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.util.LittleEndianOutput;
+
 
 /**
  * @author Glen Stampoultzis (glens at apache.org)
@@ -39,9 +41,8 @@
         return 1;
     }
 
-    public void writeBytes( byte[] array, int offset )
-    {
-        array[ offset + 0 ] = sid;
+    public void write(LittleEndianOutput out) {
+        out.writeByte(sid + getPtgClass());
     }
 
     public String toFormulaString()

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java Thu Oct 23 15:28:05 2008
@@ -16,7 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
  *
@@ -25,22 +25,17 @@
  */
 public class UnknownPtg extends Ptg {
     private short size = 1;
+    private final int _sid;
 
-    /** Creates new UnknownPtg */
-
-    public UnknownPtg()
-    {
-    }
-
-    public UnknownPtg(RecordInputStream in) {
-        // doesn't need anything
+    public UnknownPtg(int sid) {
+        _sid = sid;
     }
 
     public boolean isBaseToken() {
-    	return true;
+        return true;
     }
-    public void writeBytes(byte [] array, int offset)
-    {
+    public void write(LittleEndianOutput out) {
+        out.writeByte(_sid);
     }
 
     public int getSize()
@@ -55,8 +50,6 @@
     public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
 
     public Object clone() {
-      return new UnknownPtg();
+      return this;
     }
-
-    
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java?rev=707486&r1=707485&r2=707486&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/ValueOperatorPtg.java Thu Oct 23 15:28:05 2008
@@ -17,18 +17,19 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndianOutput;
 
 /**
- * Common superclass of all value operators.
- * Subclasses include all unary and binary operators except for the reference operators (IntersectionPtg, RangePtg, UnionPtg) 
+ * Common superclass of all value operators. Subclasses include all unary and
+ * binary operators except for the reference operators (IntersectionPtg,
+ * RangePtg, UnionPtg)
  * 
  * @author Josh Micich
  */
 public abstract class ValueOperatorPtg extends OperationPtg {
 
 	/**
-	 * All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classified)  
+	 * All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classified)
 	 */
 	public final boolean isBaseToken() {
 		return true;
@@ -38,8 +39,8 @@
 		return Ptg.CLASS_VALUE;
 	}
 
-	public final void writeBytes(byte[] array, int offset) {
-		array[offset + 0] = getSid();
+	public void write(LittleEndianOutput out) {
+		out.writeByte(getSid());
 	}
 
 	protected abstract byte getSid();
@@ -47,8 +48,9 @@
 	public final int getSize() {
 		return 1;
 	}
-    public final String toFormulaString() {
-    	// TODO - prune this method out of the hierarchy
-    	throw new RuntimeException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs");
+
+	public final String toFormulaString() {
+		// TODO - prune this method out of the hierarchy
+		throw new RuntimeException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs");
 	}
 }

Added: poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java?rev=707486&view=auto
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java (added)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java Thu Oct 23 15:28:05 2008
@@ -0,0 +1,84 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.util;
+
+
+/**
+ * Adapts a plain byte array to {@link LittleEndianOutput} 
+ * 
+ * 
+ * @author Josh Micich
+ */
+public final class LittleEndianByteArrayOutputStream implements LittleEndianOutput {
+	private final byte[] _buf;
+	private final int _endIndex;
+	private int _writeIndex;
+
+	public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset, int maxWriteLen) {
+		_buf = buf;
+		_writeIndex = startOffset;
+		_endIndex = startOffset + maxWriteLen;
+	}
+	public LittleEndianByteArrayOutputStream(byte[] buf, int startOffset) {
+		this(buf, startOffset, buf.length - startOffset);
+	}
+
+	private void checkPosition(int i) {
+		if (i > _endIndex - _writeIndex) {
+			throw new RuntimeException("Buffer overrun");
+		}
+	}
+
+	public void writeByte(int v) {
+		checkPosition(1);
+		_buf[_writeIndex++] = (byte)v;
+	}
+
+	public void writeDouble(double v) {
+		writeLong(Double.doubleToLongBits(v));
+	}
+
+	public void writeInt(int v) {
+		checkPosition(4);
+		int i = _writeIndex;
+		_buf[i++] = (byte)((v >>>  0) & 0xFF);
+		_buf[i++] = (byte)((v >>>  8) & 0xFF);
+		_buf[i++] = (byte)((v >>> 16) & 0xFF);
+		_buf[i++] = (byte)((v >>> 24) & 0xFF);
+		_writeIndex = i;
+	}
+
+	public void writeLong(long v) {
+		writeInt((int)(v >>  0));
+		writeInt((int)(v >> 32));
+	}
+
+	public void writeShort(int v) {
+		checkPosition(2);
+		int i = _writeIndex;
+		_buf[i++] = (byte)((v >>>  0) & 0xFF);
+		_buf[i++] = (byte)((v >>>  8) & 0xFF);
+		_writeIndex = i;
+	}
+	public void write(byte[] b) {
+		int len = b.length;
+		checkPosition(len);
+		System.arraycopy(b, 0, _buf, _writeIndex, len);
+		_writeIndex += len;
+	}
+}



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


Mime
View raw message