aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-10-24 02:08:47 +0000
committerJosh Micich <josh@apache.org>2008-10-24 02:08:47 +0000
commit3b2241f86cea431eb4ab287bc71a7332c126a194 (patch)
tree70a93cae7ffba87a59d9d3bee3dae02913ebaab5
parentb4265b89039ac2ddd7be69fd2955834cf72f4a33 (diff)
downloadpoi-3b2241f86cea431eb4ab287bc71a7332c126a194.tar.gz
poi-3b2241f86cea431eb4ab287bc71a7332c126a194.zip
Further conversion of Ptg classes to use LittleEndian input/output interfaces
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@707525 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-xsrc/java/org/apache/poi/hssf/record/CRNRecord.java31
-rwxr-xr-xsrc/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java54
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java4
-rwxr-xr-xsrc/java/org/apache/poi/hssf/record/formula/AreaPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java22
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/AttrPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/BoolPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/ErrPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/ExpPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/FuncPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/IntPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/NamePtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/NameXPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/NumberPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/Ptg.java22
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java4
-rwxr-xr-xsrc/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/RefNPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/RefPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/StringPtg.java4
-rw-r--r--src/java/org/apache/poi/hssf/record/formula/TblPtg.java4
-rw-r--r--src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java3
-rw-r--r--src/java/org/apache/poi/util/StringUtil.java21
-rw-r--r--src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java4
-rw-r--r--src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java3
37 files changed, 148 insertions, 128 deletions
diff --git a/src/java/org/apache/poi/hssf/record/CRNRecord.java b/src/java/org/apache/poi/hssf/record/CRNRecord.java
index 417f2a559a..050076cca2 100755
--- a/src/java/org/apache/poi/hssf/record/CRNRecord.java
+++ b/src/java/org/apache/poi/hssf/record/CRNRecord.java
@@ -18,17 +18,18 @@
package org.apache.poi.hssf.record;
import org.apache.poi.hssf.record.constant.ConstantValueParser;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianOutput;
/**
- * Title: CRN <P>
- * Description: This record stores the contents of an external cell or cell range <P>
- * REFERENCE: 5.23<P>
+ * Title: CRN(0x005A) <p/>
+ * Description: This record stores the contents of an external cell or cell range <p/>
+ * REFERENCE: OOO 5.23<p/>
*
* @author josh micich
*/
public final class CRNRecord extends Record {
- public final static short sid = 0x5A;
+ public final static short sid = 0x005A;
private int field_1_last_column_index;
private int field_2_first_column_index;
@@ -45,8 +46,8 @@ public final class CRNRecord extends Record {
public CRNRecord(RecordInputStream in) {
- field_1_last_column_index = in.readByte() & 0x00FF;
- field_2_first_column_index = in.readByte() & 0x00FF;
+ field_1_last_column_index = in.readUByte();
+ field_2_first_column_index = in.readUByte();
field_3_row_index = in.readShort();
int nValues = field_1_last_column_index - field_2_first_column_index + 1;
field_4_constant_values = ConstantValueParser.parse(in, nValues);
@@ -68,13 +69,15 @@ public final class CRNRecord extends Record {
public int serialize(int offset, byte [] data) {
int dataSize = getDataSize();
- LittleEndian.putShort(data, 0 + offset, sid);
- LittleEndian.putShort(data, 2 + offset, (short) dataSize);
- LittleEndian.putByte(data, 4 + offset, field_1_last_column_index);
- LittleEndian.putByte(data, 5 + offset, field_2_first_column_index);
- LittleEndian.putShort(data, 6 + offset, (short) field_3_row_index);
- ConstantValueParser.encode(data, 8 + offset, field_4_constant_values);
- return getRecordSize();
+ int recSize = 4 + dataSize;
+ LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
+ out.writeShort(sid);
+ out.writeShort(dataSize);
+ 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;
}
public int getRecordSize() {
diff --git a/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java b/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java
index 12f26bfdee..8304eb0ee3 100755
--- a/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java
+++ b/src/java/org/apache/poi/hssf/record/constant/ConstantValueParser.java
@@ -17,10 +17,11 @@
package org.apache.poi.hssf.record.constant;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.record.UnicodeString.UnicodeRecordStats;
-import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+import org.apache.poi.util.StringUtil;
/**
* To support Constant Values (2.5.7) as required by the CRN record.
@@ -47,7 +48,7 @@ public final class ConstantValueParser {
// no instances of this class
}
- public static Object[] parse(RecordInputStream in, int nValues) {
+ public static Object[] parse(LittleEndianInput in, int nValues) {
Object[] result = new Object[nValues];
for (int i = 0; i < result.length; i++) {
result[i] = readAConstantValue(in);
@@ -55,7 +56,7 @@ public final class ConstantValueParser {
return result;
}
- private static Object readAConstantValue(RecordInputStream in) {
+ private static Object readAConstantValue(LittleEndianInput in) {
byte grbit = in.readByte();
switch(grbit) {
case TYPE_EMPTY:
@@ -64,7 +65,7 @@ public final class ConstantValueParser {
case TYPE_NUMBER:
return new Double(in.readDouble());
case TYPE_STRING:
- return in.readUnicodeString();
+ return new UnicodeString(StringUtil.readUnicodeString(in));
case TYPE_BOOLEAN:
return readBoolean(in);
case TYPE_ERROR_CODE:
@@ -77,7 +78,7 @@ public final class ConstantValueParser {
throw new RuntimeException("Unknown grbit value (" + grbit + ")");
}
- private static Object readBoolean(RecordInputStream in) {
+ private static Object readBoolean(LittleEndianInput in) {
byte val = (byte)in.readLong(); // 7 bytes 'not used'
switch(val) {
case FALSE_ENCODING:
@@ -116,46 +117,43 @@ public final class ConstantValueParser {
return urs.recordSize;
}
- public static void encode(byte[] data, int offset, Object[] values) {
- int currentOffset = offset;
+ public static void encode(LittleEndianOutput out, Object[] values) {
for (int i = 0; i < values.length; i++) {
- currentOffset += encodeSingleValue(data, currentOffset, values[i]);
+ encodeSingleValue(out, values[i]);
}
}
- private static int encodeSingleValue(byte[] data, int offset, Object value) {
+ private static void encodeSingleValue(LittleEndianOutput out, Object value) {
if (value == EMPTY_REPRESENTATION) {
- LittleEndian.putByte(data, offset, TYPE_EMPTY);
- LittleEndian.putLong(data, offset+1, 0L);
- return 9;
+ out.writeByte(TYPE_EMPTY);
+ out.writeLong(0L);
+ return;
}
if (value instanceof Boolean) {
Boolean bVal = ((Boolean)value);
- LittleEndian.putByte(data, offset, TYPE_BOOLEAN);
+ out.writeByte(TYPE_BOOLEAN);
long longVal = bVal.booleanValue() ? 1L : 0L;
- LittleEndian.putLong(data, offset+1, longVal);
- return 9;
+ out.writeLong(longVal);
+ return;
}
if (value instanceof Double) {
Double dVal = (Double) value;
- LittleEndian.putByte(data, offset, TYPE_NUMBER);
- LittleEndian.putDouble(data, offset+1, dVal.doubleValue());
- return 9;
+ out.writeByte(TYPE_NUMBER);
+ out.writeDouble(dVal.doubleValue());
+ return;
}
if (value instanceof UnicodeString) {
UnicodeString usVal = (UnicodeString) value;
- LittleEndian.putByte(data, offset, TYPE_STRING);
- UnicodeRecordStats urs = new UnicodeRecordStats();
- usVal.serialize(urs, offset +1, data);
- return 1 + urs.recordSize;
+ out.writeByte(TYPE_STRING);
+ StringUtil.writeUnicodeString(out, usVal.getString());
+ return;
}
if (value instanceof ErrorConstant) {
ErrorConstant ecVal = (ErrorConstant) value;
- LittleEndian.putByte(data, offset, TYPE_ERROR_CODE);
- LittleEndian.putUShort(data, offset+1, ecVal.getErrorCode());
- LittleEndian.putUShort(data, offset+3, 0);
- LittleEndian.putInt(data, offset+5, 0);
- return 9;
+ out.writeByte(TYPE_ERROR_CODE);
+ long longVal = ecVal.getErrorCode();
+ out.writeLong(longVal);
+ return;
}
throw new IllegalStateException("Unexpected value type (" + value.getClass().getName() + "'");
diff --git a/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java b/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java
index 5bee0afe03..7802fcd13f 100644
--- a/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java
+++ b/src/java/org/apache/poi/hssf/record/formula/Area2DPtgBase.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -30,7 +30,7 @@ public abstract class Area2DPtgBase extends AreaPtgBase {
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
}
- protected Area2DPtgBase(RecordInputStream in) {
+ protected Area2DPtgBase(LittleEndianInput in) {
readCoordinates(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
index e5c2fdc10d..675ee45551 100644
--- a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -44,7 +44,7 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor
setExternSheetIndex( externIdx );
}
- public Area3DPtg(RecordInputStream in) {
+ public Area3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort();
readCoordinates(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
index f50af0d0cf..dfbfb7ab32 100644
--- a/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -36,7 +36,7 @@ public final class AreaErrPtg extends OperandPtg {
unused2 = 0;
}
- public AreaErrPtg(RecordInputStream in) {
+ public AreaErrPtg(LittleEndianInput in) {
// 8 bytes unused:
unused1 = in.readInt();
unused2 = in.readInt();
diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java
index fc391b801d..f8b761f315 100644
--- a/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
public final class AreaNPtg extends Area2DPtgBase {
public final static short sid = 0x2D;
- public AreaNPtg(RecordInputStream in) {
+ public AreaNPtg(LittleEndianInput in) {
super(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
index 77e9fa0b5e..1da9b784c8 100755
--- a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* Specifies a rectangular area of cells A1:A4 for instance.
@@ -29,7 +29,7 @@ public final class AreaPtg extends Area2DPtgBase {
public AreaPtg(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);
}
- public AreaPtg(RecordInputStream in) {
+ public AreaPtg(LittleEndianInput in) {
super(in);
}
public AreaPtg(String arearef) {
diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java b/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
index 2fa1290c0c..8e338c587a 100644
--- a/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -113,7 +113,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI {
}
}
- protected final void readCoordinates(RecordInputStream in) {
+ protected final void readCoordinates(LittleEndianInput in) {
field_1_first_row = in.readUShort();
field_2_last_row = in.readUShort();
field_3_first_column = in.readUShort();
diff --git a/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java b/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
index 21df3982a2..3fcc23eda0 100644
--- a/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
@@ -17,11 +17,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -55,7 +54,7 @@ public final class ArrayPtg extends Ptg {
private short token_2_rows;
private Object[] token_3_arrayValues;
- public ArrayPtg(RecordInputStream in) {
+ public ArrayPtg(LittleEndianInput in) {
field_1_reserved = new byte[RESERVED_FIELD_LEN];
// TODO - add readFully method to RecordInputStream
for(int i=0; i< RESERVED_FIELD_LEN; i++) {
@@ -109,7 +108,7 @@ public final class ArrayPtg extends Ptg {
* AFTER the last Ptg in the expression.
* See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
*/
- public void readTokenValues(RecordInputStream in) {
+ public void readTokenValues(LittleEndianInput in) {
int nColumns = in.readUByte();
short nRows = in.readShort();
//The token_1_columns and token_2_rows do not follow the documentation.
@@ -133,7 +132,7 @@ public final class ArrayPtg extends Ptg {
if (token_3_arrayValues == null) {
sb.append(" #values#uninitialised#\n");
} else {
- sb.append(" ").append(formatAsString());
+ sb.append(" ").append(toFormulaString());
}
return sb.toString();
}
@@ -159,11 +158,11 @@ public final class ArrayPtg extends Ptg {
out.write(field_1_reserved);
}
- public int writeTokenValueBytes(byte[] data, int offset) {
+ public int writeTokenValueBytes(LittleEndianOutput out) {
- LittleEndian.putByte(data, offset + 0, token_1_columns-1);
- LittleEndian.putUShort(data, offset + 1, token_2_rows-1);
- ConstantValueParser.encode(data, offset + 3, token_3_arrayValues);
+ out.writeByte(token_1_columns-1);
+ out.writeShort(token_2_rows-1);
+ ConstantValueParser.encode(out, token_3_arrayValues);
return 3 + ConstantValueParser.getEncodedSize(token_3_arrayValues);
}
@@ -183,7 +182,7 @@ public final class ArrayPtg extends Ptg {
+ ConstantValueParser.getEncodedSize(token_3_arrayValues);
}
- public String formatAsString() { // TODO - fold into toFormulaString
+ public String toFormulaString() {
StringBuffer b = new StringBuffer();
b.append("{");
for (int y=0;y<getRowCount();y++) {
@@ -201,9 +200,6 @@ public final class ArrayPtg extends Ptg {
b.append("}");
return b.toString();
}
- public String toFormulaString() {
- return formatAsString();
- }
private static String getConstantText(Object o) {
diff --git a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
index 51d3194c0b..7a256bf2f7 100644
--- a/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -79,7 +79,7 @@ public final class AttrPtg extends ControlPtg {
_chooseFuncOffset = -1;
}
- public AttrPtg(RecordInputStream in)
+ public AttrPtg(LittleEndianInput in)
{
field_1_options = in.readByte();
field_2_data = in.readShort();
diff --git a/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java b/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
index 8dfbca33fa..88604ac50d 100644
--- a/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/BoolPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -32,7 +32,7 @@ public final class BoolPtg extends ScalarConstantPtg {
public final static byte sid = 0x1D;
private final boolean _value;
- public BoolPtg(RecordInputStream in) {
+ public BoolPtg(LittleEndianInput in) {
_value = (in.readByte() == 1);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
index 9aa07dddfc..0cf412d859 100644
--- a/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -42,7 +42,7 @@ public final class DeletedArea3DPtg extends OperandPtg implements WorkbookDepend
unused2 = 0;
}
- public DeletedArea3DPtg(RecordInputStream in) {
+ public DeletedArea3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readUShort();
unused1 = in.readInt();
unused2 = in.readInt();
diff --git a/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
index 90ac7efac7..dcc07ab6d9 100644
--- a/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
@@ -18,10 +18,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -37,7 +37,7 @@ public final class DeletedRef3DPtg extends OperandPtg implements WorkbookDepende
private final int unused1;
/** Creates new DeletedRef3DPtg */
- public DeletedRef3DPtg(RecordInputStream in) {
+ public DeletedRef3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readUShort();
unused1 = in.readInt();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java b/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
index f2720e52d8..361e4b5cf9 100644
--- a/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -58,7 +58,7 @@ public final class ErrPtg extends ScalarConstantPtg {
field_1_error_code = errorCode;
}
- public static ErrPtg read(RecordInputStream in) {
+ public static ErrPtg read(LittleEndianInput in) {
return valueOf(in.readByte());
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java b/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
index 9a75a627bf..665fa97c83 100644
--- a/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/ExpPtg.java
@@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.RecordFormatException;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -33,7 +33,7 @@ public final class ExpPtg extends ControlPtg {
private final short field_1_first_row;
private final short field_2_first_col;
- public ExpPtg(RecordInputStream in)
+ public ExpPtg(LittleEndianInput in)
{
field_1_first_row = in.readShort();
field_2_first_col = in.readShort();
diff --git a/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java b/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
index 3265f88b1d..133072203b 100644
--- a/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
@@ -16,9 +16,9 @@
==================================================================== */
package org.apache.poi.hssf.record.formula;
-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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -35,7 +35,7 @@ public final class FuncPtg extends AbstractFunctionPtg {
/**Creates new function pointer from a byte array
* usually called while reading an excel file.
*/
- public FuncPtg(RecordInputStream in) {
+ public FuncPtg(LittleEndianInput in) {
//field_1_num_args = data[ offset + 0 ];
field_2_fnc_index = in.readShort();
diff --git a/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java b/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java
index 6a6ccda8ae..1deb630d50 100644
--- a/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/FuncVarPtg.java
@@ -16,9 +16,9 @@
==================================================================== */
package org.apache.poi.hssf.record.formula;
-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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -33,7 +33,7 @@ public final class FuncVarPtg extends AbstractFunctionPtg{
/**Creates new function pointer from a byte array
* usually called while reading an excel file.
*/
- public FuncVarPtg(RecordInputStream in) {
+ public FuncVarPtg(LittleEndianInput in) {
field_1_num_args = in.readByte();
field_2_fnc_index = in.readShort();
FunctionMetadata fm = FunctionMetadataRegistry.getFunctionByIndex(field_2_fnc_index);
diff --git a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
index 4df6d6f22f..bb5d36f007 100644
--- a/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -46,7 +46,7 @@ public final class IntPtg extends ScalarConstantPtg {
public final static byte sid = 0x1e;
private final int field_1_value;
- public IntPtg(RecordInputStream in) {
+ public IntPtg(LittleEndianInput in) {
this(in.readUShort());
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java b/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
index 9e9c090510..58a836e28f 100644
--- a/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -36,7 +36,7 @@ public class MemAreaPtg extends OperandPtg {
field_2_subex_len = subexLen;
}
- public MemAreaPtg(RecordInputStream in) {
+ public MemAreaPtg(LittleEndianInput in) {
field_1_reserved = in.readInt();
field_2_subex_len = in.readShort();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java b/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
index dc87ec2734..91027b0ab0 100644
--- a/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -32,7 +32,7 @@ public final class MemErrPtg extends OperandPtg {
private int field_1_reserved;
private short field_2_subex_len;
- public MemErrPtg(RecordInputStream in) {
+ public MemErrPtg(LittleEndianInput in) {
field_1_reserved = in.readInt();
field_2_subex_len = in.readShort();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java b/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
index 98557263c0..3ee893bdd7 100644
--- a/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -32,7 +32,7 @@ public final class MemFuncPtg extends OperandPtg {
* Creates new function pointer from a byte array usually called while
* reading an excel file.
*/
- public MemFuncPtg(RecordInputStream in) {
+ public MemFuncPtg(LittleEndianInput in) {
this(in.readUShort());
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/NamePtg.java b/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
index e44369d72d..e5cd0fc9de 100644
--- a/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -43,7 +43,7 @@ public final class NamePtg extends OperandPtg implements WorkbookDependentFormul
/** Creates new NamePtg */
- public NamePtg(RecordInputStream in) {
+ public NamePtg(LittleEndianInput in) {
field_1_label_index = in.readShort();
field_2_zero = in.readShort();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java b/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
index bf8ea13561..de08763c73 100644
--- a/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -51,7 +51,7 @@ public final class NameXPtg extends OperandPtg implements WorkbookDependentFormu
this(sheetRefIndex, nameIndex + 1, 0);
}
- public NameXPtg(RecordInputStream in) {
+ public NameXPtg(LittleEndianInput in) {
this(in.readUShort(), in.readUShort(), in.readUShort());
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java b/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
index 52779e0641..5bd8b08453 100644
--- a/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/NumberPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -32,7 +32,7 @@ public final class NumberPtg extends ScalarConstantPtg {
public final static byte sid = 0x1f;
private final double field_1_value;
- public NumberPtg(RecordInputStream in) {
+ public NumberPtg(LittleEndianInput in) {
this(in.readDouble());
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/Ptg.java b/src/java/org/apache/poi/hssf/record/formula/Ptg.java
index a1a826dbbf..771cccf582 100644
--- a/src/java/org/apache/poi/hssf/record/formula/Ptg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/Ptg.java
@@ -20,8 +20,8 @@ package org.apache.poi.hssf.record.formula;
import java.util.ArrayList;
import java.util.List;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -48,12 +48,12 @@ public abstract class Ptg implements Cloneable {
* Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
* Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
*/
- public static Ptg[] readTokens(int size, RecordInputStream in) {
+ public static Ptg[] readTokens(int size, LittleEndianInput in) {
List temp = new ArrayList(4 + size / 2);
int pos = 0;
List arrayPtgs = null;
while (pos < size) {
- Ptg ptg = Ptg.createPtg( in );
+ Ptg ptg = Ptg.createPtg(in);
if (ptg instanceof ArrayPtg) {
if (arrayPtgs == null) {
arrayPtgs = new ArrayList(5);
@@ -77,7 +77,7 @@ public abstract class Ptg implements Cloneable {
return toPtgArray(temp);
}
- public static Ptg createPtg(RecordInputStream in) {
+ public static Ptg createPtg(LittleEndianInput in) {
byte id = in.readByte();
if (id < 0x20) {
@@ -97,7 +97,7 @@ public abstract class Ptg implements Cloneable {
return retval;
}
- private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
+ private static Ptg createClassifiedPtg(byte id, LittleEndianInput in) {
int baseId = id & 0x1F | 0x20;
@@ -126,7 +126,7 @@ public abstract class Ptg implements Cloneable {
Integer.toHexString(id) + " (" + ( int ) id + ")");
}
- private static Ptg createBasePtg(byte id, RecordInputStream in) {
+ private static Ptg createBasePtg(byte id, LittleEndianInput in) {
switch(id) {
case 0x00: return new UnknownPtg(id); // TODO - not a real Ptg
case ExpPtg.sid: return new ExpPtg(in); // 0x01
@@ -228,10 +228,9 @@ public abstract class Ptg implements Cloneable {
* @return number of bytes written
*/
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
- int pos = 0;
int nTokens = ptgs.length;
- LittleEndianOutput out = new LittleEndianByteArrayOutputStream(array, offset);
+ LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset);
List arrayPtgs = null;
@@ -244,18 +243,15 @@ public abstract class Ptg implements Cloneable {
arrayPtgs = new ArrayList(5);
}
arrayPtgs.add(ptg);
- pos += ArrayPtg.PLAIN_TOKEN_SIZE;
- } else {
- pos += ptg.getSize();
}
}
if (arrayPtgs != null) {
for (int i=0;i<arrayPtgs.size();i++) {
ArrayPtg p = (ArrayPtg)arrayPtgs.get(i);
- pos += p.writeTokenValueBytes(array, pos + offset);
+ p.writeTokenValueBytes(out);
}
}
- return pos;
+ return out.getWriteIndex() - offset;
}
/**
diff --git a/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java b/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java
index f2fcd504c7..3e52bc2081 100644
--- a/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java
+++ b/src/java/org/apache/poi/hssf/record/formula/Ref2DPtgBase.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -41,7 +41,7 @@ abstract class Ref2DPtgBase extends RefPtgBase {
setColRelative(isColumnRelative);
}
- protected Ref2DPtgBase(RecordInputStream in) {
+ protected Ref2DPtgBase(LittleEndianInput in) {
readCoordinates(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
index ff86b8c3c8..09b6725a87 100644
--- a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
@@ -17,11 +17,11 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -41,7 +41,7 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu
/** Creates new AreaPtg */
public Ref3DPtg() {}
- public Ref3DPtg(RecordInputStream in) {
+ public Ref3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort();
readCoordinates(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java b/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
index 3cf9b340bf..4cbd501053 100755
--- a/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/RefErrorPtg.java
@@ -17,8 +17,8 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -34,7 +34,7 @@ public final class RefErrorPtg extends OperandPtg {
public RefErrorPtg() {
field_1_reserved = 0;
}
- public RefErrorPtg(RecordInputStream in) {
+ public RefErrorPtg(LittleEndianInput in) {
field_1_reserved = in.readInt();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java b/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
index 07114265d0..3a8148c46c 100644
--- a/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* RefNPtg
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
public final class RefNPtg extends Ref2DPtgBase {
public final static byte sid = 0x2C;
- public RefNPtg(RecordInputStream in) {
+ public RefNPtg(LittleEndianInput in) {
super(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/RefPtg.java b/src/java/org/apache/poi/hssf/record/formula/RefPtg.java
index 94a1b3301c..69508fd7d2 100644
--- a/src/java/org/apache/poi/hssf/record/formula/RefPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/RefPtg.java
@@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* ReferencePtg - handles references (such as A1, A2, IA4)
@@ -39,7 +39,7 @@ public final class RefPtg extends Ref2DPtgBase {
super(row, column, isRowRelative, isColumnRelative);
}
- public RefPtg(RecordInputStream in) {
+ public RefPtg(LittleEndianInput in) {
super(in);
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java b/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java
index d623324a37..8357e158c5 100644
--- a/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java
+++ b/src/java/org/apache/poi/hssf/record/formula/RefPtgBase.java
@@ -17,10 +17,10 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -67,7 +67,7 @@ public abstract class RefPtgBase extends OperandPtg {
setColRelative(isColumnRelative);
}
- protected final void readCoordinates(RecordInputStream in) {
+ protected final void readCoordinates(LittleEndianInput in) {
field_1_row = in.readUShort();
field_2_col = in.readUShort();
}
diff --git a/src/java/org/apache/poi/hssf/record/formula/StringPtg.java b/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
index cd6749e5bc..59a5521cc2 100644
--- a/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/StringPtg.java
@@ -17,9 +17,9 @@
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
import org.apache.poi.util.StringUtil;
@@ -47,7 +47,7 @@ public final class StringPtg extends ScalarConstantPtg {
private final String field_3_string;
/** Create a StringPtg from a stream */
- public StringPtg(RecordInputStream in) {
+ public StringPtg(LittleEndianInput in) {
field_1_length = in.readUByte();
field_2_options = in.readByte();
if (fHighByte.isSet(field_2_options)) {
diff --git a/src/java/org/apache/poi/hssf/record/formula/TblPtg.java b/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
index c62783a3a0..280bd9c010 100644
--- a/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
+++ b/src/java/org/apache/poi/hssf/record/formula/TblPtg.java
@@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.record.RecordFormatException;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
/**
@@ -43,7 +43,7 @@ public final class TblPtg extends ControlPtg {
/** The column number of the upper left corner */
private final int field_2_first_col;
- public TblPtg(RecordInputStream in) {
+ public TblPtg(LittleEndianInput in) {
field_1_first_row = in.readUShort();
field_2_first_col = in.readUShort();
}
diff --git a/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java b/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
index 598a9cbdbc..b77407c7a9 100644
--- a/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
+++ b/src/java/org/apache/poi/util/LittleEndianByteArrayOutputStream.java
@@ -81,4 +81,7 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
System.arraycopy(b, 0, _buf, _writeIndex, len);
_writeIndex += len;
}
+ public int getWriteIndex() {
+ return _writeIndex;
+ }
}
diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java
index e78e9b40e9..8a57d2340b 100644
--- a/src/java/org/apache/poi/util/StringUtil.java
+++ b/src/java/org/apache/poi/util/StringUtil.java
@@ -140,6 +140,27 @@ public class StringUtil {
}
return readUnicodeLE(in, nChars);
}
+ /**
+ * OutputStream <tt>out</tt> will get:
+ * <ol>
+ * <li>ushort nChars</li>
+ * <li>byte is16BitFlag</li>
+ * <li>byte[]/char[] characterData</li>
+ * </ol>
+ * For this encoding, the is16BitFlag is always present even if nChars==0.
+ */
+ public static void writeUnicodeString(LittleEndianOutput out, String value) {
+
+ int nChars = value.length();
+ out.writeShort(nChars);
+ boolean is16Bit = hasMultibyte(value);
+ out.writeByte(is16Bit ? 0x01 : 0x00);
+ if (is16Bit) {
+ putUnicodeLE(value, out);
+ } else {
+ putCompressedUnicode(value, out);
+ }
+ }
/**
* Takes a unicode (java) string, and returns it as 8 bit data (in ISO-8859-1
diff --git a/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java b/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
index 17a0901040..6e1a06ac53 100644
--- a/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
+++ b/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
@@ -26,6 +26,7 @@ import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
/**
*
* @author Josh Micich
@@ -52,7 +53,8 @@ public final class TestConstantValueParser extends TestCase {
public void testEncode() {
int size = ConstantValueParser.getEncodedSize(SAMPLE_VALUES);
byte[] data = new byte[size];
- ConstantValueParser.encode(data, 0, SAMPLE_VALUES);
+
+ ConstantValueParser.encode(new LittleEndianByteArrayOutputStream(data, 0), SAMPLE_VALUES);
if (!Arrays.equals(data, SAMPLE_ENCODING)) {
fail("Encoding differs");
diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
index 8d2fe631d2..16ec4444fa 100644
--- a/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
+++ b/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
@@ -24,6 +24,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
@@ -70,7 +71,7 @@ public final class TestArrayPtg extends TestCase {
assertEquals(new UnicodeString("FG"), values[1][2]);
byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
- ptg.writeTokenValueBytes(outBuf, 0);
+ ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));
if(outBuf[0] == 4) {
throw new AssertionFailedError("Identified bug 42564b");