/** * get an unsigned int value from a byte array * * @param data * the byte array * @return the unsigned int (32-bit) value in a long */ public static long getUInt( byte[] data ) { return getUInt( data, 0 ); }
/** * Parses an RfX cell range from the data starting at the offset. * This performs no range checking. * @param data raw bytes * @param offset offset at which to start reading from data * @param cellRange to overwrite. If null, a new cellRange will be created. * @return a mutable cell range. */ public static XSSFBCellRange parse(byte[] data, int offset, XSSFBCellRange cellRange) { if (cellRange == null) { cellRange = new XSSFBCellRange(); } cellRange.firstRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; cellRange.lastRow = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; cellRange.firstCol = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; cellRange.lastCol = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); return cellRange; }
private void tryToAddWorksheet(byte[] data) throws XSSFBParseException { int offset = 0; //this is the sheet state #2.5.142 /*long hsShtat =*/ //noinspection ResultOfMethodCallIgnored LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; //according to #2.4.304 if (iTabID < 1 || iTabID > 0x0000FFFFL) { throw new XSSFBParseException("table id out of range: "+iTabID); } StringBuilder sb = new StringBuilder(); offset += XSSFBUtils.readXLWideString(data, offset, sb); String relId = sb.toString(); sb.setLength(0); /*offset +=*/ XSSFBUtils.readXLWideString(data, offset, sb); String name = sb.toString(); if (relId.trim().length() > 0) { sheets.add(new XSSFSheetRef(relId, name)); } }
private boolean tryOldFormat(byte[] data) throws XSSFBParseException { //undocumented what is contained in these 8 bytes. //for the non-beta xlsb files, this would be 4, not 8. int offset = 8; long iTabID = LittleEndian.getUInt(data, offset); offset += LittleEndian.INT_SIZE; if (iTabID < 1 || iTabID > 0x0000FFFFL) { throw new XSSFBParseException("table id out of range: "+iTabID); } StringBuilder sb = new StringBuilder(); offset += XSSFBUtils.readXLWideString(data, offset, sb); String relId = sb.toString(); sb.setLength(0); offset += XSSFBUtils.readXLWideString(data, offset, sb); String name = sb.toString(); if (relId.trim().length() > 0) { sheets.add(new XSSFSheetRef(relId, name)); } if (offset == data.length) { return true; } return false; }
@Override public void handleRecord(int recordType, byte[] data) throws XSSFBParseException { XSSFBRecordType type = XSSFBRecordType.lookup(recordType); switch (type) { case BrtSstItem: XSSFBRichStr rstr = XSSFBRichStr.build(data, 0); strings.add(rstr.getString()); break; case BrtBeginSst: count = XSSFBUtils.castToInt(LittleEndian.getUInt(data,0)); uniqueCount = XSSFBUtils.castToInt(LittleEndian.getUInt(data, 4)); break; } } }
return Integer.toString( LittleEndian.getUShort(b) ); case 4: return Long.toString( LittleEndian.getUInt(b) ); default:
/** * Reads an XLNullableWideString. * @param data data from which to read * @param offset in data from which to start * @param sb buffer to which to write. You must setLength(0) before calling! * @return number of bytes read * @throws XSSFBParseException if there was an exception while trying to read the string */ public static int readXLWideString(byte[] data, int offset, StringBuilder sb) throws XSSFBParseException { long numChars = LittleEndian.getUInt(data, offset); if (numChars < 0) { throw new XSSFBParseException("too few chars to read"); } else if (numChars > 0xFFFFFFFFL) { throw new XSSFBParseException("too many chars to read"); } int numBytes = 2*(int)numChars; offset += 4; if (offset+numBytes > data.length) { throw new XSSFBParseException("trying to read beyond data length"); } sb.append(new String(data, offset, numBytes, StandardCharsets.UTF_16LE)); numBytes+=4; return numBytes; }
/** * Reads an XLNullableWideString. * @param data data from which to read * @param offset in data from which to start * @param sb buffer to which to write. You must setLength(0) before calling! * @return number of bytes read * @throws XSSFBParseException if there was an exception during reading */ static int readXLNullableWideString(byte[] data, int offset, StringBuilder sb) throws XSSFBParseException { long numChars = LittleEndian.getUInt(data, offset); if (numChars < 0) { throw new XSSFBParseException("too few chars to read"); } else if (numChars == 0xFFFFFFFFL) { //this means null value (2.5.166), do not read any bytes!!! return 0; } else if (numChars > 0xFFFFFFFFL) { throw new XSSFBParseException("too many chars to read"); } int numBytes = 2*(int)numChars; offset += 4; if (offset+numBytes > data.length) { throw new XSSFBParseException("trying to read beyond data length: " + "offset="+offset+", numBytes="+numBytes+", data.length="+data.length); } sb.append(new String(data, offset, numBytes, StandardCharsets.UTF_16LE)); numBytes+=4; return numBytes; }
/** * * @param data raw data * @param offset offset at which to start reading the record * @param currentRow 0-based current row count * @param cell cell buffer to update */ public static void parse(byte[] data, int offset, int currentRow, XSSFBCellHeader cell) { int colNum = XSSFBUtils.castToInt(LittleEndian.getUInt(data, offset)); offset += LittleEndian.INT_SIZE; int styleIdx = XSSFBUtils.get24BitInt(data, offset); offset += 3; //TODO: range checking boolean showPhonetic = false;//TODO: fill this out cell.reset(currentRow, colNum, styleIdx, showPhonetic); }
public ImageHeaderEMF(final byte data[], final int off) { int offset = off; int type = (int)LittleEndian.getUInt(data, offset); offset += 4; if (type != 1) { LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type"); deviceBounds = new Rectangle(0,0,200,200); return; } // ignore header size offset += 4; int left = LittleEndian.getInt(data, offset); offset += 4; int top = LittleEndian.getInt(data, offset); offset += 4; int right = LittleEndian.getInt(data, offset); offset += 4; int bottom = LittleEndian.getInt(data, offset); offset += 4; deviceBounds = new Rectangle(left, top, right-left, bottom-top); // ignore frame bounds offset += 16; String signature = new String(data, offset, EMF_SIGNATURE.length(), LocaleUtil.CHARSET_1252); if (!EMF_SIGNATURE.equals(signature)) { LOG.log(POILogger.WARN, "Invalid EMF picture - invalid signature"); } }
type = LittleEndian.getUInt(src, o); o += LittleEndianConsts.INT_SIZE;
@Override public void handleRecord(int id, byte[] data) throws XSSFBParseException { XSSFBRecordType recordType = XSSFBRecordType.lookup(id); switch (recordType) { case BrtBeginComment: int offset = 0; authorId = XSSFBUtils.castToInt(LittleEndian.getUInt(data)); offset += LittleEndian.INT_SIZE; cellRange = XSSFBCellRange.parse(data, offset, cellRange); offset+= XSSFBCellRange.length; //for strict parsing; confirm that firstRow==lastRow and firstCol==colLats (2.4.28) cellAddress = new CellAddress(cellRange.firstRow, cellRange.firstCol); break; case BrtCommentText: XSSFBRichStr xssfbRichStr = XSSFBRichStr.build(data, 0); comment = xssfbRichStr.getString(); break; case BrtEndComment: comments.put(cellAddress, new XSSFBComment(cellAddress, authors.get(authorId), comment)); authorId = -1; cellAddress = null; break; case BrtCommentAuthor: authorBuffer.setLength(0); XSSFBUtils.readXLWideString(data, 0, authorBuffer); authors.add(authorBuffer.toString()); break; } }
private void handleBrtCellIsst(byte[] data) { beforeCellValue(data); int idx = XSSFBUtils.castToInt(LittleEndian.getUInt(data, XSSFBCellHeader.length)); RichTextString rtss = stringsTable.getItemAt(idx); handleCellValue(rtss.getString()); }
format = LittleEndian.getUShort(src, o); o += LittleEndianConsts.SHORT_SIZE; osVersion = (int) LittleEndian.getUInt(src, o); o += LittleEndianConsts.INT_SIZE; classID = new ClassID(src, o);
int offFix = (int)LittleEndian.getUInt(src, offset + ClassID.LENGTH);
int rw = XSSFBUtils.castToInt(LittleEndian.getUInt(data, 0)); if (rw > 0x00100000) {//could make sure this is larger than currentRow, according to spec? throw new XSSFBParseException("Row number beyond allowable range: "+rw);
/** * Gets the object ID seed, which will be used as the unique * OLE identifier for the next OLE object added * @return the object ID seed */ public long getObjectIDSeed() { return LittleEndian.getUInt(_data,0); }
@Override public void init(byte[] dataBytes, int recordId, int flags) throws IOException { //assert record id == header this.flags = flags; int offset = 0; this.version = LittleEndian.getUInt(dataBytes, offset); offset += LittleEndian.INT_SIZE; this.emfPlusFlags = LittleEndian.getUInt(dataBytes, offset); offset += LittleEndian.INT_SIZE; this.logicalDpiX = LittleEndian.getUInt(dataBytes, offset); offset += LittleEndian.INT_SIZE; this.logicalDpiY = LittleEndian.getUInt(dataBytes, offset); }
/** * get an unsigned int value from a byte array * * @param data * the byte array * @return the unsigned int (32-bit) value in a long */ public static long getUInt( byte[] data ) { return getUInt( data, 0 ); }
private void handleBrtCellIsst(byte[] data) { beforeCellValue(data); int idx = XSSFBUtils.castToInt(LittleEndian.getUInt(data, XSSFBCellHeader.length)); RichTextString rtss = stringsTable.getItemAt(idx); handleCellValue(rtss.getString()); }