@Override
public NTFSAttribute next() {
Set<Integer> encounteredIds = new HashSet<Integer>();
while (entryIterator.hasNext()) {
AttributeListEntry entry = entryIterator.next();
// Sanity check - ensure we don't hit the same ID more than once
int attributeId = entry.getAttributeID();
if (encounteredIds.contains(attributeId)) {
throw new IllegalStateException("Hit the same attribute ID more than once, aborting. ref = 0x" +
Long.toHexString(entry.getFileReferenceNumber()) + " id=" + attributeId);
}
encounteredIds.add(attributeId);
try {
// If it's resident (i.e. in the current file record) then we don't need to
// look it up, and doing so would risk infinite recursion.
FileRecord holdingRecord;
if (entry.getFileReferenceNumber() == referenceNumber) {
holdingRecord = FileRecord.this;
} else {
log.debug("Looking up MFT entry for: " + entry.getFileReferenceNumber());
holdingRecord = getVolume().getMFT().getRecord(entry.getFileReferenceNumber());
}
NTFSAttribute attribute = holdingRecord.findStoredAttributeByID(entry.getAttributeID());
log.debug("Attribute: " + attribute);
return attribute;
} catch (IOException e) {
throw new IllegalStateException("Error getting MFT or FileRecord for attribute in list, ref = 0x" +
Long.toHexString(entry.getFileReferenceNumber()), e);
}
}
return null;
}