myInputStream = dataReferenceStack.pop().createInputStream();
long parentDirectoryUniqueId = BinaryTools.readUInt64AsLong(myInputStream);
myInputStream.close();
myInputStream = null;
FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();
parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagLocation =
myExtendedFileEntry.DescriptorTag.TagLocation;
parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = tagSerialNumber;
parentDirectoryFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;
parentDirectoryFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.part_num = partitionToStoreMetadataOn;
parentDirectoryFileIdentifierDescriptor.FileVersionNumber = 1;
parentDirectoryFileIdentifierDescriptor.FileCharacteristics = 10; // file is directory and parent
parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.lb_num = parentDirectoryLocation;
parentDirectoryFileIdentifierDescriptor.ICB.implementationUse = new byte[6];
parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[2] = (byte) (parentDirectoryUniqueId & 0xFF);
parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[3] =
(byte) ((parentDirectoryUniqueId >> 8) & 0xFF);
parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[4] =
(byte) ((parentDirectoryUniqueId >> 16) & 0xFF);
parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[5] =
(byte) ((parentDirectoryUniqueId >> 32) & 0xFF);
childFileIdentifierDescriptors.add(parentDirectoryFileIdentifierDescriptor);
myInputStream = dataReferenceStack.pop().createInputStream();
int numberOfChildFiles = (int) BinaryTools.readUInt32AsLong(myInputStream);
myInputStream.close();
myInputStream = null;
// build file identifier descriptor elements for child files
for (int i = 0; i < numberOfChildFiles; ++i) {
myInputStream = dataReferenceStack.pop().createInputStream();
int childFileType = (int) BinaryTools.readUInt32AsLong(myInputStream);
myInputStream.close();
myInputStream = null;
DataReference myDataReference = dataReferenceStack.pop();
myInputStream = myDataReference.createInputStream();
String childFileIdentifier =
new String(BinaryTools.readByteArray(myInputStream, (int) myDataReference.getLength()));
myInputStream.close();
myInputStream = null;
myInputStream = dataReferenceStack.pop().createInputStream();
long childFileLocation = BinaryTools.readUInt32AsLong(myInputStream);
myInputStream.close();
myInputStream = null;
myInputStream = dataReferenceStack.pop().createInputStream();
long childFileUniqueId = BinaryTools.readUInt64AsLong(myInputStream);
myInputStream.close();
myInputStream = null;
FileIdentifierDescriptor childFileIdentifierDescriptor = new FileIdentifierDescriptor();
childFileIdentifierDescriptor.DescriptorTag.TagLocation = myExtendedFileEntry.DescriptorTag.TagLocation;
childFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = tagSerialNumber;
childFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;
childFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
childFileIdentifierDescriptor.ICB.ExtentLocation.lb_num = childFileLocation;
childFileIdentifierDescriptor.ICB.ExtentLocation.part_num = partitionToStoreMetadataOn;
childFileIdentifierDescriptor.ICB.implementationUse = new byte[6];
childFileIdentifierDescriptor.ICB.implementationUse[2] = (byte) (childFileUniqueId & 0xFF);
childFileIdentifierDescriptor.ICB.implementationUse[3] = (byte) ((childFileUniqueId >> 8) & 0xFF);
childFileIdentifierDescriptor.ICB.implementationUse[4] = (byte) ((childFileUniqueId >> 16) & 0xFF);
childFileIdentifierDescriptor.ICB.implementationUse[5] = (byte) ((childFileUniqueId >> 32) & 0xFF);
childFileIdentifierDescriptor.FileVersionNumber = 1;
try {
childFileIdentifierDescriptor.setFileIdentifier(childFileIdentifier);
}
catch (Exception myException) {
throw new HandlerException(myException);
}
if (childFileType == 1) // directory
{
childFileIdentifierDescriptor.FileCharacteristics = 2;
}
childFileIdentifierDescriptors.add(childFileIdentifierDescriptor);
}
}
catch (IOException myIOException) {
throw new HandlerException(myIOException);
}
finally {
if (myInputStream != null) {
try {
myInputStream.close();
}
catch (IOException myIOException) {
}
}
}
// get directory file data length
int directoryFileDataLength = 0;
for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
directoryFileDataLength += childFileIdentifierDescriptors.get(i).getLength();
}
myExtendedFileEntry.InformationLength = directoryFileDataLength;
myExtendedFileEntry.ObjectSize = myExtendedFileEntry.InformationLength;
if (directoryFileDataLength <= blockSize - ExtendedFileEntry.fixedPartLength) {
// inline embedded file data
myExtendedFileEntry.ICBTag.Flags = 3; // storage type inline
myExtendedFileEntry.LogicalBlocksRecorded = 0;
myExtendedFileEntry.LengthofAllocationDescriptors = directoryFileDataLength;
myExtendedFileEntry.AllocationDescriptors = new byte[directoryFileDataLength];
int pos = 0;
for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
byte childFileIdentifierDescriptorBytes[] = childFileIdentifierDescriptors.get(i).getBytes();
System.arraycopy(childFileIdentifierDescriptorBytes, 0, myExtendedFileEntry.AllocationDescriptors, pos,
childFileIdentifierDescriptorBytes.length);
pos += childFileIdentifierDescriptorBytes.length;
}
/*
// full element with descriptor tag
super.data( new ByteArrayDataReference( myExtendedFileEntry.getBytes( blockSize ) ) );
*/
// without descriptor tag (handled in next pipeline section)
super.startElement(new SabreUDFElement(SabreUDFElement.UDFElementType.DescriptorTag));
super.data(new WordDataReference(266)); // tag identifier
super.data(new WordDataReference(myExtendedFileEntry.DescriptorTag.TagLocation)); // tag location
super.data(
new WordDataReference(tagSerialNumber)); // tag serial number
super.data(
new WordDataReference(descriptorVersion)); // descriptor version
super.data(new ByteArrayDataReference(myExtendedFileEntry.getBytesWithoutDescriptorTag()));
super.endElement();
} else {
// store as exernal file data with Short_ad
myExtendedFileEntry.ICBTag.Flags = 0; // storage type short_ad
myExtendedFileEntry.LogicalBlocksRecorded = (long) (directoryFileDataLength / blockSize);
if (directoryFileDataLength % blockSize != 0) {
myExtendedFileEntry.LogicalBlocksRecorded++;
}
Short_ad allocationDescriptor = new Short_ad();
allocationDescriptor.ExtentLength = directoryFileDataLength;
allocationDescriptor.ExtentPosition = dataLocation;
if (directoryFileDataLength % blockSize != 0) {
directoryFileDataLength += blockSize - (directoryFileDataLength % blockSize);
}
byte[] data = new byte[directoryFileDataLength];
long currentRealPosition = dataLocation * blockSize;
int pos = 0;
for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
long tagLocationBlock = (long) (currentRealPosition / blockSize);
FileIdentifierDescriptor childFileIdentifierDescriptor = childFileIdentifierDescriptors.get(i);
childFileIdentifierDescriptor.DescriptorTag.TagLocation = tagLocationBlock;
byte childFileIdentifierDescriptorBytes[] = childFileIdentifierDescriptors.get(i).getBytes();