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;
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);
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() {
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.
// 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);
return result;
}
- private static Object readAConstantValue(RecordInputStream in) {
+ private static Object readAConstantValue(LittleEndianInput in) {
byte grbit = in.readByte();
switch(grbit) {
case TYPE_EMPTY:
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:
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:
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() + "'");
\r
package org.apache.poi.hssf.record.formula;\r
\r
-import org.apache.poi.hssf.record.RecordInputStream;\r
+import org.apache.poi.util.LittleEndianInput;\r
import org.apache.poi.util.LittleEndianOutput;\r
\r
/**\r
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);\r
}\r
\r
- protected Area2DPtgBase(RecordInputStream in) {\r
+ protected Area2DPtgBase(LittleEndianInput in) {\r
readCoordinates(in);\r
}\r
\r
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;
/**
setExternSheetIndex( externIdx );
}
- public Area3DPtg(RecordInputStream in) {
+ public Area3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort();
readCoordinates(in);
}
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;
/**
unused2 = 0;
}
- public AreaErrPtg(RecordInputStream in) {
+ public AreaErrPtg(LittleEndianInput in) {
// 8 bytes unused:
unused1 = in.readInt();
unused2 = in.readInt();
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.
public final class AreaNPtg extends Area2DPtgBase {
public final static short sid = 0x2D;
- public AreaNPtg(RecordInputStream in) {
+ public AreaNPtg(LittleEndianInput in) {
super(in);
}
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.
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) {
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;
/**
}
}
- 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();
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;
/**
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++) {
* 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.
if (token_3_arrayValues == null) {
sb.append(" #values#uninitialised#\n");
} else {
- sb.append(" ").append(formatAsString());
+ sb.append(" ").append(toFormulaString());
}
return sb.toString();
}
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);
}
+ 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++) {
b.append("}");
return b.toString();
}
- public String toFormulaString() {
- return formatAsString();
- }
private static String getConstantText(Object o) {
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;
/**
_chooseFuncOffset = -1;
}
- public AttrPtg(RecordInputStream in)
+ public AttrPtg(LittleEndianInput in)
{
field_1_options = in.readByte();
field_2_data = in.readShort();
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;
/**
public final static byte sid = 0x1D;
private final boolean _value;
- public BoolPtg(RecordInputStream in) {
+ public BoolPtg(LittleEndianInput in) {
_value = (in.readByte() == 1);
}
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;
/**
unused2 = 0;
}
- public DeletedArea3DPtg(RecordInputStream in) {
+ public DeletedArea3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readUShort();
unused1 = in.readInt();
unused2 = in.readInt();
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;
/**
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();
}
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;
/**
field_1_error_code = errorCode;
}
- public static ErrPtg read(RecordInputStream in) {
+ public static ErrPtg read(LittleEndianInput in) {
return valueOf(in.readByte());
}
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;
/**
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();
==================================================================== */
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;
/**
/**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();
==================================================================== */
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;
/**
/**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);
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;
/**
public final static byte sid = 0x1e;
private final int field_1_value;
- public IntPtg(RecordInputStream in) {
+ public IntPtg(LittleEndianInput in) {
this(in.readUShort());
}
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;
/**
field_2_subex_len = subexLen;
}
- public MemAreaPtg(RecordInputStream in) {
+ public MemAreaPtg(LittleEndianInput in) {
field_1_reserved = in.readInt();
field_2_subex_len = in.readShort();
}
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;
/**
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();
}
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;
/**
* 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());
}
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;
/**
/** Creates new NamePtg */
- public NamePtg(RecordInputStream in) {
+ public NamePtg(LittleEndianInput in) {
field_1_label_index = in.readShort();
field_2_zero = in.readShort();
}
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;
/**
this(sheetRefIndex, nameIndex + 1, 0);
}
- public NameXPtg(RecordInputStream in) {
+ public NameXPtg(LittleEndianInput in) {
this(in.readUShort(), in.readUShort(), in.readUShort());
}
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;
/**
public final static byte sid = 0x1f;
private final double field_1_value;
- public NumberPtg(RecordInputStream in) {
+ public NumberPtg(LittleEndianInput in) {
this(in.readDouble());
}
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;
/**
* 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);
return toPtgArray(temp);
}
- public static Ptg createPtg(RecordInputStream in) {
+ public static Ptg createPtg(LittleEndianInput in) {
byte id = in.readByte();
if (id < 0x20) {
return retval;
}
- private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
+ private static Ptg createClassifiedPtg(byte id, LittleEndianInput in) {
int baseId = id & 0x1F | 0x20;
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
* @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;
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;
}
/**
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;
/**
setColRelative(isColumnRelative);
}
- protected Ref2DPtgBase(RecordInputStream in) {
+ protected Ref2DPtgBase(LittleEndianInput in) {
readCoordinates(in);
}
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;
/**
/** Creates new AreaPtg */
public Ref3DPtg() {}
- public Ref3DPtg(RecordInputStream in) {
+ public Ref3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort();
readCoordinates(in);
}
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;
/**
public RefErrorPtg() {
field_1_reserved = 0;
}
- public RefErrorPtg(RecordInputStream in) {
+ public RefErrorPtg(LittleEndianInput in) {
field_1_reserved = in.readInt();
}
package org.apache.poi.hssf.record.formula;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* RefNPtg
public final class RefNPtg extends Ref2DPtgBase {
public final static byte sid = 0x2C;
- public RefNPtg(RecordInputStream in) {
+ public RefNPtg(LittleEndianInput in) {
super(in);
}
\r
package org.apache.poi.hssf.record.formula;\r
\r
-import org.apache.poi.hssf.record.RecordInputStream;\r
+import org.apache.poi.util.LittleEndianInput;\r
\r
/**\r
* ReferencePtg - handles references (such as A1, A2, IA4)\r
super(row, column, isRowRelative, isColumnRelative);\r
}\r
\r
- public RefPtg(RecordInputStream in) {\r
+ public RefPtg(LittleEndianInput in) {\r
super(in);\r
}\r
\r
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;
/**
setColRelative(isColumnRelative);
}
- protected final void readCoordinates(RecordInputStream in) {
+ protected final void readCoordinates(LittleEndianInput in) {
field_1_row = in.readUShort();
field_2_col = in.readUShort();
}
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;
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)) {
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;
/**
/** 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();
}
System.arraycopy(b, 0, _buf, _writeIndex, len);
_writeIndex += len;
}
+ public int getWriteIndex() {
+ return _writeIndex;
+ }
}
}
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
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
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");
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;
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");