Search in sources :

Example 1 with RecordInputStream

use of org.apache.poi.hssf.record.RecordInputStream in project poi by apache.

the class BiffViewer method createRecords.

/**
     *  Create an array of records from an input stream
     *
     * @param is the InputStream from which the records will be obtained
     * @param ps the PrintWriter to output the record data
     * @param recListener the record listener to notify about read records
     * @param dumpInterpretedRecords if {@code true}, the read records will be written to the PrintWriter
     *
     * @return an array of Records created from the InputStream
     * @exception  org.apache.poi.util.RecordFormatException  on error processing the InputStream
     */
public static Record[] createRecords(InputStream is, PrintWriter ps, BiffRecordListener recListener, boolean dumpInterpretedRecords) throws org.apache.poi.util.RecordFormatException {
    List<Record> temp = new ArrayList<Record>();
    RecordInputStream recStream = new RecordInputStream(is);
    while (true) {
        boolean hasNext;
        try {
            hasNext = recStream.hasNextRecord();
        } catch (LeftoverDataException e) {
            logger.log(POILogger.ERROR, "Discarding " + recStream.remaining() + " bytes and continuing", e);
            recStream.readRemainder();
            hasNext = recStream.hasNextRecord();
        }
        if (!hasNext) {
            break;
        }
        recStream.nextRecord();
        if (recStream.getSid() == 0) {
            continue;
        }
        Record record;
        if (dumpInterpretedRecords) {
            record = createRecord(recStream);
            if (record.getSid() == ContinueRecord.sid) {
                continue;
            }
            temp.add(record);
            for (String header : recListener.getRecentHeaders()) {
                ps.println(header);
            }
            ps.print(record);
        } else {
            recStream.readRemainder();
        }
        ps.println();
    }
    Record[] result = new Record[temp.size()];
    temp.toArray(result);
    return result;
}
Also used : LeftoverDataException(org.apache.poi.hssf.record.RecordInputStream.LeftoverDataException) ArrayList(java.util.ArrayList) WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) DrawingSelectionRecord(org.apache.poi.hssf.record.DrawingSelectionRecord) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) DefaultColWidthRecord(org.apache.poi.hssf.record.DefaultColWidthRecord) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) FooterRecord(org.apache.poi.hssf.record.FooterRecord) DatRecord(org.apache.poi.hssf.record.chart.DatRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) ChartRecord(org.apache.poi.hssf.record.chart.ChartRecord) PageItemRecord(org.apache.poi.hssf.record.pivottable.PageItemRecord) TableStylesRecord(org.apache.poi.hssf.record.TableStylesRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) LegendRecord(org.apache.poi.hssf.record.chart.LegendRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) AreaRecord(org.apache.poi.hssf.record.chart.AreaRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) SeriesTextRecord(org.apache.poi.hssf.record.chart.SeriesTextRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) DefaultDataLabelTextPropertiesRecord(org.apache.poi.hssf.record.chart.DefaultDataLabelTextPropertiesRecord) PrintSetupRecord(org.apache.poi.hssf.record.PrintSetupRecord) Record(org.apache.poi.hssf.record.Record) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) PrintHeadersRecord(org.apache.poi.hssf.record.PrintHeadersRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) DBCellRecord(org.apache.poi.hssf.record.DBCellRecord) BeginRecord(org.apache.poi.hssf.record.chart.BeginRecord) TopMarginRecord(org.apache.poi.hssf.record.TopMarginRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) HorizontalPageBreakRecord(org.apache.poi.hssf.record.HorizontalPageBreakRecord) EndRecord(org.apache.poi.hssf.record.chart.EndRecord) CalcCountRecord(org.apache.poi.hssf.record.CalcCountRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) PlotGrowthRecord(org.apache.poi.hssf.record.chart.PlotGrowthRecord) UnitsRecord(org.apache.poi.hssf.record.chart.UnitsRecord) ObjectLinkRecord(org.apache.poi.hssf.record.chart.ObjectLinkRecord) HeaderRecord(org.apache.poi.hssf.record.HeaderRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) IterationRecord(org.apache.poi.hssf.record.IterationRecord) SeriesRecord(org.apache.poi.hssf.record.chart.SeriesRecord) ExtendedPivotTableViewFieldsRecord(org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord) FeatHdrRecord(org.apache.poi.hssf.record.FeatHdrRecord) LabelSSTRecord(org.apache.poi.hssf.record.LabelSSTRecord) RKRecord(org.apache.poi.hssf.record.RKRecord) CatLabRecord(org.apache.poi.hssf.record.chart.CatLabRecord) MulRKRecord(org.apache.poi.hssf.record.MulRKRecord) ChartEndBlockRecord(org.apache.poi.hssf.record.chart.ChartEndBlockRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) ViewSourceRecord(org.apache.poi.hssf.record.pivottable.ViewSourceRecord) DataFormatRecord(org.apache.poi.hssf.record.chart.DataFormatRecord) PaneRecord(org.apache.poi.hssf.record.PaneRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) NumberRecord(org.apache.poi.hssf.record.NumberRecord) FontBasisRecord(org.apache.poi.hssf.record.chart.FontBasisRecord) ChartStartBlockRecord(org.apache.poi.hssf.record.chart.ChartStartBlockRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) SeriesIndexRecord(org.apache.poi.hssf.record.chart.SeriesIndexRecord) DConRefRecord(org.apache.poi.hssf.record.DConRefRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) SheetPropertiesRecord(org.apache.poi.hssf.record.chart.SheetPropertiesRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) BottomMarginRecord(org.apache.poi.hssf.record.BottomMarginRecord) RightMarginRecord(org.apache.poi.hssf.record.RightMarginRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) StreamIDRecord(org.apache.poi.hssf.record.pivottable.StreamIDRecord) CFHeader12Record(org.apache.poi.hssf.record.CFHeader12Record) BlankRecord(org.apache.poi.hssf.record.BlankRecord) AutoFilterInfoRecord(org.apache.poi.hssf.record.AutoFilterInfoRecord) DVRecord(org.apache.poi.hssf.record.DVRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord) LeftMarginRecord(org.apache.poi.hssf.record.LeftMarginRecord) StringRecord(org.apache.poi.hssf.record.StringRecord) CFRuleRecord(org.apache.poi.hssf.record.CFRuleRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) VCenterRecord(org.apache.poi.hssf.record.VCenterRecord) AxisUsedRecord(org.apache.poi.hssf.record.chart.AxisUsedRecord) DefaultRowHeightRecord(org.apache.poi.hssf.record.DefaultRowHeightRecord) GridsetRecord(org.apache.poi.hssf.record.GridsetRecord) LinkedDataRecord(org.apache.poi.hssf.record.chart.LinkedDataRecord) VerticalPageBreakRecord(org.apache.poi.hssf.record.VerticalPageBreakRecord) ChartFRTInfoRecord(org.apache.poi.hssf.record.chart.ChartFRTInfoRecord) ValueRangeRecord(org.apache.poi.hssf.record.chart.ValueRangeRecord) ChartStartObjectRecord(org.apache.poi.hssf.record.chart.ChartStartObjectRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) ViewFieldsRecord(org.apache.poi.hssf.record.pivottable.ViewFieldsRecord) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) AxisParentRecord(org.apache.poi.hssf.record.chart.AxisParentRecord) BoolErrRecord(org.apache.poi.hssf.record.BoolErrRecord) SeriesToChartGroupRecord(org.apache.poi.hssf.record.chart.SeriesToChartGroupRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) CFRule12Record(org.apache.poi.hssf.record.CFRule12Record) AreaFormatRecord(org.apache.poi.hssf.record.chart.AreaFormatRecord) RefModeRecord(org.apache.poi.hssf.record.RefModeRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) HCenterRecord(org.apache.poi.hssf.record.HCenterRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) PrintGridlinesRecord(org.apache.poi.hssf.record.PrintGridlinesRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) DataItemRecord(org.apache.poi.hssf.record.pivottable.DataItemRecord) CalcModeRecord(org.apache.poi.hssf.record.CalcModeRecord) ExternalNameRecord(org.apache.poi.hssf.record.ExternalNameRecord) SelectionRecord(org.apache.poi.hssf.record.SelectionRecord) BarRecord(org.apache.poi.hssf.record.chart.BarRecord) ChartFormatRecord(org.apache.poi.hssf.record.chart.ChartFormatRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) AxisLineFormatRecord(org.apache.poi.hssf.record.chart.AxisLineFormatRecord) SeriesListRecord(org.apache.poi.hssf.record.chart.SeriesListRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) CategorySeriesAxisRecord(org.apache.poi.hssf.record.chart.CategorySeriesAxisRecord) FrameRecord(org.apache.poi.hssf.record.chart.FrameRecord) PlotAreaRecord(org.apache.poi.hssf.record.chart.PlotAreaRecord) LabelRecord(org.apache.poi.hssf.record.LabelRecord) DVALRecord(org.apache.poi.hssf.record.DVALRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) DeltaRecord(org.apache.poi.hssf.record.DeltaRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) TextRecord(org.apache.poi.hssf.record.chart.TextRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) ChartEndObjectRecord(org.apache.poi.hssf.record.chart.ChartEndObjectRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) AxisOptionsRecord(org.apache.poi.hssf.record.chart.AxisOptionsRecord) FeatRecord(org.apache.poi.hssf.record.FeatRecord) ViewDefinitionRecord(org.apache.poi.hssf.record.pivottable.ViewDefinitionRecord) TickRecord(org.apache.poi.hssf.record.chart.TickRecord) SaveRecalcRecord(org.apache.poi.hssf.record.SaveRecalcRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) AxisRecord(org.apache.poi.hssf.record.chart.AxisRecord) MulBlankRecord(org.apache.poi.hssf.record.MulBlankRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) FontIndexRecord(org.apache.poi.hssf.record.chart.FontIndexRecord) LineFormatRecord(org.apache.poi.hssf.record.chart.LineFormatRecord) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream)

