Package com.github.stephenc.javaisotools.udflib.structures

Examples of com.github.stephenc.javaisotools.udflib.structures.FileIdentifierDescriptor


            ArrayList<FileIdentifierDescriptor> childFileIdentifierDescriptors =
                    new ArrayList<FileIdentifierDescriptor>();

            // parent directory FID
            FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();

            parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagLocation = currentBlock - partitionStartingBlock;
            parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = serialNumberForTags;
            parentDirectoryFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;

            parentDirectoryFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
            parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.part_num = 0;

            parentDirectoryFileIdentifierDescriptor.FileVersionNumber = 1;
            parentDirectoryFileIdentifierDescriptor.FileCharacteristics = 10; // file is directory and parent

            // if root directory
            if (parentFileEntry == null) {
                parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.lb_num =
                        currentBlock - partitionStartingBlock;
            }
            // if non root directory
            else {
                parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.lb_num =
                        parentFileEntry.DescriptorTag.TagLocation;

                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse = new byte[6];
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[2] =
                        (byte) (parentFileEntry.UniqueID & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[3] =
                        (byte) ((parentFileEntry.UniqueID >> 8) & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[4] =
                        (byte) ((parentFileEntry.UniqueID >> 16) & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[5] =
                        (byte) ((parentFileEntry.UniqueID >> 32) & 0xFF);
            }

            childFileIdentifierDescriptors.add(parentDirectoryFileIdentifierDescriptor);

            // child file FIDs
            for (int i = 0; i < childUDFImageBuilderFiles.length; ++i) {
                long childFileUniqueID = myUniqueIdDisposer.getNextUniqueId();

                FileIdentifierDescriptor childFileIdentifierDescriptor = new FileIdentifierDescriptor();

                childFileIdentifierDescriptor.DescriptorTag.TagLocation = currentBlock - partitionStartingBlock;
                childFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = serialNumberForTags;
                childFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;

                childFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
                childFileIdentifierDescriptor.ICB.ExtentLocation.lb_num = nextFreeBlock - partitionStartingBlock;
                childFileIdentifierDescriptor.ICB.ExtentLocation.part_num = 0;

                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;

                childFileIdentifierDescriptor.setFileIdentifier(childUDFImageBuilderFiles[i].getIdentifier());

                if (childUDFImageBuilderFiles[i].getFileType() == UDFImageBuilderFile.FileType.Directory) {
                    childFileIdentifierDescriptor.FileCharacteristics = 2;
                }

                childFileIdentifierDescriptors.add(childFileIdentifierDescriptor);

                nextFreeBlock = recursiveWriteFilesystem(myRandomAccessFile, partitionStartingBlock, blockSize,
                        serialNumberForTags, childUDFImageBuilderFiles[i], nextFreeBlock, myFileEntry,
                        childFileUniqueID, writeExtendedFileEntries, descriptorVersion);
            }

            // get directory file data length
            int directoryFileDataLength = 0;
            for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
                directoryFileDataLength += childFileIdentifierDescriptors.get(i).getLength();
            }

            myFileEntry.InformationLength = directoryFileDataLength;

            if ((writeExtendedFileEntries && directoryFileDataLength <= blockSize - ExtendedFileEntry.fixedPartLength)
                    ||
                    (!writeExtendedFileEntries && directoryFileDataLength <= blockSize - FileEntry.fixedPartLength)) {
                // inline embedded file data
                myFileEntry.ICBTag.Flags = 3;        // storage type inline
                myFileEntry.LogicalBlocksRecorded = 0;
                myFileEntry.LengthofAllocationDescriptors = directoryFileDataLength;
                myFileEntry.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, myFileEntry.AllocationDescriptors, pos,
                            childFileIdentifierDescriptorBytes.length);
                    pos += childFileIdentifierDescriptorBytes.length;
                }
            } else {
                // store as exernal file data with Short_ad
                myFileEntry.ICBTag.Flags = 0;        // storage type short_ad

                myFileEntry.LogicalBlocksRecorded = (long) (directoryFileDataLength / blockSize);
                if (directoryFileDataLength % blockSize != 0) {
                    myFileEntry.LogicalBlocksRecorded++;
                }

                Short_ad allocationDescriptor = new Short_ad();

                allocationDescriptor.ExtentLength = directoryFileDataLength;
                allocationDescriptor.ExtentPosition = nextFreeBlock - partitionStartingBlock;

                long currentRealPosition = nextFreeBlock * blockSize;
                myRandomAccessFile.seek(currentRealPosition);

                for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
                    long tagLocationBlock = (long) (currentRealPosition / blockSize) - partitionStartingBlock;

                    FileIdentifierDescriptor childFileIdentifierDescriptor = childFileIdentifierDescriptors.get(i);

                    childFileIdentifierDescriptor.DescriptorTag.TagLocation = tagLocationBlock;

                    byte childFileIdentifierDescriptorBytes[] = childFileIdentifierDescriptors.get(i).getBytes();
                    myRandomAccessFile.write(childFileIdentifierDescriptorBytes);
View Full Code Here


            ArrayList<FileIdentifierDescriptor> childFileIdentifierDescriptors =
                    new ArrayList<FileIdentifierDescriptor>();

            // parent directory FID
            FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();

            parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagLocation =
                    currentMetadataBlock - metadataPartitionStartingBlock;
            parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = serialNumberForTags;
            parentDirectoryFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;

            parentDirectoryFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
            parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.part_num = 1;

            parentDirectoryFileIdentifierDescriptor.FileVersionNumber = 1;
            parentDirectoryFileIdentifierDescriptor.FileCharacteristics = 10; // file is directory and parent

            // if root directory
            if (parentFileEntry == null) {
                parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.lb_num =
                        currentMetadataBlock - metadataPartitionStartingBlock;
            }
            // if non root directory
            else {
                parentDirectoryFileIdentifierDescriptor.ICB.ExtentLocation.lb_num =
                        parentFileEntry.DescriptorTag.TagLocation;

                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse = new byte[6];
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[2] =
                        (byte) (parentFileEntry.UniqueID & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[3] =
                        (byte) ((parentFileEntry.UniqueID >> 8) & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[4] =
                        (byte) ((parentFileEntry.UniqueID >> 16) & 0xFF);
                parentDirectoryFileIdentifierDescriptor.ICB.implementationUse[5] =
                        (byte) ((parentFileEntry.UniqueID >> 32) & 0xFF);
            }

            childFileIdentifierDescriptors.add(parentDirectoryFileIdentifierDescriptor);

            // child file FIDs
            for (int i = 0; i < childUDFImageBuilderFiles.length; ++i) {
                long childFileUniqueID = myUniqueIdDisposer.getNextUniqueId();

                FileIdentifierDescriptor childFileIdentifierDescriptor = new FileIdentifierDescriptor();

                childFileIdentifierDescriptor.DescriptorTag.TagLocation =
                        currentMetadataBlock - metadataPartitionStartingBlock;
                childFileIdentifierDescriptor.DescriptorTag.TagSerialNumber = serialNumberForTags;
                childFileIdentifierDescriptor.DescriptorTag.DescriptorVersion = descriptorVersion;

                childFileIdentifierDescriptor.ICB.ExtentLength = blockSize;
                childFileIdentifierDescriptor.ICB.ExtentLocation.lb_num =
                        nextFreeBlocks[0] - metadataPartitionStartingBlock;
                childFileIdentifierDescriptor.ICB.ExtentLocation.part_num = 1;

                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;

                childFileIdentifierDescriptor.setFileIdentifier(childUDFImageBuilderFiles[i].getIdentifier());

                if (childUDFImageBuilderFiles[i].getFileType() == UDFImageBuilderFile.FileType.Directory) {
                    childFileIdentifierDescriptor.FileCharacteristics = 2;
                }

                childFileIdentifierDescriptors.add(childFileIdentifierDescriptor);

                nextFreeBlocks = recursiveWriteFilesystemWithMetadata(myRandomAccessFile, partitionStartingBlock,
                        metadataPartitionStartingBlock, blockSize, serialNumberForTags, childUDFImageBuilderFiles[i],
                        nextFreeBlocks[0], nextFreeBlocks[1], myExtendedFileEntry, childFileUniqueID,
                        descriptorVersion);
            }

            // get directory file data length
            int directoryFileDataLength = 0;
            for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
                directoryFileDataLength += childFileIdentifierDescriptors.get(i).getLength();
            }

            myExtendedFileEntry.InformationLength = directoryFileDataLength;

            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;
                }
            } 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 = nextFreeBlocks[0] - metadataPartitionStartingBlock;

                long currentRealPosition = nextFreeBlocks[0] * blockSize;
                myRandomAccessFile.seek(currentRealPosition);

                for (int i = 0; i < childFileIdentifierDescriptors.size(); ++i) {
                    long tagLocationBlock = (long) (currentRealPosition / blockSize) - metadataPartitionStartingBlock;

                    FileIdentifierDescriptor childFileIdentifierDescriptor = childFileIdentifierDescriptors.get(i);

                    childFileIdentifierDescriptor.DescriptorTag.TagLocation = tagLocationBlock;

                    byte childFileIdentifierDescriptorBytes[] = childFileIdentifierDescriptors.get(i).getBytes();
                    myRandomAccessFile.write(childFileIdentifierDescriptorBytes);
View Full Code Here

        {
            long FileIdentifierDescriptorsLength = 0;

            wholeMetadataLengthInBlocks += 1;

            FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();
            FileIdentifierDescriptorsLength += parentDirectoryFileIdentifierDescriptor.getLength();

            UDFImageBuilderFile[] childUDFImageBuilderFiles = myUDFImageBuilderFile.getChilds();

            for (int i = 0; i < childUDFImageBuilderFiles.length; ++i) {
                FileIdentifierDescriptor childFileIdentifierDescriptor = new FileIdentifierDescriptor();
                childFileIdentifierDescriptor.setFileIdentifier(childUDFImageBuilderFiles[i].getIdentifier());
                FileIdentifierDescriptorsLength += childFileIdentifierDescriptor.getLength();

                wholeMetadataLengthInBlocks += recursiveGetMetadataFileLength(childUDFImageBuilderFiles[i], blockSize);
            }

            if (FileIdentifierDescriptorsLength > (blockSize - ExtendedFileEntry.fixedPartLength)) {
View Full Code Here

            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();

View Full Code Here

            }
        } else //if( myUDFImageBuilderFile.getFileType() == UDFImageBuilderFile.FileType.Directory )
        {
            long FileIdentifierDescriptorsLength = 0;

            FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();
            FileIdentifierDescriptorsLength += parentDirectoryFileIdentifierDescriptor.getLength();

            UDFImageBuilderFile[] childUDFImageBuilderFiles = currentUDFImageBuilderFile.getChilds();

            for (int i = 0; i < childUDFImageBuilderFiles.length; ++i) {
                FileIdentifierDescriptor childFileIdentifierDescriptor = new FileIdentifierDescriptor();
                childFileIdentifierDescriptor.setFileIdentifier(childUDFImageBuilderFiles[i].getIdentifier());
                FileIdentifierDescriptorsLength += childFileIdentifierDescriptor.getLength();
            }

            if (((myUDFRevision == UDFRevision.Revision102) &&
                    FileIdentifierDescriptorsLength > (blockSize - FileEntry.fixedPartLength))
                    || (FileIdentifierDescriptorsLength > (blockSize - ExtendedFileEntry.fixedPartLength))) {
View Full Code Here

            myInputStream = dataReferenceStack.pop().createInputStream();
            long parentDirectoryUniqueId = BinaryTools.readUInt64AsLong(myInputStream);
            myInputStream.close();
            myInputStream = null;

            FileIdentifierDescriptor parentDirectoryFileIdentifierDescriptor = new FileIdentifierDescriptor();

            parentDirectoryFileIdentifierDescriptor.DescriptorTag.TagLocation = myFileEntry.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 = myFileEntry.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();
        }

        myFileEntry.InformationLength = directoryFileDataLength;

        if (directoryFileDataLength <= blockSize - ExtendedFileEntry.fixedPartLength) {
            // inline embedded file data
            myFileEntry.ICBTag.Flags = 3;                // storage type inline
            myFileEntry.LogicalBlocksRecorded = 0;
            myFileEntry.LengthofAllocationDescriptors = directoryFileDataLength;
            myFileEntry.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, myFileEntry.AllocationDescriptors, pos,
                        childFileIdentifierDescriptorBytes.length);
                pos += childFileIdentifierDescriptorBytes.length;
            }

            /*
               // full element with descriptor tag
               super.data( new ByteArrayDataReference( myFileEntry.getBytes( blockSize ) ) );
               */

            // without descriptor tag (handled in next pipeline section)
            super.startElement(new SabreUDFElement(SabreUDFElement.UDFElementType.DescriptorTag));
            super.data(new WordDataReference(261));                                                // tag identifier
            super.data(new WordDataReference(myFileEntry.DescriptorTag.TagLocation));            // tag location
            super.data(new WordDataReference(tagSerialNumber));                                    // tag serial number
            super.data(new WordDataReference(descriptorVersion));                                // descriptor version
            super.data(new ByteArrayDataReference(myFileEntry.getBytesWithoutDescriptorTag()));
            super.endElement();
        } else {
            // store as exernal file data with Short_ad
            myFileEntry.ICBTag.Flags = 0;        // storage type short_ad

            myFileEntry.LogicalBlocksRecorded = (long) (directoryFileDataLength / blockSize);
            if (directoryFileDataLength % blockSize != 0) {
                myFileEntry.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();

View Full Code Here

TOP

Related Classes of com.github.stephenc.javaisotools.udflib.structures.FileIdentifierDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.