/** * A stateless method that will read and parse the RandomIndexPack within a MXF file and return a list of byte offsets * corresponding to the partitions of the MXF file. In a typical IMF workflow this would be the second method after * {@link #getRandomIndexPackSize(PayloadRecord)} that would need to be invoked to perform IMF essence component * level validation * @param randomIndexPackPayload - a payload containing the raw bytes corresponding to the RandomIndexPack of the MXF file * @param randomIndexPackSize - size of the RandomIndexPack of the MXF file * @return list of long integer values representing the byte offsets of the partitions in the MXF file * @throws IOException - any I/O related error is exposed through an IOException */ public static List<Long> getEssencePartitionOffsets(PayloadRecord randomIndexPackPayload, Long randomIndexPackSize) throws IOException { if(randomIndexPackPayload.getPayload().length != randomIndexPackSize){ throw new IllegalArgumentException(String.format("RandomIndexPackSize passed in is = %d, RandomIndexPack payload size = %d, they should be equal", randomIndexPackSize, randomIndexPackPayload.getPayload().length)); } RandomIndexPack randomIndexPack = new RandomIndexPack(new ByteArrayDataProvider(randomIndexPackPayload.getPayload()), 0L, randomIndexPackSize); return randomIndexPack.getAllPartitionByteOffsets(); }
private void setIndexTableSegments(@Nonnull IMFErrorLogger imfErrorLogger) throws IOException { RandomIndexPack randomIndexPack = getRandomIndexPack(imfErrorLogger); List<IndexTableSegment> indexTableSegments = new ArrayList<>(); List<Long> allPartitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets(); int numPartitions = allPartitionByteOffsets.size(); for (int i=0; i<numPartitions -1; i++) { indexTableSegments.addAll(getIndexTableSegments(allPartitionByteOffsets.get(i), allPartitionByteOffsets.get(i+1) -1)); } indexTableSegments.addAll(getIndexTableSegments( allPartitionByteOffsets.get(numPartitions -1), this.resourceByteRangeProvider.getResourceSize() - 1)); this.indexTableSegments = Collections.unmodifiableList(indexTableSegments); }
/** * A method that returns the random index pack in the Essence * @return RandomIndexPack in the essence * @throws IOException - any I/O related error will be exposed through an IOException */ public RandomIndexPack getRandomIndexPack()throws IOException { long archiveFileSize = this.resourceByteRangeProvider.getResourceSize(); long randomIndexPackSize; {//logic to provide as an input stream the portion of the archive that contains randomIndexPack size long rangeEnd = archiveFileSize - 1; long rangeStart = archiveFileSize - 4; File fileWithRandomIndexPackSize = this.resourceByteRangeProvider.getByteRange(rangeStart, rangeEnd, this.workingDirectory); byte[] bytes = Files.readAllBytes(Paths.get(fileWithRandomIndexPackSize.toURI())); randomIndexPackSize = (long)(ByteBuffer.wrap(bytes).getInt()); } RandomIndexPack randomIndexPack; {//logic to provide as an input stream the portion of the archive that contains randomIndexPack long rangeEnd = archiveFileSize - 1; long rangeStart = archiveFileSize - randomIndexPackSize; if (rangeStart < 0) { throw new MXFException(String.format("randomIndexPackSize = %d obtained from last 4 bytes of the MXF file is larger than archiveFile size = %d, implying that this file does not contain a RandomIndexPack", randomIndexPackSize, archiveFileSize)); } File fileWithRandomIndexPack = this.resourceByteRangeProvider.getByteRange(rangeStart, rangeEnd, this.workingDirectory); ByteProvider byteProvider = this.getByteProvider(fileWithRandomIndexPack); randomIndexPack = new RandomIndexPack(byteProvider, rangeStart, randomIndexPackSize); } return randomIndexPack; }
private IMFConstraints.HeaderPartitionIMF getHeaderPartitionIMF(@Nonnull IMFErrorLogger imfErrorLogger) throws IOException { if (this.headerPartition == null) { RandomIndexPack randomIndexPack = getRandomIndexPack(imfErrorLogger); List<Long> allPartitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets(); try { setHeaderPartitionIMF(allPartitionByteOffsets.get(0), allPartitionByteOffsets.get(1) - 1, imfErrorLogger); } catch (IMFException e){ throw new IMFException(String.format("Could not set Header Partition"), imfErrorLogger); } } return this.headerPartition; }
randomIndexPack = new RandomIndexPack(byteProvider, rangeStart, randomIndexPackSize);
randomIndexPack = new RandomIndexPack(byteProvider, rangeStart, randomIndexPackSize); List<Long> partitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets();
/** * A method that returns an object model of the HeaderPartition in the Essence * @return Header partition in the essence * @throws IOException - any I/O related error will be exposed through an IOException */ public HeaderPartition getHeaderPartition() throws IOException{ RandomIndexPack randomIndexPack = this.getRandomIndexPack(); List<Long> allPartitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets(); long inclusiveRangeStart = allPartitionByteOffsets.get(0); long inclusiveRangeEnd = allPartitionByteOffsets.get(1) - 1; File fileWithHeaderPartition = this.resourceByteRangeProvider.getByteRange(inclusiveRangeStart, inclusiveRangeEnd, this.workingDirectory); ByteProvider byteProvider = this.getByteProvider(fileWithHeaderPartition); HeaderPartition headerPartition = new HeaderPartition(byteProvider, inclusiveRangeStart, inclusiveRangeEnd - inclusiveRangeStart + 1, this.imfErrorLogger); return headerPartition; }
private void setPartitionPacks(@Nonnull IMFErrorLogger imfErrorLogger) throws IOException { RandomIndexPack randomIndexPack = getRandomIndexPack(imfErrorLogger); List<PartitionPack> partitionPacks = new ArrayList<>(); List<Long> allPartitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets(); for (long offset : allPartitionByteOffsets) { partitionPacks.add(getPartitionPack(offset)); } try { //validate partition packs MXFOperationalPattern1A.checkOperationalPattern1ACompliance(partitionPacks); IMFConstraints.checkIMFCompliance(partitionPacks, imfErrorLogger); } catch (IMFException | MXFException e){ imfErrorLogger.addError(IMFErrorLogger.IMFErrors.ErrorCodes.IMF_ESSENCE_COMPONENT_ERROR, IMFErrorLogger.IMFErrors.ErrorLevels.FATAL, String.format("This IMFTrackFile has fatal errors in the partition packs, please see the errors that follow.")); if(e instanceof IMFException){ IMFException imfException = (IMFException)e; imfErrorLogger.addAllErrors(imfException.getErrors()); } else if(e instanceof MXFException){ MXFException mxfException = (MXFException)e; imfErrorLogger.addAllErrors(mxfException.getErrors()); } } //add reference to list of partition packs this.partitionPacks = Collections.unmodifiableList(partitionPacks); }
List<Long> allPartitionByteOffsets = randomIndexPack.getAllPartitionByteOffsets(); for (long offset : allPartitionByteOffsets)