Reorganized things a bit in preparation for some changes.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352413 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2002-04-14 13:54:00 +00:00
parent ef54430078
commit 9cccf3465b

View File

@ -1,4 +1,3 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
@ -93,8 +92,7 @@ public class BiffViewer
if (args.length > 0)
{
filename = args[0];
}
else
} else
{
System.out.println("BIFFVIEWER REQUIRES A FILENAME***");
}
@ -115,8 +113,7 @@ public class BiffViewer
InputStream stream =
fs.createDocumentInputStream("Workbook");
Record[] records = createRecords(stream, dump);
}
catch (Exception e)
} catch (Exception e)
{
e.printStackTrace();
}
@ -151,7 +148,7 @@ public class BiffViewer
{
rectype = LittleEndian.readShort(in);
System.out.println("============================================");
System.out.println("you are at offset " + loc);
System.out.println("Offset 0x" + Integer.toHexString(loc) + " (" + loc + ")");
loc += 2;
if (rectype != 0)
{
@ -169,65 +166,42 @@ public class BiffViewer
// offset += 4 + recsize;
if (dump)
{
// System.out
// .println("fixing to recordize the following");
System.out.println("rectype = 0x"
+ Integer.toHexString(rectype));
System.out.println("recsize = 0x"
+ Integer.toHexString(recsize));
System.out.println(
"--------------------------------------------");
if (data.length > 0)
{
HexDump.dump(data, 0, System.out, 0);
}
else
{
System.out.print("**NO RECORD DATA**");
}
System.out.println();
System.out.println(
"-END----------------------------------------");
dump(rectype, recsize, data);
}
Record[] recs = createRecord(rectype, recsize,
data); // handle MulRK records
if (recs.length > 1)
{
for (int k = 0; k < recs.length; k++)
{
records.add(
recs[ k ]); // these will be number records
last_record =
recs[ k ]; // do to keep the algorythm homogenous...you can't
} // actually continue a number record anyhow.
}
else
{
Record record = recs[0];
if ((record instanceof UnknownRecord)
&& !dump) // if we didn't already dump
{ // just cause dump was on and we're hit an unknow
// record hex dump it!
System.out.println(
"-----UNKNOWN----------------------------------");
if (data.length > 0)
{
HexDump.dump(data, 0, System.out, 0);
}
else
{
System.out.print("**NO RECORD DATA**");
}
System.out.println();
System.out.println(
"-----UNKNOWN----------------------------------");
dumpUnknownRecord(data);
}
if (record != null)
{
if (rectype == ContinueRecord.sid)
{
dumpContinueRecord(last_record, dump, data);
} else
{
last_record = record;
records.add(record);
}
}
}
} while (rectype != 0);
} catch (IOException e)
{
throw new RecordFormatException("Error reading bytes");
}
Record[] retval = new Record[records.size()];
retval = (Record[]) records.toArray(retval);
return retval;
}
private static void dumpContinueRecord(Record last_record, boolean dump, byte[] data) throws IOException
{
if (last_record == null)
{
@ -261,25 +235,44 @@ public class BiffViewer
"-----CONTINUED----------------------------------");
}
}
else
{
last_record = record;
records.add(record);
}
}
}
}
}
while (rectype != 0);
}
catch (IOException e)
{
throw new RecordFormatException("Error reading bytes");
}
Record[] retval = new Record[ records.size() ];
retval = ( Record [] ) records.toArray(retval);
return retval;
private static void dumpUnknownRecord(byte[] data) throws IOException
{
// record hex dump it!
System.out.println(
"-----UNKNOWN----------------------------------");
if (data.length > 0)
{
HexDump.dump(data, 0, System.out, 0);
} else
{
System.out.print("**NO RECORD DATA**");
}
System.out.println();
System.out.println(
"-----UNKNOWN----------------------------------");
}
private static void dump(short rectype, short recsize, byte[] data) throws IOException
{
// System.out
// .println("fixing to recordize the following");
System.out.print("rectype = 0x"
+ Integer.toHexString(rectype));
System.out.println(", recsize = 0x"
+ Integer.toHexString(recsize));
System.out.println(
"-BEGIN DUMP---------------------------------");
if (data.length > 0)
{
HexDump.dump(data, 0, System.out, 0);
} else
{
System.out.println("**NO RECORD DATA**");
}
// System.out.println();
System.out.println(
"-END DUMP-----------------------------------");
}
/**
@ -699,13 +692,11 @@ public class BiffViewer
stream.read(data);
HexDump.dump(data, 0, System.out, 0);
}
else
} else
{
viewer.run();
}
}
catch (Exception e)
} catch (Exception e)
{
e.printStackTrace();
}