Fix indent/whitespace

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1690495 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-12 18:02:50 +00:00
parent 239998a88c
commit d141ffd773
1 changed files with 301 additions and 304 deletions

View File

@ -88,325 +88,322 @@ import org.apache.poi.util.LittleEndian;
/** /**
* Utillity for reading in BIFF8 records and displaying data from them. * Utillity for reading in BIFF8 records and displaying data from them.
* * @see #main
*@author Andrew C. Oliver (acoliver at apache dot org)
*@author Glen Stampoultzis (glens at apache.org)
*@see #main
*/ */
public final class BiffViewer { public final class BiffViewer {
static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray(); static final char[] NEW_LINE_CHARS = System.getProperty("line.separator").toCharArray();
private BiffViewer() { private BiffViewer() {
// no instances of this class // no instances of this class
} }
/** /**
* Create an array of records from an input stream * Create an array of records from an input stream
* *
*@param is the InputStream from which the records will be obtained *@param is the InputStream from which the records will be obtained
*@return an array of Records created from the InputStream *@return an array of Records created from the InputStream
*@exception RecordFormatException on error processing the InputStream *@exception RecordFormatException on error processing the InputStream
*/ */
public static Record[] createRecords(InputStream is, PrintStream ps, BiffRecordListener recListener, boolean dumpInterpretedRecords) public static Record[] createRecords(InputStream is, PrintStream ps, BiffRecordListener recListener, boolean dumpInterpretedRecords)
throws RecordFormatException { throws RecordFormatException {
List<Record> temp = new ArrayList<Record>(); List<Record> temp = new ArrayList<Record>();
RecordInputStream recStream = new RecordInputStream(is); RecordInputStream recStream = new RecordInputStream(is);
while (true) { while (true) {
boolean hasNext; boolean hasNext;
try { try {
hasNext = recStream.hasNextRecord(); hasNext = recStream.hasNextRecord();
} catch (LeftoverDataException e) { } catch (LeftoverDataException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("Discarding " + recStream.remaining() + " bytes and continuing"); System.err.println("Discarding " + recStream.remaining() + " bytes and continuing");
recStream.readRemainder(); recStream.readRemainder();
hasNext = recStream.hasNextRecord(); hasNext = recStream.hasNextRecord();
} }
if (!hasNext) { if (!hasNext) {
break; break;
} }
recStream.nextRecord(); recStream.nextRecord();
if (recStream.getSid() == 0) { if (recStream.getSid() == 0) {
continue; continue;
} }
Record record; Record record;
if (dumpInterpretedRecords) { if (dumpInterpretedRecords) {
record = createRecord (recStream); record = createRecord (recStream);
if (record.getSid() == ContinueRecord.sid) { if (record.getSid() == ContinueRecord.sid) {
continue; continue;
} }
temp.add(record); temp.add(record);
if (dumpInterpretedRecords) { if (dumpInterpretedRecords) {
for (String header : recListener.getRecentHeaders()) { for (String header : recListener.getRecentHeaders()) {
ps.println(header); ps.println(header);
} }
ps.print(record.toString()); ps.print(record.toString());
} }
} else { } else {
recStream.readRemainder(); recStream.readRemainder();
} }
ps.println(); ps.println();
} }
Record[] result = new Record[temp.size()]; Record[] result = new Record[temp.size()];
temp.toArray(result); temp.toArray(result);
return result; return result;
} }
/** /**
* Essentially a duplicate of RecordFactory. Kept separate 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) {
switch (in.getSid()) { switch (in.getSid()) {
case AreaFormatRecord.sid: return new AreaFormatRecord(in); case AreaFormatRecord.sid: return new AreaFormatRecord(in);
case AreaRecord.sid: return new AreaRecord(in); case AreaRecord.sid: return new AreaRecord(in);
case ArrayRecord.sid: return new ArrayRecord(in); case ArrayRecord.sid: return new ArrayRecord(in);
case AxisLineFormatRecord.sid: return new AxisLineFormatRecord(in); case AxisLineFormatRecord.sid: return new AxisLineFormatRecord(in);
case AxisOptionsRecord.sid: return new AxisOptionsRecord(in); case AxisOptionsRecord.sid: return new AxisOptionsRecord(in);
case AxisParentRecord.sid: return new AxisParentRecord(in); case AxisParentRecord.sid: return new AxisParentRecord(in);
case AxisRecord.sid: return new AxisRecord(in); case AxisRecord.sid: return new AxisRecord(in);
case AxisUsedRecord.sid: return new AxisUsedRecord(in); case AxisUsedRecord.sid: return new AxisUsedRecord(in);
case AutoFilterInfoRecord.sid: return new AutoFilterInfoRecord(in); case AutoFilterInfoRecord.sid: return new AutoFilterInfoRecord(in);
case BOFRecord.sid: return new BOFRecord(in); case BOFRecord.sid: return new BOFRecord(in);
case BackupRecord.sid: return new BackupRecord(in); case BackupRecord.sid: return new BackupRecord(in);
case BarRecord.sid: return new BarRecord(in); case BarRecord.sid: return new BarRecord(in);
case BeginRecord.sid: return new BeginRecord(in); case BeginRecord.sid: return new BeginRecord(in);
case BlankRecord.sid: return new BlankRecord(in); case BlankRecord.sid: return new BlankRecord(in);
case BookBoolRecord.sid: return new BookBoolRecord(in); case BookBoolRecord.sid: return new BookBoolRecord(in);
case BoolErrRecord.sid: return new BoolErrRecord(in); case BoolErrRecord.sid: return new BoolErrRecord(in);
case BottomMarginRecord.sid: return new BottomMarginRecord(in); case BottomMarginRecord.sid: return new BottomMarginRecord(in);
case BoundSheetRecord.sid: return new BoundSheetRecord(in); case BoundSheetRecord.sid: return new BoundSheetRecord(in);
case CFHeaderRecord.sid: return new CFHeaderRecord(in); case CFHeaderRecord.sid: return new CFHeaderRecord(in);
case CFHeader12Record.sid: return new CFHeader12Record(in); case CFHeader12Record.sid: return new CFHeader12Record(in);
case CFRuleRecord.sid: return new CFRuleRecord(in); case CFRuleRecord.sid: return new CFRuleRecord(in);
case CalcCountRecord.sid: return new CalcCountRecord(in); case CalcCountRecord.sid: return new CalcCountRecord(in);
case CalcModeRecord.sid: return new CalcModeRecord(in); case CalcModeRecord.sid: return new CalcModeRecord(in);
case CategorySeriesAxisRecord.sid: return new CategorySeriesAxisRecord(in); case CategorySeriesAxisRecord.sid:return new CategorySeriesAxisRecord(in);
case ChartFormatRecord.sid: return new ChartFormatRecord(in); case ChartFormatRecord.sid: return new ChartFormatRecord(in);
case ChartRecord.sid: return new ChartRecord(in); case ChartRecord.sid: return new ChartRecord(in);
case CodepageRecord.sid: return new CodepageRecord(in); case CodepageRecord.sid: return new CodepageRecord(in);
case ColumnInfoRecord.sid: return new ColumnInfoRecord(in); case ColumnInfoRecord.sid: return new ColumnInfoRecord(in);
case ContinueRecord.sid: return new ContinueRecord(in); case ContinueRecord.sid: return new ContinueRecord(in);
case CountryRecord.sid: return new CountryRecord(in); case CountryRecord.sid: return new CountryRecord(in);
case DBCellRecord.sid: return new DBCellRecord(in); case DBCellRecord.sid: return new DBCellRecord(in);
case DSFRecord.sid: return new DSFRecord(in); case DSFRecord.sid: return new DSFRecord(in);
case DatRecord.sid: return new DatRecord(in); case DatRecord.sid: return new DatRecord(in);
case DataFormatRecord.sid: return new DataFormatRecord(in); case DataFormatRecord.sid: return new DataFormatRecord(in);
case DateWindow1904Record.sid: return new DateWindow1904Record(in); case DateWindow1904Record.sid: return new DateWindow1904Record(in);
case DConRefRecord.sid: return new DConRefRecord(in); case DConRefRecord.sid: return new DConRefRecord(in);
case DefaultColWidthRecord.sid:return new DefaultColWidthRecord(in); case DefaultColWidthRecord.sid: return new DefaultColWidthRecord(in);
case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in); case DefaultDataLabelTextPropertiesRecord.sid: return new DefaultDataLabelTextPropertiesRecord(in);
case DefaultRowHeightRecord.sid: return new DefaultRowHeightRecord(in); case DefaultRowHeightRecord.sid: return new DefaultRowHeightRecord(in);
case DeltaRecord.sid: return new DeltaRecord(in); case DeltaRecord.sid: return new DeltaRecord(in);
case DimensionsRecord.sid: return new DimensionsRecord(in); case DimensionsRecord.sid: return new DimensionsRecord(in);
case DrawingGroupRecord.sid: return new DrawingGroupRecord(in); case DrawingGroupRecord.sid: return new DrawingGroupRecord(in);
case DrawingRecordForBiffViewer.sid: return new DrawingRecordForBiffViewer(in); case DrawingRecordForBiffViewer.sid: return new DrawingRecordForBiffViewer(in);
case DrawingSelectionRecord.sid: return new DrawingSelectionRecord(in); case DrawingSelectionRecord.sid: return new DrawingSelectionRecord(in);
case DVRecord.sid: return new DVRecord(in); case DVRecord.sid: return new DVRecord(in);
case DVALRecord.sid: return new DVALRecord(in); case DVALRecord.sid: return new DVALRecord(in);
case EOFRecord.sid: return new EOFRecord(in); case EOFRecord.sid: return new EOFRecord(in);
case EndRecord.sid: return new EndRecord(in); case EndRecord.sid: return new EndRecord(in);
case ExtSSTRecord.sid: return new ExtSSTRecord(in); case ExtSSTRecord.sid: return new ExtSSTRecord(in);
case ExtendedFormatRecord.sid: return new ExtendedFormatRecord(in); case ExtendedFormatRecord.sid: return new ExtendedFormatRecord(in);
case ExternSheetRecord.sid: return new ExternSheetRecord(in); case ExternSheetRecord.sid: return new ExternSheetRecord(in);
case ExternalNameRecord.sid: return new ExternalNameRecord(in); case ExternalNameRecord.sid: return new ExternalNameRecord(in);
case FeatRecord.sid: return new FeatRecord(in); case FeatRecord.sid: return new FeatRecord(in);
case FeatHdrRecord.sid: return new FeatHdrRecord(in); case FeatHdrRecord.sid: return new FeatHdrRecord(in);
case FilePassRecord.sid: return new FilePassRecord(in); case FilePassRecord.sid: return new FilePassRecord(in);
case FileSharingRecord.sid: return new FileSharingRecord(in); case FileSharingRecord.sid: return new FileSharingRecord(in);
case FnGroupCountRecord.sid: return new FnGroupCountRecord(in); case FnGroupCountRecord.sid: return new FnGroupCountRecord(in);
case FontBasisRecord.sid: return new FontBasisRecord(in); case FontBasisRecord.sid: return new FontBasisRecord(in);
case FontIndexRecord.sid: return new FontIndexRecord(in); case FontIndexRecord.sid: return new FontIndexRecord(in);
case FontRecord.sid: return new FontRecord(in); case FontRecord.sid: return new FontRecord(in);
case FooterRecord.sid: return new FooterRecord(in); case FooterRecord.sid: return new FooterRecord(in);
case FormatRecord.sid: return new FormatRecord(in); case FormatRecord.sid: return new FormatRecord(in);
case FormulaRecord.sid: return new FormulaRecord(in); case FormulaRecord.sid: return new FormulaRecord(in);
case FrameRecord.sid: return new FrameRecord(in); case FrameRecord.sid: return new FrameRecord(in);
case GridsetRecord.sid: return new GridsetRecord(in); case GridsetRecord.sid: return new GridsetRecord(in);
case GutsRecord.sid: return new GutsRecord(in); case GutsRecord.sid: return new GutsRecord(in);
case HCenterRecord.sid: return new HCenterRecord(in); case HCenterRecord.sid: return new HCenterRecord(in);
case HeaderRecord.sid: return new HeaderRecord(in); case HeaderRecord.sid: return new HeaderRecord(in);
case HideObjRecord.sid: return new HideObjRecord(in); case HideObjRecord.sid: return new HideObjRecord(in);
case HorizontalPageBreakRecord.sid: return new HorizontalPageBreakRecord(in); case HorizontalPageBreakRecord.sid: return new HorizontalPageBreakRecord(in);
case HyperlinkRecord.sid: return new HyperlinkRecord(in); case HyperlinkRecord.sid: return new HyperlinkRecord(in);
case IndexRecord.sid: return new IndexRecord(in); case IndexRecord.sid: return new IndexRecord(in);
case InterfaceEndRecord.sid: return InterfaceEndRecord.create(in); case InterfaceEndRecord.sid: return InterfaceEndRecord.create(in);
case InterfaceHdrRecord.sid: return new InterfaceHdrRecord(in); case InterfaceHdrRecord.sid: return new InterfaceHdrRecord(in);
case IterationRecord.sid: return new IterationRecord(in); case IterationRecord.sid: return new IterationRecord(in);
case LabelRecord.sid: return new LabelRecord(in); case LabelRecord.sid: return new LabelRecord(in);
case LabelSSTRecord.sid: return new LabelSSTRecord(in); case LabelSSTRecord.sid: return new LabelSSTRecord(in);
case LeftMarginRecord.sid: return new LeftMarginRecord(in); case LeftMarginRecord.sid: return new LeftMarginRecord(in);
case LegendRecord.sid: return new LegendRecord(in); case LegendRecord.sid: return new LegendRecord(in);
case LineFormatRecord.sid: return new LineFormatRecord(in); case LineFormatRecord.sid: return new LineFormatRecord(in);
case LinkedDataRecord.sid: return new LinkedDataRecord(in); case LinkedDataRecord.sid: return new LinkedDataRecord(in);
case MMSRecord.sid: return new MMSRecord(in); case MMSRecord.sid: return new MMSRecord(in);
case MergeCellsRecord.sid: return new MergeCellsRecord(in); case MergeCellsRecord.sid: return new MergeCellsRecord(in);
case MulBlankRecord.sid: return new MulBlankRecord(in); case MulBlankRecord.sid: return new MulBlankRecord(in);
case MulRKRecord.sid: return new MulRKRecord(in); case MulRKRecord.sid: return new MulRKRecord(in);
case NameRecord.sid: return new NameRecord(in); case NameRecord.sid: return new NameRecord(in);
case NameCommentRecord.sid: return new NameCommentRecord(in); case NameCommentRecord.sid: return new NameCommentRecord(in);
case NoteRecord.sid: return new NoteRecord(in); case NoteRecord.sid: return new NoteRecord(in);
case NumberRecord.sid: return new NumberRecord(in); case NumberRecord.sid: return new NumberRecord(in);
case ObjRecord.sid: return new ObjRecord(in); case ObjRecord.sid: return new ObjRecord(in);
case ObjectLinkRecord.sid: return new ObjectLinkRecord(in); case ObjectLinkRecord.sid: return new ObjectLinkRecord(in);
case PaletteRecord.sid: return new PaletteRecord(in); case PaletteRecord.sid: return new PaletteRecord(in);
case PaneRecord.sid: return new PaneRecord(in); case PaneRecord.sid: return new PaneRecord(in);
case PasswordRecord.sid: return new PasswordRecord(in); case PasswordRecord.sid: return new PasswordRecord(in);
case PasswordRev4Record.sid: return new PasswordRev4Record(in); case PasswordRev4Record.sid: return new PasswordRev4Record(in);
case PlotAreaRecord.sid: return new PlotAreaRecord(in); case PlotAreaRecord.sid: return new PlotAreaRecord(in);
case PlotGrowthRecord.sid: return new PlotGrowthRecord(in); case PlotGrowthRecord.sid: return new PlotGrowthRecord(in);
case PrecisionRecord.sid: return new PrecisionRecord(in); case PrecisionRecord.sid: return new PrecisionRecord(in);
case PrintGridlinesRecord.sid: return new PrintGridlinesRecord(in); case PrintGridlinesRecord.sid: return new PrintGridlinesRecord(in);
case PrintHeadersRecord.sid: return new PrintHeadersRecord(in); case PrintHeadersRecord.sid: return new PrintHeadersRecord(in);
case PrintSetupRecord.sid: return new PrintSetupRecord(in); case PrintSetupRecord.sid: return new PrintSetupRecord(in);
case ProtectRecord.sid: return new ProtectRecord(in); case ProtectRecord.sid: return new ProtectRecord(in);
case ProtectionRev4Record.sid: return new ProtectionRev4Record(in); case ProtectionRev4Record.sid: return new ProtectionRev4Record(in);
case RKRecord.sid: return new RKRecord(in); case RKRecord.sid: return new RKRecord(in);
case RecalcIdRecord.sid: return new RecalcIdRecord(in); case RecalcIdRecord.sid: return new RecalcIdRecord(in);
case RefModeRecord.sid: return new RefModeRecord(in); case RefModeRecord.sid: return new RefModeRecord(in);
case RefreshAllRecord.sid: return new RefreshAllRecord(in); case RefreshAllRecord.sid: return new RefreshAllRecord(in);
case RightMarginRecord.sid: return new RightMarginRecord(in); case RightMarginRecord.sid: return new RightMarginRecord(in);
case RowRecord.sid: return new RowRecord(in); case RowRecord.sid: return new RowRecord(in);
case SCLRecord.sid: return new SCLRecord(in); case SCLRecord.sid: return new SCLRecord(in);
case SSTRecord.sid: return new SSTRecord(in); case SSTRecord.sid: return new SSTRecord(in);
case SaveRecalcRecord.sid: return new SaveRecalcRecord(in); case SaveRecalcRecord.sid: return new SaveRecalcRecord(in);
case SelectionRecord.sid: return new SelectionRecord(in); case SelectionRecord.sid: return new SelectionRecord(in);
case SeriesIndexRecord.sid: return new SeriesIndexRecord(in); case SeriesIndexRecord.sid: return new SeriesIndexRecord(in);
case SeriesListRecord.sid: return new SeriesListRecord(in); case SeriesListRecord.sid: return new SeriesListRecord(in);
case SeriesRecord.sid: return new SeriesRecord(in); case SeriesRecord.sid: return new SeriesRecord(in);
case SeriesTextRecord.sid: return new SeriesTextRecord(in); case SeriesTextRecord.sid: return new SeriesTextRecord(in);
case SeriesToChartGroupRecord.sid: return new SeriesToChartGroupRecord(in); case SeriesToChartGroupRecord.sid:return new SeriesToChartGroupRecord(in);
case SharedFormulaRecord.sid: return new SharedFormulaRecord(in); case SharedFormulaRecord.sid: return new SharedFormulaRecord(in);
case SheetPropertiesRecord.sid:return new SheetPropertiesRecord(in); case SheetPropertiesRecord.sid: return new SheetPropertiesRecord(in);
case StringRecord.sid: return new StringRecord(in); case StringRecord.sid: return new StringRecord(in);
case StyleRecord.sid: return new StyleRecord(in); case StyleRecord.sid: return new StyleRecord(in);
case SupBookRecord.sid: return new SupBookRecord(in); case SupBookRecord.sid: return new SupBookRecord(in);
case TabIdRecord.sid: return new TabIdRecord(in); case TabIdRecord.sid: return new TabIdRecord(in);
case TableStylesRecord.sid: return new TableStylesRecord(in); case TableStylesRecord.sid: return new TableStylesRecord(in);
case TableRecord.sid: return new TableRecord(in); case TableRecord.sid: return new TableRecord(in);
case TextObjectRecord.sid: return new TextObjectRecord(in); case TextObjectRecord.sid: return new TextObjectRecord(in);
case TextRecord.sid: return new TextRecord(in); case TextRecord.sid: return new TextRecord(in);
case TickRecord.sid: return new TickRecord(in); case TickRecord.sid: return new TickRecord(in);
case TopMarginRecord.sid: return new TopMarginRecord(in); case TopMarginRecord.sid: return new TopMarginRecord(in);
case UncalcedRecord.sid: return new UncalcedRecord(in); case UncalcedRecord.sid: return new UncalcedRecord(in);
case UnitsRecord.sid: return new UnitsRecord(in); case UnitsRecord.sid: return new UnitsRecord(in);
case UseSelFSRecord.sid: return new UseSelFSRecord(in); case UseSelFSRecord.sid: return new UseSelFSRecord(in);
case VCenterRecord.sid: return new VCenterRecord(in); case VCenterRecord.sid: return new VCenterRecord(in);
case ValueRangeRecord.sid: return new ValueRangeRecord(in); case ValueRangeRecord.sid: return new ValueRangeRecord(in);
case VerticalPageBreakRecord.sid: return new VerticalPageBreakRecord(in); case VerticalPageBreakRecord.sid: return new VerticalPageBreakRecord(in);
case WSBoolRecord.sid: return new WSBoolRecord(in); case WSBoolRecord.sid: return new WSBoolRecord(in);
case WindowOneRecord.sid: return new WindowOneRecord(in); case WindowOneRecord.sid: return new WindowOneRecord(in);
case WindowProtectRecord.sid: return new WindowProtectRecord(in); case WindowProtectRecord.sid: return new WindowProtectRecord(in);
case WindowTwoRecord.sid: return new WindowTwoRecord(in); case WindowTwoRecord.sid: return new WindowTwoRecord(in);
case WriteAccessRecord.sid: return new WriteAccessRecord(in); case WriteAccessRecord.sid: return new WriteAccessRecord(in);
case WriteProtectRecord.sid: return new WriteProtectRecord(in); case WriteProtectRecord.sid: return new WriteProtectRecord(in);
// chart // chart
case CatLabRecord.sid: return new CatLabRecord(in); case CatLabRecord.sid: return new CatLabRecord(in);
case ChartEndBlockRecord.sid: return new ChartEndBlockRecord(in); case ChartEndBlockRecord.sid: return new ChartEndBlockRecord(in);
case ChartEndObjectRecord.sid: return new ChartEndObjectRecord(in); case ChartEndObjectRecord.sid: return new ChartEndObjectRecord(in);
case ChartFRTInfoRecord.sid: return new ChartFRTInfoRecord(in); case ChartFRTInfoRecord.sid: return new ChartFRTInfoRecord(in);
case ChartStartBlockRecord.sid: return new ChartStartBlockRecord(in); case ChartStartBlockRecord.sid: return new ChartStartBlockRecord(in);
case ChartStartObjectRecord.sid: return new ChartStartObjectRecord(in); case ChartStartObjectRecord.sid: return new ChartStartObjectRecord(in);
// pivot table // pivot table
case StreamIDRecord.sid: return new StreamIDRecord(in); case StreamIDRecord.sid: return new StreamIDRecord(in);
case ViewSourceRecord.sid: return new ViewSourceRecord(in); case ViewSourceRecord.sid: return new ViewSourceRecord(in);
case PageItemRecord.sid: return new PageItemRecord(in); case PageItemRecord.sid: return new PageItemRecord(in);
case ViewDefinitionRecord.sid: return new ViewDefinitionRecord(in); case ViewDefinitionRecord.sid: return new ViewDefinitionRecord(in);
case ViewFieldsRecord.sid: return new ViewFieldsRecord(in); case ViewFieldsRecord.sid: return new ViewFieldsRecord(in);
case DataItemRecord.sid: return new DataItemRecord(in); case DataItemRecord.sid: return new DataItemRecord(in);
case ExtendedPivotTableViewFieldsRecord.sid: return new ExtendedPivotTableViewFieldsRecord(in); case ExtendedPivotTableViewFieldsRecord.sid: return new ExtendedPivotTableViewFieldsRecord(in);
} }
return new UnknownRecord(in); return new UnknownRecord(in);
} }
private static final class CommandArgs { private static final class CommandArgs {
private final boolean _biffhex; private final boolean _biffhex;
private final boolean _noint; private final boolean _noint;
private final boolean _out; private final boolean _out;
private final boolean _rawhex; private final boolean _rawhex;
private final boolean _noHeader; private final boolean _noHeader;
private final File _file; private final File _file;
private CommandArgs(boolean biffhex, boolean noint, boolean out, boolean rawhex, boolean noHeader, File file) { private CommandArgs(boolean biffhex, boolean noint, boolean out, boolean rawhex, boolean noHeader, File file) {
_biffhex = biffhex; _biffhex = biffhex;
_noint = noint; _noint = noint;
_out = out; _out = out;
_rawhex = rawhex; _rawhex = rawhex;
_file = file; _file = file;
_noHeader = noHeader; _noHeader = noHeader;
} }
public static CommandArgs parse(String[] args) throws CommandParseException { public static CommandArgs parse(String[] args) throws CommandParseException {
int nArgs = args.length; int nArgs = args.length;
boolean biffhex = false; boolean biffhex = false;
boolean noint = false; boolean noint = false;
boolean out = false; boolean out = false;
boolean rawhex = false; boolean rawhex = false;
boolean noheader = false; boolean noheader = false;
File file = null; File file = null;
for (int i=0; i<nArgs; i++) { for (int i=0; i<nArgs; i++) {
String arg = args[i]; String arg = args[i];
if (arg.startsWith("--")) { if (arg.startsWith("--")) {
if ("--biffhex".equals(arg)) { if ("--biffhex".equals(arg)) {
biffhex = true; biffhex = true;
} else if ("--noint".equals(arg)) { } else if ("--noint".equals(arg)) {
noint = true; noint = true;
} else if ("--out".equals(arg)) { } else if ("--out".equals(arg)) {
out = true; out = true;
} else if ("--escher".equals(arg)) { } else if ("--escher".equals(arg)) {
System.setProperty("poi.deserialize.escher", "true"); System.setProperty("poi.deserialize.escher", "true");
} else if ("--rawhex".equals(arg)) { } else if ("--rawhex".equals(arg)) {
rawhex = true; rawhex = true;
} else if ("--noheader".equals(arg)) { } else if ("--noheader".equals(arg)) {
noheader = true; noheader = true;
} else { } else {
throw new CommandParseException("Unexpected option '" + arg + "'"); throw new CommandParseException("Unexpected option '" + arg + "'");
} }
continue; continue;
} }
file = new File(arg); file = new File(arg);
if (!file.exists()) { if (!file.exists()) {
throw new CommandParseException("Specified file '" + arg + "' does not exist"); throw new CommandParseException("Specified file '" + arg + "' does not exist");
} }
if (i+1<nArgs) { if (i+1<nArgs) {
throw new CommandParseException("File name must be the last arg"); throw new CommandParseException("File name must be the last arg");
} }
} }
if (file == null) { if (file == null) {
throw new CommandParseException("Biff viewer needs a filename"); throw new CommandParseException("Biff viewer needs a filename");
} }
return new CommandArgs(biffhex, noint, out, rawhex, noheader, file); return new CommandArgs(biffhex, noint, out, rawhex, noheader, file);
} }
public boolean shouldDumpBiffHex() { public boolean shouldDumpBiffHex() {
return _biffhex; return _biffhex;
} }
public boolean shouldDumpRecordInterpretations() { public boolean shouldDumpRecordInterpretations() {
return !_noint; return !_noint;
} }
public boolean shouldOutputToFile() { public boolean shouldOutputToFile() {
return _out; return _out;
} }
public boolean shouldOutputRawHexOnly() { public boolean shouldOutputRawHexOnly() {
return _rawhex; return _rawhex;
} }
public boolean suppressHeader() { public boolean suppressHeader() {
return _noHeader; return _noHeader;
} }
public File getFile() { public File getFile() {
return _file; return _file;
} }
} }
private static final class CommandParseException extends Exception { private static final class CommandParseException extends Exception {
public CommandParseException(String msg) { public CommandParseException(String msg) {
super(msg); super(msg);
} }
} }
/** /**
* Method main with 1 argument just run straight biffview against given * Method main with 1 argument just run straight biffview against given