public static Record[] createRecords(InputStream in) throws RecordFormatException {
ArrayList records = new ArrayList(NUM_RECORDS);
Record last_record = null;
int loc = 0;
try
{
long offset = 0;
short rectype = 0;
do
{
// System.out.println("you are at offset "+loc);
rectype = LittleEndian.readShort(in);
loc += 2;
if (rectype != 0)
{
short recsize = LittleEndian.readShort(in);
byte[] data = new byte[ ( int ) recsize ];
in.read(data);
loc += recsize;
// System.out.println("TYPE: "
// + Integer.toHexString(rectype));
// System.out.println("SIZE: "
// + Integer.toHexString(recsize));
// HexDump.dump(data, offset + 4, System.out, 0);
offset += 4 + recsize;
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 != null)
{
if (rectype == ContinueRecord.sid)
{
if (last_record == null)
{
throw new RecordFormatException(
"First record is a ContinueRecord??");
}
last_record.processContinueRecord(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;
}
Create an array of records from an input stream |