/// <exception cref="Com.Khubla.Pdxreader.Api.PDXReaderException"/> public static MBTableBlock GetMBTableBlock(MBTableBlock.RecordType recordType) { switch (recordType) { case MBTableBlock.RecordType.header: { return(new MBTableHeaderBlock()); } case MBTableBlock.RecordType.single: { return(new MBSingleBlock()); } case MBTableBlock.RecordType.suballocated: { return(new MBSuballocatedBlock()); } case MBTableBlock.RecordType.free: { return(new MBFreeBlock()); } default: { throw new PDXReaderException("Unknown record type '" + recordType + "'"); } } }
/// <summary>This method finds all the blocks with their types and offsets</summary> /// <exception cref="Com.Khubla.Pdxreader.Api.PDXReaderException"/> private void PreReadBlocks(File file) { try { /* * set up streams */ BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream (file)); LittleEndianDataInputStream littleEndianDataInputStream = new LittleEndianDataInputStream (bufferedInputStream); try { /* * offset tracker */ int fileOffset = 0; /* * loop */ while (littleEndianDataInputStream.Available() > 1) { /* * read type */ int type = littleEndianDataInputStream.ReadByte(); /* * get an appropriate Block type */ MBTableBlock.RecordType recordType = MBTableBlock.GetRecordType(type); /* * ok? */ if (null != recordType) { MBTableBlock mbTableBlock = MBTableBlockFactory.GetMBTableBlock(recordType); /* * set the offset */ mbTableBlock.SetFileOffset(fileOffset); /* * pre-read */ int bytesPreRead = mbTableBlock.PreRead(littleEndianDataInputStream); /* * add to list */ blocks.Add(mbTableBlock); /* * skip forward to next one */ int bytesToSkip = mbTableBlock.GetSizeofBlock() - (1 + bytesPreRead); long skipped = littleEndianDataInputStream.Skip(bytesToSkip); if (0 != skipped) { /* * update the offset */ fileOffset += mbTableBlock.GetSizeofBlock(); } } } } finally { littleEndianDataInputStream.Close(); bufferedInputStream.Close(); } } catch (Exception e) { throw new PDXReaderException("Exception in read", e); } }
public MBTableBlock(MBTableBlock.RecordType recordType) { // Size of block divided by 4k (1 because the header is 4k) this.recordType = recordType; }