Example 2 with RecordInputStream

use of org.apache.poi.hssf.record.RecordInputStream in project poi by apache.

the class RecordLister method run.

public void run() throws IOException {
    NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
    try {
        InputStream din = BiffViewer.getPOIFSInputStream(fs);
        try {
            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));
                }
            }
        } finally {
            din.close();
        }
    } finally {
        fs.close();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream) InputStream(java.io.InputStream) File(java.io.File) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream)

Example 3 with RecordInputStream

use of org.apache.poi.hssf.record.RecordInputStream in project poi by apache.

the class TestViewFieldsRecord method testUnicodeFlag_bug46693.

public void testUnicodeFlag_bug46693() {
    byte[] data = HexRead.readFromString("01 00 01 00 01 00 04 00 05 00 00 6D 61 72 63 6F");
    RecordInputStream in = TestcaseRecordInputStream.create(ViewFieldsRecord.sid, data);
    ViewFieldsRecord rec = new ViewFieldsRecord(in);
    if (in.remaining() == 1) {
        throw new AssertionFailedError("Identified bug 46693b");
    }
    assertEquals(0, in.remaining());
    assertEquals(4 + data.length, rec.getRecordSize());
}
Also used : ViewFieldsRecord(org.apache.poi.hssf.record.pivottable.ViewFieldsRecord) AssertionFailedError(junit.framework.AssertionFailedError) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream) TestcaseRecordInputStream(org.apache.poi.hssf.record.TestcaseRecordInputStream)

Example 4 with RecordInputStream

use of org.apache.poi.hssf.record.RecordInputStream in project poi by apache.

the class OldExcelExtractor method open.

private void open(InputStream biffStream) throws IOException {
    BufferedInputStream bis = (biffStream instanceof BufferedInputStream) ? (BufferedInputStream) biffStream : new BufferedInputStream(biffStream, 8);
    if (NPOIFSFileSystem.hasPOIFSHeader(bis)) {
        NPOIFSFileSystem poifs = new NPOIFSFileSystem(bis);
        try {
            open(poifs);
        } finally {
            poifs.close();
        }
    } else {
        ris = new RecordInputStream(bis);
        toClose = bis;
        prepare();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) BufferedInputStream(java.io.BufferedInputStream) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream)

Example 5 with RecordInputStream

use of org.apache.poi.hssf.record.RecordInputStream in project poi by apache.

the class TestSeriesTextRecord method testReserializeLongTitle.

public void testReserializeLongTitle() {
    // Hex dump from bug 45784 attachment 22560 streamOffset=0x0CD1
    byte[] data = HexRead.readFromString("00 00, " + "82 " + "01 " + "50 00 6C 00 61 00 73 00 6D 00 61 00 20 00 4C 00 " + "65 00 76 00 65 00 6C 00 73 00 20 00 6F 00 66 00 " + "20 00 4C 00 2D 00 30 00 30 00 30 00 31 00 31 00 " + "31 00 32 00 32 00 32 00 2D 00 33 00 33 00 33 00 " + "58 00 34 00 34 00 34 00 20 00 69 00 6E 00 20 00 " + "53 00 44 00 20 00 72 00 61 00 74 00 0A 00 50 00 " + "4F 00 20 00 33 00 2E 00 30 00 20 00 6D 00 67 00 " + "2F 00 6B 00 67 00 20 00 28 00 35 00 2E 00 30 00 " + "20 00 6D 00 4C 00 2F 00 6B 00 67 00 29 00 20 00 " + "69 00 6E 00 20 00 4D 00 65 00 74 00 68 00 6F 00 " + "63 00 65 00 6C 00 0A 00 49 00 56 00 20 00 30 00 " + "2E 00 35 00 20 00 6D 00 67 00 2F 00 6B 00 67 00 " + "20 00 28 00 31 00 2E 00 30 00 20 00 6D 00 4C 00 " + "2F 00 6B 00 67 00 29 00 20 00 69 00 6E 00 20 00 " + "36 00 30 00 25 00 20 00 50 00 45 00 47 00 20 00 " + "32 00 30 00 30 00 0A 00 46 00 20 00 3D 00 61 00 " + "62 00 63 00");
    RecordInputStream in = TestcaseRecordInputStream.create(SeriesTextRecord.sid, data);
    SeriesTextRecord str;
    try {
        str = new SeriesTextRecord(in);
    } catch (RecordFormatException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            // "Bad requested string length (-126)"
            throw new AssertionFailedError("Identified bug 45784a");
        }
        throw e;
    }
    if (str.getRecordSize() < 0) {
        throw new AssertionFailedError("Identified bug 45784b");
    }
    byte[] ser;
    try {
        ser = str.serialize();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TestcaseRecordInputStream.confirmRecordEncoding(SeriesTextRecord.sid, data, ser);
}
Also used : RecordFormatException(org.apache.poi.hssf.record.RecordFormatException) AssertionFailedError(junit.framework.AssertionFailedError) RecordInputStream(org.apache.poi.hssf.record.RecordInputStream) TestcaseRecordInputStream(org.apache.poi.hssf.record.TestcaseRecordInputStream) RecordFormatException(org.apache.poi.hssf.record.RecordFormatException)

Aggregations

RecordInputStream (org.apache.poi.hssf.record.RecordInputStream)13 TestcaseRecordInputStream (org.apache.poi.hssf.record.TestcaseRecordInputStream)9 AssertionFailedError (junit.framework.AssertionFailedError)7 RecordFormatException (org.apache.poi.hssf.record.RecordFormatException)3 ExtendedPivotTableViewFieldsRecord (org.apache.poi.hssf.record.pivottable.ExtendedPivotTableViewFieldsRecord)3 ViewFieldsRecord (org.apache.poi.hssf.record.pivottable.ViewFieldsRecord)3 PageItemRecord (org.apache.poi.hssf.record.pivottable.PageItemRecord)2 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ArrayRecord (org.apache.poi.hssf.record.ArrayRecord)1 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1 BlankRecord (org.apache.poi.hssf.record.BlankRecord)1 BookBoolRecord (org.apache.poi.hssf.record.BookBoolRecord)1