Simplification of BiffViewer. Made easier to send results to file.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@657166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-05-16 18:46:04 +00:00
parent 9c65dbae4a
commit e5828d77dc

View File

@ -15,22 +15,20 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* BiffViewer.java
*
* Created on November 13, 2001, 9:23 AM
*/
package org.apache.poi.hssf.dev; package org.apache.poi.hssf.dev;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
/** /**
* Utillity for reading in BIFF8 records and displaying data from them. * Utillity for reading in BIFF8 records and displaying data from them.
* *
@ -38,38 +36,26 @@ import java.util.ArrayList;
*@author Glen Stampoultzis (glens at apache.org) *@author Glen Stampoultzis (glens at apache.org)
*@see #main *@see #main
*/ */
public final class BiffViewer {
public class BiffViewer { private final File _inputFile;
String filename;
private boolean dump; private boolean dump;
private final PrintStream _ps;
/** public BiffViewer(File inFile, PrintStream ps) {
* Creates new BiffViewer _inputFile = inFile;
* _ps = ps;
*@param args
*/
public BiffViewer(String[] args) {
if (args.length > 0) {
filename = args[0];
} else {
System.out.println("BIFFVIEWER REQUIRES A FILENAME***");
}
} }
/** /**
* Method run starts up BiffViewer... * Method run starts up BiffViewer...
*/ */
public void run() { public void run() {
try { try {
POIFSFileSystem fs = POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(_inputFile));
new POIFSFileSystem(new FileInputStream(filename)); InputStream stream = fs.createDocumentInputStream("Workbook");
InputStream stream = createRecords(stream, dump, _ps);
fs.createDocumentInputStream("Workbook");
createRecords(stream, dump);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -86,13 +72,11 @@ public class BiffViewer {
* InputStream * InputStream
*@exception RecordFormatException on error processing the InputStream *@exception RecordFormatException on error processing the InputStream
*/ */
public static Record[] createRecords(InputStream in, boolean dump, PrintStream ps)
public static Record[] createRecords(InputStream in, boolean dump)
throws RecordFormatException { throws RecordFormatException {
ArrayList records = new ArrayList(); ArrayList records = new ArrayList();
RecordDetails activeRecord = null; RecordDetails activeRecord = null;
try {
BiffviewRecordInputStream recStream = new BiffviewRecordInputStream(in); BiffviewRecordInputStream recStream = new BiffviewRecordInputStream(in);
while (recStream.hasNextRecord()) { while (recStream.hasNextRecord()) {
recStream.nextRecord(); recStream.nextRecord();
@ -102,435 +86,292 @@ public class BiffViewer {
{ {
records.add(record); records.add(record);
if (activeRecord != null) if (activeRecord != null)
activeRecord.dump(); activeRecord.dump(ps);
activeRecord = new RecordDetails(recStream.getSid(), recStream.getLength(), (int)recStream.getPos(), record); activeRecord = new RecordDetails(recStream.getSid(), recStream.getLength(), (int)recStream.getPos(), record);
} }
if (dump) { if (dump) {
recStream.dumpBytes(); recStream.dumpBytes(ps);
} }
} }
} }
activeRecord.dump(); if (activeRecord != null) {
} catch (IOException e) { activeRecord.dump(ps);
throw new RecordFormatException("Error reading bytes", e);
} }
Record[] retval = new Record[records.size()]; Record[] retval = new Record[records.size()];
records.toArray(retval);
retval = (Record[]) records.toArray(retval);
return retval; return retval;
} }
private static void dumpNormal(Record record, int startloc, short rectype, short recsize)
{
System.out.println("Offset 0x" + Integer.toHexString(startloc) + " (" + startloc + ")");
System.out.println( "recordid = 0x" + Integer.toHexString( rectype ) + ", size = " + recsize );
System.out.println( record.toString() );
}
/** /**
* Essentially a duplicate of RecordFactory. Kept seperate as not to screw * Essentially a duplicate of RecordFactory. Kept separate as not to screw
* up non-debug operations. * up non-debug operations.
* *
*/ */
private static Record createRecord( RecordInputStream in ) private static Record createRecord( RecordInputStream in )
{ {
Record retval = null;
switch ( in.getSid() ) switch ( in.getSid() )
{ {
case ChartRecord.sid: case ChartRecord.sid:
retval = new ChartRecord( in ); return new ChartRecord( in );
break;
case ChartFormatRecord.sid: case ChartFormatRecord.sid:
retval = new ChartFormatRecord( in ); return new ChartFormatRecord( in );
break;
case SeriesRecord.sid: case SeriesRecord.sid:
retval = new SeriesRecord( in ); return new SeriesRecord( in );
break;
case BeginRecord.sid: case BeginRecord.sid:
retval = new BeginRecord( in ); return new BeginRecord( in );
break;
case EndRecord.sid: case EndRecord.sid:
retval = new EndRecord( in ); return new EndRecord( in );
break;
case BOFRecord.sid: case BOFRecord.sid:
retval = new BOFRecord( in ); return new BOFRecord( in );
break;
case InterfaceHdrRecord.sid: case InterfaceHdrRecord.sid:
retval = new InterfaceHdrRecord( in ); return new InterfaceHdrRecord( in );
break;
case MMSRecord.sid: case MMSRecord.sid:
retval = new MMSRecord( in ); return new MMSRecord( in );
break;
case InterfaceEndRecord.sid: case InterfaceEndRecord.sid:
retval = new InterfaceEndRecord( in ); return new InterfaceEndRecord( in );
break;
case WriteAccessRecord.sid: case WriteAccessRecord.sid:
retval = new WriteAccessRecord( in ); return new WriteAccessRecord( in );
break;
case CodepageRecord.sid: case CodepageRecord.sid:
retval = new CodepageRecord( in ); return new CodepageRecord( in );
break;
case DSFRecord.sid: case DSFRecord.sid:
retval = new DSFRecord( in ); return new DSFRecord( in );
break;
case TabIdRecord.sid: case TabIdRecord.sid:
retval = new TabIdRecord( in ); return new TabIdRecord( in );
break;
case FnGroupCountRecord.sid: case FnGroupCountRecord.sid:
retval = new FnGroupCountRecord( in ); return new FnGroupCountRecord( in );
break;
case WindowProtectRecord.sid: case WindowProtectRecord.sid:
retval = new WindowProtectRecord( in ); return new WindowProtectRecord( in );
break;
case ProtectRecord.sid: case ProtectRecord.sid:
retval = new ProtectRecord( in ); return new ProtectRecord( in );
break;
case PasswordRecord.sid: case PasswordRecord.sid:
retval = new PasswordRecord( in ); return new PasswordRecord( in );
break;
case ProtectionRev4Record.sid: case ProtectionRev4Record.sid:
retval = new ProtectionRev4Record( in ); return new ProtectionRev4Record( in );
break;
case PasswordRev4Record.sid: case PasswordRev4Record.sid:
retval = new PasswordRev4Record( in ); return new PasswordRev4Record( in );
break;
case WindowOneRecord.sid: case WindowOneRecord.sid:
retval = new WindowOneRecord( in ); return new WindowOneRecord( in );
break;
case BackupRecord.sid: case BackupRecord.sid:
retval = new BackupRecord( in ); return new BackupRecord( in );
break;
case HideObjRecord.sid: case HideObjRecord.sid:
retval = new HideObjRecord( in ); return new HideObjRecord( in );
break;
case DateWindow1904Record.sid: case DateWindow1904Record.sid:
retval = new DateWindow1904Record( in ); return new DateWindow1904Record( in );
break;
case PrecisionRecord.sid: case PrecisionRecord.sid:
retval = new PrecisionRecord( in ); return new PrecisionRecord( in );
break;
case RefreshAllRecord.sid: case RefreshAllRecord.sid:
retval = new RefreshAllRecord( in ); return new RefreshAllRecord( in );
break;
case BookBoolRecord.sid: case BookBoolRecord.sid:
retval = new BookBoolRecord( in ); return new BookBoolRecord( in );
break;
case FontRecord.sid: case FontRecord.sid:
retval = new FontRecord( in ); return new FontRecord( in );
break;
case FormatRecord.sid: case FormatRecord.sid:
retval = new FormatRecord( in ); return new FormatRecord( in );
break;
case ExtendedFormatRecord.sid: case ExtendedFormatRecord.sid:
retval = new ExtendedFormatRecord( in ); return new ExtendedFormatRecord( in );
break;
case StyleRecord.sid: case StyleRecord.sid:
retval = new StyleRecord( in ); return new StyleRecord( in );
break;
case UseSelFSRecord.sid: case UseSelFSRecord.sid:
retval = new UseSelFSRecord( in ); return new UseSelFSRecord( in );
break;
case BoundSheetRecord.sid: case BoundSheetRecord.sid:
retval = new BoundSheetRecord( in ); return new BoundSheetRecord( in );
break;
case CountryRecord.sid: case CountryRecord.sid:
retval = new CountryRecord( in ); return new CountryRecord( in );
break;
case SSTRecord.sid: case SSTRecord.sid:
retval = new SSTRecord( in ); return new SSTRecord( in );
break;
case ExtSSTRecord.sid: case ExtSSTRecord.sid:
retval = new ExtSSTRecord( in ); return new ExtSSTRecord( in );
break;
case EOFRecord.sid: case EOFRecord.sid:
retval = new EOFRecord( in ); return new EOFRecord( in );
break;
case IndexRecord.sid: case IndexRecord.sid:
retval = new IndexRecord( in ); return new IndexRecord( in );
break;
case CalcModeRecord.sid: case CalcModeRecord.sid:
retval = new CalcModeRecord( in ); return new CalcModeRecord( in );
break;
case CalcCountRecord.sid: case CalcCountRecord.sid:
retval = new CalcCountRecord( in ); return new CalcCountRecord( in );
break;
case RefModeRecord.sid: case RefModeRecord.sid:
retval = new RefModeRecord( in ); return new RefModeRecord( in );
break;
case IterationRecord.sid: case IterationRecord.sid:
retval = new IterationRecord( in ); return new IterationRecord( in );
break;
case DeltaRecord.sid: case DeltaRecord.sid:
retval = new DeltaRecord( in ); return new DeltaRecord( in );
break;
case SaveRecalcRecord.sid: case SaveRecalcRecord.sid:
retval = new SaveRecalcRecord( in ); return new SaveRecalcRecord( in );
break;
case PrintHeadersRecord.sid: case PrintHeadersRecord.sid:
retval = new PrintHeadersRecord( in ); return new PrintHeadersRecord( in );
break;
case PrintGridlinesRecord.sid: case PrintGridlinesRecord.sid:
retval = new PrintGridlinesRecord( in ); return new PrintGridlinesRecord( in );
break;
case GridsetRecord.sid: case GridsetRecord.sid:
retval = new GridsetRecord( in ); return new GridsetRecord( in );
break;
case DrawingGroupRecord.sid: case DrawingGroupRecord.sid:
retval = new DrawingGroupRecord( in ); return new DrawingGroupRecord( in );
break;
case DrawingRecordForBiffViewer.sid: case DrawingRecordForBiffViewer.sid:
retval = new DrawingRecordForBiffViewer( in ); return new DrawingRecordForBiffViewer( in );
break;
case DrawingSelectionRecord.sid: case DrawingSelectionRecord.sid:
retval = new DrawingSelectionRecord( in ); return new DrawingSelectionRecord( in );
break;
case GutsRecord.sid: case GutsRecord.sid:
retval = new GutsRecord( in ); return new GutsRecord( in );
break;
case DefaultRowHeightRecord.sid: case DefaultRowHeightRecord.sid:
retval = new DefaultRowHeightRecord( in ); return new DefaultRowHeightRecord( in );
break;
case WSBoolRecord.sid: case WSBoolRecord.sid:
retval = new WSBoolRecord( in ); return new WSBoolRecord( in );
break;
case HeaderRecord.sid: case HeaderRecord.sid:
retval = new HeaderRecord( in ); return new HeaderRecord( in );
break;
case FooterRecord.sid: case FooterRecord.sid:
retval = new FooterRecord( in ); return new FooterRecord( in );
break;
case HCenterRecord.sid: case HCenterRecord.sid:
retval = new HCenterRecord( in ); return new HCenterRecord( in );
break;
case VCenterRecord.sid: case VCenterRecord.sid:
retval = new VCenterRecord( in ); return new VCenterRecord( in );
break;
case PrintSetupRecord.sid: case PrintSetupRecord.sid:
retval = new PrintSetupRecord( in ); return new PrintSetupRecord( in );
break;
case DefaultColWidthRecord.sid: case DefaultColWidthRecord.sid:
retval = new DefaultColWidthRecord( in ); return new DefaultColWidthRecord( in );
break;
case DimensionsRecord.sid: case DimensionsRecord.sid:
retval = new DimensionsRecord( in ); return new DimensionsRecord( in );
break;
case RowRecord.sid: case RowRecord.sid:
retval = new RowRecord( in ); return new RowRecord( in );
break;
case LabelSSTRecord.sid: case LabelSSTRecord.sid:
retval = new LabelSSTRecord( in ); return new LabelSSTRecord( in );
break;
case RKRecord.sid: case RKRecord.sid:
retval = new RKRecord( in ); return new RKRecord( in );
break;
case NumberRecord.sid: case NumberRecord.sid:
retval = new NumberRecord( in ); return new NumberRecord( in );
break;
case DBCellRecord.sid: case DBCellRecord.sid:
retval = new DBCellRecord( in ); return new DBCellRecord( in );
break;
case WindowTwoRecord.sid: case WindowTwoRecord.sid:
retval = new WindowTwoRecord( in ); return new WindowTwoRecord( in );
break;
case SelectionRecord.sid: case SelectionRecord.sid:
retval = new SelectionRecord( in ); return new SelectionRecord( in );
break;
case ContinueRecord.sid: case ContinueRecord.sid:
retval = new ContinueRecord( in ); return new ContinueRecord( in );
break;
case LabelRecord.sid: case LabelRecord.sid:
retval = new LabelRecord( in ); return new LabelRecord( in );
break;
case MulRKRecord.sid: case MulRKRecord.sid:
retval = new MulRKRecord( in ); return new MulRKRecord( in );
break;
case MulBlankRecord.sid: case MulBlankRecord.sid:
retval = new MulBlankRecord( in ); return new MulBlankRecord( in );
break;
case BlankRecord.sid: case BlankRecord.sid:
retval = new BlankRecord( in ); return new BlankRecord( in );
break;
case BoolErrRecord.sid: case BoolErrRecord.sid:
retval = new BoolErrRecord( in ); return new BoolErrRecord( in );
break;
case ColumnInfoRecord.sid: case ColumnInfoRecord.sid:
retval = new ColumnInfoRecord( in ); return new ColumnInfoRecord( in );
break;
case MergeCellsRecord.sid: case MergeCellsRecord.sid:
retval = new MergeCellsRecord( in ); return new MergeCellsRecord( in );
break;
case AreaRecord.sid: case AreaRecord.sid:
retval = new AreaRecord( in ); return new AreaRecord( in );
break;
case DataFormatRecord.sid: case DataFormatRecord.sid:
retval = new DataFormatRecord( in ); return new DataFormatRecord( in );
break;
case BarRecord.sid: case BarRecord.sid:
retval = new BarRecord( in ); return new BarRecord( in );
break;
case DatRecord.sid: case DatRecord.sid:
retval = new DatRecord( in ); return new DatRecord( in );
break;
case PlotGrowthRecord.sid: case PlotGrowthRecord.sid:
retval = new PlotGrowthRecord( in ); return new PlotGrowthRecord( in );
break;
case UnitsRecord.sid: case UnitsRecord.sid:
retval = new UnitsRecord( in ); return new UnitsRecord( in );
break;
case FrameRecord.sid: case FrameRecord.sid:
retval = new FrameRecord( in ); return new FrameRecord( in );
break;
case ValueRangeRecord.sid: case ValueRangeRecord.sid:
retval = new ValueRangeRecord( in ); return new ValueRangeRecord( in );
break;
case SeriesListRecord.sid: case SeriesListRecord.sid:
retval = new SeriesListRecord( in ); return new SeriesListRecord( in );
break;
case FontBasisRecord.sid: case FontBasisRecord.sid:
retval = new FontBasisRecord( in ); return new FontBasisRecord( in );
break;
case FontIndexRecord.sid: case FontIndexRecord.sid:
retval = new FontIndexRecord( in ); return new FontIndexRecord( in );
break;
case LineFormatRecord.sid: case LineFormatRecord.sid:
retval = new LineFormatRecord( in ); return new LineFormatRecord( in );
break;
case AreaFormatRecord.sid: case AreaFormatRecord.sid:
retval = new AreaFormatRecord( in ); return new AreaFormatRecord( in );
break;
case LinkedDataRecord.sid: case LinkedDataRecord.sid:
retval = new LinkedDataRecord( in ); return new LinkedDataRecord( in );
break;
case FormulaRecord.sid: case FormulaRecord.sid:
retval = new FormulaRecord( in ); return new FormulaRecord( in );
break;
case SheetPropertiesRecord.sid: case SheetPropertiesRecord.sid:
retval = new SheetPropertiesRecord( in ); return new SheetPropertiesRecord( in );
break;
case DefaultDataLabelTextPropertiesRecord.sid: case DefaultDataLabelTextPropertiesRecord.sid:
retval = new DefaultDataLabelTextPropertiesRecord( in ); return new DefaultDataLabelTextPropertiesRecord( in );
break;
case TextRecord.sid: case TextRecord.sid:
retval = new TextRecord( in ); return new TextRecord( in );
break;
case AxisParentRecord.sid: case AxisParentRecord.sid:
retval = new AxisParentRecord( in ); return new AxisParentRecord( in );
break;
case AxisLineFormatRecord.sid: case AxisLineFormatRecord.sid:
retval = new AxisLineFormatRecord( in ); return new AxisLineFormatRecord( in );
break;
case SupBookRecord.sid: case SupBookRecord.sid:
retval = new SupBookRecord( in ); return new SupBookRecord( in );
break;
case ExternSheetRecord.sid: case ExternSheetRecord.sid:
retval = new ExternSheetRecord( in ); return new ExternSheetRecord( in );
break;
case SCLRecord.sid: case SCLRecord.sid:
retval = new SCLRecord( in ); return new SCLRecord( in );
break;
case SeriesToChartGroupRecord.sid: case SeriesToChartGroupRecord.sid:
retval = new SeriesToChartGroupRecord( in ); return new SeriesToChartGroupRecord( in );
break;
case AxisUsedRecord.sid: case AxisUsedRecord.sid:
retval = new AxisUsedRecord( in ); return new AxisUsedRecord( in );
break;
case AxisRecord.sid: case AxisRecord.sid:
retval = new AxisRecord( in ); return new AxisRecord( in );
break;
case CategorySeriesAxisRecord.sid: case CategorySeriesAxisRecord.sid:
retval = new CategorySeriesAxisRecord( in ); return new CategorySeriesAxisRecord( in );
break;
case AxisOptionsRecord.sid: case AxisOptionsRecord.sid:
retval = new AxisOptionsRecord( in ); return new AxisOptionsRecord( in );
break;
case TickRecord.sid: case TickRecord.sid:
retval = new TickRecord( in ); return new TickRecord( in );
break;
case SeriesTextRecord.sid: case SeriesTextRecord.sid:
retval = new SeriesTextRecord( in ); return new SeriesTextRecord( in );
break;
case ObjectLinkRecord.sid: case ObjectLinkRecord.sid:
retval = new ObjectLinkRecord( in ); return new ObjectLinkRecord( in );
break;
case PlotAreaRecord.sid: case PlotAreaRecord.sid:
retval = new PlotAreaRecord( in ); return new PlotAreaRecord( in );
break;
case SeriesIndexRecord.sid: case SeriesIndexRecord.sid:
retval = new SeriesIndexRecord( in ); return new SeriesIndexRecord( in );
break;
case LegendRecord.sid: case LegendRecord.sid:
retval = new LegendRecord( in ); return new LegendRecord( in );
break;
case LeftMarginRecord.sid: case LeftMarginRecord.sid:
retval = new LeftMarginRecord( in ); return new LeftMarginRecord( in );
break;
case RightMarginRecord.sid: case RightMarginRecord.sid:
retval = new RightMarginRecord( in ); return new RightMarginRecord( in );
break;
case TopMarginRecord.sid: case TopMarginRecord.sid:
retval = new TopMarginRecord( in ); return new TopMarginRecord( in );
break;
case BottomMarginRecord.sid: case BottomMarginRecord.sid:
retval = new BottomMarginRecord( in ); return new BottomMarginRecord( in );
break;
case PaletteRecord.sid: case PaletteRecord.sid:
retval = new PaletteRecord( in ); return new PaletteRecord( in );
break;
case StringRecord.sid: case StringRecord.sid:
retval = new StringRecord( in ); return new StringRecord( in );
break;
case NameRecord.sid: case NameRecord.sid:
retval = new NameRecord( in ); return new NameRecord( in );
break;
case PaneRecord.sid: case PaneRecord.sid:
retval = new PaneRecord( in ); return new PaneRecord( in );
break;
case SharedFormulaRecord.sid: case SharedFormulaRecord.sid:
retval = new SharedFormulaRecord( in); return new SharedFormulaRecord( in);
break;
case ObjRecord.sid: case ObjRecord.sid:
retval = new ObjRecord( in); return new ObjRecord( in);
break;
case TextObjectRecord.sid: case TextObjectRecord.sid:
retval = new TextObjectRecord( in); return new TextObjectRecord( in);
break;
case HorizontalPageBreakRecord.sid: case HorizontalPageBreakRecord.sid:
retval = new HorizontalPageBreakRecord( in); return new HorizontalPageBreakRecord( in);
break;
case VerticalPageBreakRecord.sid: case VerticalPageBreakRecord.sid:
retval = new VerticalPageBreakRecord( in); return new VerticalPageBreakRecord( in);
break;
case WriteProtectRecord.sid: case WriteProtectRecord.sid:
retval = new WriteProtectRecord( in); return new WriteProtectRecord( in);
break;
case FilePassRecord.sid: case FilePassRecord.sid:
retval = new FilePassRecord(in); return new FilePassRecord(in);
break;
case NoteRecord.sid: case NoteRecord.sid:
retval = new NoteRecord( in ); return new NoteRecord( in );
break;
case FileSharingRecord.sid: case FileSharingRecord.sid:
retval = new FileSharingRecord( in ); return new FileSharingRecord( in );
break;
case HyperlinkRecord.sid: case HyperlinkRecord.sid:
retval = new HyperlinkRecord( in ); return new HyperlinkRecord( in );
break;
default:
retval = new UnknownRecord( in );
} }
return retval; return new UnknownRecord( in );
} }
/** /**
* Method setDump - hex dump out data or not. * Method setDump - hex dump out data or not.
*
*@param dump
*/ */
public void setDump(boolean dump) { public void setDump(boolean dump) {
this.dump = dump; this.dump = dump;
} }
@ -552,24 +393,35 @@ public class BiffViewer {
* *
*/ */
public static void main(String[] args) { public static void main(String[] args) {
try {
System.setProperty("poi.deserialize.escher", "true"); System.setProperty("poi.deserialize.escher", "true");
if (args.length == 0) if (args.length == 0) {
{
System.out.println( "Biff viewer needs a filename" ); System.out.println( "Biff viewer needs a filename" );
return;
} }
else
{ try {
BiffViewer viewer = new BiffViewer(args); String inFileName = args[0];
if ((args.length > 1) && args[1].equals("on")) { File inputFile = new File(inFileName);
if(!inputFile.exists()) {
throw new RuntimeException("specified inputFile '" + inFileName + "' does not exist");
}
PrintStream ps;
if (false) { // set to true to output to file
OutputStream os = new FileOutputStream(inFileName + ".out");
ps = new PrintStream(os);
} else {
ps = System.out;
}
BiffViewer viewer = new BiffViewer(inputFile, ps);
if (args.length > 1 && args[1].equals("on")) {
viewer.setDump(true); viewer.setDump(true);
} }
if ((args.length > 1) && args[1].equals("bfd")) { if (args.length > 1 && args[1].equals("bfd")) {
POIFSFileSystem fs = POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(inputFile));
new POIFSFileSystem(new FileInputStream(args[0])); InputStream stream = fs.createDocumentInputStream("Workbook");
InputStream stream =
fs.createDocumentInputStream("Workbook");
int size = stream.available(); int size = stream.available();
byte[] data = new byte[size]; byte[] data = new byte[size];
@ -578,7 +430,7 @@ public class BiffViewer {
} else { } else {
viewer.run(); viewer.run();
} }
} ps.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -587,7 +439,7 @@ public class BiffViewer {
/** /**
* This record supports dumping of completed continue records. * This record supports dumping of completed continue records.
*/ */
static class RecordDetails private static final class RecordDetails
{ {
short rectype, recsize; short rectype, recsize;
int startloc; int startloc;
@ -616,18 +468,19 @@ public class BiffViewer {
return record; return record;
} }
public void dump() throws IOException public void dump(PrintStream ps) {
{ ps.println("Offset 0x" + Integer.toHexString(startloc) + " (" + startloc + ")");
dumpNormal(record, startloc, rectype, recsize); ps.println( "recordid = 0x" + Integer.toHexString( rectype ) + ", size = " + recsize );
ps.println( record.toString() );
} }
} }
static class BiffviewRecordInputStream extends RecordInputStream { private static final class BiffviewRecordInputStream extends RecordInputStream {
public BiffviewRecordInputStream(InputStream in) { public BiffviewRecordInputStream(InputStream in) {
super(in); super(in);
} }
public void dumpBytes() { public void dumpBytes(PrintStream ps) {
HexDump.dump(this.data, 0, this.currentLength); ps.println(HexDump.dump(this.data, 0, this.currentLength));
} }
} }