* containing all supported data.
* @throws IOException
* Read errors.
*/
private AsfHeader parseData(RandomAccessFile in) throws IOException {
AsfHeader result = null;
long chunkStart = in.getFilePointer();
GUID possibleGuid = Utils.readGUID(in);
if (GUID.GUID_HEADER.equals(possibleGuid)) {
// For Know the filepointer pointed to an ASF header chunk.
BigInteger chunkLen = Utils.readBig64(in);
long chunkCount = Utils.readUINT32(in);
// They are of unknown use.
in.skipBytes(2);
/*
* Now reading header of chuncks.
*/
ArrayList chunks = new ArrayList();
while (chunkLen.compareTo(BigInteger.valueOf(in.getFilePointer())) > 0) {
Chunk chunk = ChunkHeaderReader.readChunckHeader(in);
chunks.add(chunk);
in.seek(chunk.getChunckEnd());
}
/*
* Creating the resulting object because streamchunks will be added.
*/
result = new AsfHeader(chunkStart, chunkLen, chunkCount);
/*
* Now we know all positions and guids of chunks which are contained
* whithin asf header. Further we need to identify the type of those
* chunks and parse the interesting ones.
*/
FileHeader fileHeader = null;
ExtendedContentDescription extendedDescription = null;
EncodingChunk encodingChunk = null;
StreamChunk streamChunk = null;
ContentDescription contentDescription = null;
StreamBitratePropertiesChunk bitratePropertiesChunk = null;
Iterator iterator = chunks.iterator();
while (iterator.hasNext()) {
Chunk currentChunk = (Chunk) iterator.next();
if (fileHeader == null
&& (fileHeader = FileHeaderReader
.read(in, currentChunk)) != null) {
continue;
}
if (extendedDescription == null
&& (extendedDescription = ExtContentDescReader.read(in,
currentChunk)) != null) {
continue;
}
if (encodingChunk == null
&& (encodingChunk = EncodingChunkReader.read(in,
currentChunk)) != null) {
continue;
}
if (streamChunk == null
&& (streamChunk = StreamChunkReader.read(in,
currentChunk)) != null) {
result.addStreamChunk(streamChunk);
streamChunk = null;
continue;
}
if (contentDescription == null
&& (contentDescription = ContentDescriptionReader.read(
in, currentChunk)) != null) {
continue;
}
if (bitratePropertiesChunk == null
&& (bitratePropertiesChunk = StreamBitratePropertiesReader
.read(in, currentChunk)) != null) {
continue;
}
/*
* If none of the above statements executed the "continue", this
* chunk couldn't be interpreted. Despite this the chunk is
* remembered
*/
result.addUnspecifiedChunk(currentChunk);
}
/*
* Finally store the parsed chunks in the resulting ASFHeader
* object.
*/
result.setFileHeader(fileHeader);
result.setEncodingChunk(encodingChunk);
/*
* Warning, extendedDescription, contentDescription and
* bitratePropertiesChunk maybe null since they are optional fields.
*/
result.setExtendedContentDescription(extendedDescription);
result.setContentDescription(contentDescription);
result.setStreamBitratePropertiesChunk(bitratePropertiesChunk);
}
return result;
}