mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
b4265b8903
commit
3b2241f86c
|
@ -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() {
|
||||
|
|
|
@ -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() + "'");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -81,4 +81,7 @@ public final class LittleEndianByteArrayOutputStream implements LittleEndianOutp
|
|||
System.arraycopy(b, 0, _buf, _writeIndex, len);
|
||||
_writeIndex += len;
|
||||
}
|
||||
public int getWriteIndex() {
|
||||
return _writeIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue