private static RecordInputStream convertToInputStream(DrawingRecord r) { byte[] data = r.serialize(); RecordInputStream rinp = new RecordInputStream( new ByteArrayInputStream(data) ); rinp.nextRecord(); return rinp; }
/** * Reads all byte data for the current record, including any that overlaps * into any following continue records. * * @return all byte data for the current record * * @deprecated POI 2.0 Best to write a input stream that wraps this one * where there is special sub record that may overlap continue * records. */ @Deprecated public byte[] readAllContinuedRemainder() { ByteArrayOutputStream out = new ByteArrayOutputStream(2 * MAX_RECORD_DATA_SIZE); while (true) { byte[] b = readRemainder(); out.write(b, 0, b.length); if (!isContinueNext()) { break; } nextRecord(); } return out.toByteArray(); }
/** * Clone the current record, via a call to serialize * it, and another to create a new record from the * bytes. * May only be used for classes which don't have * internal counts / ids in them. For those which * do, a full model-aware cloning is needed, which * allocates new ids / counts as needed. * * @return the cloned current record */ public Record cloneViaReserialise() { // Do it via a re-serialization // It's a cheat, but it works... byte[] b = serialize(); RecordInputStream rinp = new RecordInputStream(new ByteArrayInputStream(b)); rinp.nextRecord(); Record[] r = RecordFactory.createRecord(rinp); if(r.length != 1) { throw new IllegalStateException("Re-serialised a record to clone it, but got " + r.length + " records back!"); } return r[0]; } }
private void checkRecordPosition(int requiredByteCount) { int nAvailable = remaining(); if (nAvailable >= requiredByteCount) { // all OK return; } if (nAvailable == 0 && isContinueNext()) { nextRecord(); return; } throw new RecordFormatException("Not enough data (" + nAvailable + ") to read requested (" + requiredByteCount +") bytes"); }
public ExtSSTRecord(RecordInputStream in) { _stringsPerBucket = in.readShort(); int nInfos = in.remaining() / InfoSubRecord.ENCODED_SIZE; ArrayList<InfoSubRecord> lst = new ArrayList<>(nInfos); while (in.available() > 0) { InfoSubRecord info = new InfoSubRecord(in); lst.add(info); if(in.available() == 0 && in.hasNextRecord() && in.getNextSid() == ContinueRecord.sid) { in.nextRecord(); } } _sstInfos = lst.toArray(new InfoSubRecord[lst.size()]); }
private void prepare() { if (! ris.hasNextRecord()) { throw new IllegalArgumentException("File contains no records!"); } ris.nextRecord(); // Work out what version we're dealing with int bofSid = ris.getSid(); switch (bofSid) { case BOFRecord.biff2_sid: biffVersion = 2; break; case BOFRecord.biff3_sid: biffVersion = 3; break; case BOFRecord.biff4_sid: biffVersion = 4; break; case BOFRecord.biff5_sid: biffVersion = 5; break; default: throw new IllegalArgumentException("File does not begin with a BOF, found sid of " + bofSid); } // Get the type BOFRecord bof = new BOFRecord(ris); fileType = bof.getType(); }
public StreamEncryptionInfo(RecordInputStream rs, List<Record> outputRecs) { Record rec; rs.nextRecord(); int recSize = 4 + rs.remaining(); rec = RecordFactory.createSingleRecord(rs); rs.nextRecord(); rec = RecordFactory.createSingleRecord(rs); recSize += rec.getRecordSize(); rs.nextRecord(); rec = RecordFactory.createSingleRecord(rs); recSize += rec.getRecordSize();
public void run() throws IOException { try (POIFSFileSystem fs = new POIFSFileSystem(new File(file), true); InputStream din = BiffViewer.getPOIFSInputStream(fs)) { RecordInputStream rinp = new RecordInputStream(din); while (rinp.hasNextRecord()) { int sid = rinp.getNextSid(); rinp.nextRecord(); int size = rinp.available(); Class<? extends Record> clz = RecordFactory.getRecordClass(sid); System.out.print( formatSID(sid) + " - " + formatSize(size) + " bytes" ); if (clz != null) { System.out.print(" \t"); System.out.print(clz.getName().replace("org.apache.poi.hssf.record.", "")); } System.out.println(); byte[] data = rinp.readRemainder(); if (data.length > 0) { System.out.print(" "); System.out.println(formatData(data)); } } } }
protected void readFully(byte[] buf, int off, int len, boolean isPlain) { int origLen = len; if (buf == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > buf.length - off) { throw new IndexOutOfBoundsException(); } while (len > 0) { int nextChunk = Math.min(available(),len); if (nextChunk == 0) { if (!hasNextRecord()) { throw new RecordFormatException("Can't read the remaining "+len+" bytes of the requested "+origLen+" bytes. No further record exists."); } else { nextRecord(); nextChunk = Math.min(available(),len); assert(nextChunk > 0); } } checkRecordPosition(nextChunk); if (isPlain) { _dataInput.readPlain(buf, off, nextChunk); } else { _dataInput.readFully(buf, off, nextChunk); } _currentDataOffset+=nextChunk; off += nextChunk; len -= nextChunk; } }
_recStream.nextRecord();
break; recStream.nextRecord(); if (recStream.getSid() == 0) { continue;
recStream.nextRecord();
throw new RecordFormatException("Odd number of bytes(" + remaining() + ") left behind"); nextRecord();
private static RecordInputStream convertToInputStream(DrawingRecord r) { byte[] data = r.serialize(); RecordInputStream rinp = new RecordInputStream( new ByteArrayInputStream(data) ); rinp.nextRecord(); return rinp; }
private static RecordInputStream convertToInputStream(DrawingRecord r) { byte[] data = r.serialize(); RecordInputStream rinp = new RecordInputStream( new ByteArrayInputStream(data) ); rinp.nextRecord(); return rinp; }
private static RecordInputStream convertToInputStream(DrawingRecord r) { byte[] data = r.serialize(); RecordInputStream rinp = new RecordInputStream( new ByteArrayInputStream(data) ); rinp.nextRecord(); return rinp; }
private void checkRecordPosition(int requiredByteCount) { int nAvailable = remaining(); if (nAvailable >= requiredByteCount) { // all OK return; } if (nAvailable == 0 && isContinueNext()) { nextRecord(); return; } throw new RecordFormatException("Not enough data (" + nAvailable + ") to read requested (" + requiredByteCount +") bytes"); }
private void checkRecordPosition(int requiredByteCount) { int nAvailable = remaining(); if (nAvailable >= requiredByteCount) { // all OK return; } if (nAvailable == 0 && isContinueNext()) { nextRecord(); return; } throw new RecordFormatException("Not enough data (" + nAvailable + ") to read requested (" + requiredByteCount +") bytes"); }
private void checkRecordPosition(int requiredByteCount) { int nAvailable = remaining(); if (nAvailable >= requiredByteCount) { // all OK return; } if (nAvailable == 0 && isContinueNext()) { nextRecord(); return; } throw new RecordFormatException("Not enough data (" + nAvailable + ") to read requested (" + requiredByteCount +") bytes"); }