org.jaudiotagger.audio.asf.io
Class AsfHeaderReader

java.lang.Object
  extended by org.jaudiotagger.audio.asf.io.ChunkContainerReader<AsfHeader>
      extended by org.jaudiotagger.audio.asf.io.AsfHeaderReader
All Implemented Interfaces:
ChunkReader

public class AsfHeaderReader
extends ChunkContainerReader<AsfHeader>

This class reads an ASF header out of an input stream an creates an AsfHeader object if successful.
For now only ASF ver 1.0 is supported, because ver 2.0 seems not to be used anywhere.
ASF headers contains other chunks. As of this other readers of current package are called from within.

Author:
Christian Laireiter

Field Summary
private static GUID[] APPLYING
          The GUID this reader applies to
private static AsfHeaderReader FULL_READER
          ASF reader configured to extract all information.
private static AsfHeaderReader INFO_READER
          ASF reader configured to just extract information about audio streams.
If the ASF file only contains one audio stream it works fine.
private static AsfHeaderReader TAG_READER
          ASF reader configured to just extract metadata information.
 
Fields inherited from class org.jaudiotagger.audio.asf.io.ChunkContainerReader
eachChunkOnce, hasFailingReaders, LOGGER, READ_LIMIT, readerMap
 
Constructor Summary
AsfHeaderReader(java.util.List<java.lang.Class<? extends ChunkReader>> toRegister, boolean readChunkOnce)
          Creates an instance of this reader.
 
Method Summary
 boolean canFail()
          Tells whether the reader can fail to return a valid chunk.
The current Use would be a modified version of StreamChunkReader, which is configured to only manage audio streams.
protected  AsfHeader createContainer(long streamPosition, java.math.BigInteger chunkLength, java.io.InputStream stream)
          This method is called by ChunkContainerReader.read(GUID, InputStream, long) in order to create the resulting object.
private static java.io.InputStream createStream(java.io.RandomAccessFile raf)
          Creates a Stream that will read from the specified RandomAccessFile;
 GUID[] getApplyingIds()
          Returns the GUIDs identifying the types of chunk, this reader will parse.
static AsfHeader readHeader(java.io.File file)
          This method extracts the full ASF-Header from the given file.
If no header could be extracted null is returned.
static AsfHeader readHeader(java.io.RandomAccessFile file)
          This method tries to extract a full ASF-header out of the given stream.
static AsfHeader readInfoHeader(java.io.RandomAccessFile file)
          This method tries to extract an ASF-header out of the given stream, which only contains information about the audio stream.
If no header could be extracted null is returned.
static AsfHeader readTagHeader(java.io.RandomAccessFile file)
          This method tries to extract an ASF-header out of the given stream, which only contains metadata.
If no header could be extracted null is returned.
 void setExtendedHeaderReader(AsfExtHeaderReader extReader)
          Sets the AsfExtHeaderReader, which is to be used, when an header extension object is found.
 
Methods inherited from class org.jaudiotagger.audio.asf.io.ChunkContainerReader
checkStream, getReader, isReaderAvailable, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLYING

private static final GUID[] APPLYING
The GUID this reader applies to


FULL_READER

private static final AsfHeaderReader FULL_READER
ASF reader configured to extract all information.


INFO_READER

private static final AsfHeaderReader INFO_READER
ASF reader configured to just extract information about audio streams.
If the ASF file only contains one audio stream it works fine.


TAG_READER

private static final AsfHeaderReader TAG_READER
ASF reader configured to just extract metadata information.

Constructor Detail

AsfHeaderReader

public AsfHeaderReader(java.util.List<java.lang.Class<? extends ChunkReader>> toRegister,
                       boolean readChunkOnce)
Creates an instance of this reader.

Parameters:
toRegister - The chunk readers to utilize.
readChunkOnce - if true, each chunk type (identified by chunk GUID) will handled only once, if a reader is available, other chunks will be discarded.
Method Detail

createStream

private static java.io.InputStream createStream(java.io.RandomAccessFile raf)
Creates a Stream that will read from the specified RandomAccessFile;

Parameters:
raf - data source to read from.
Returns:
a stream which accesses the source.

readHeader

public static AsfHeader readHeader(java.io.File file)
                            throws java.io.IOException
This method extracts the full ASF-Header from the given file.
If no header could be extracted null is returned.

Parameters:
file - the ASF file to read.
Returns:
AsfHeader-Wrapper, or null if no supported ASF header was found.
Throws:
java.io.IOException - on I/O Errors.

readHeader

public static AsfHeader readHeader(java.io.RandomAccessFile file)
                            throws java.io.IOException
This method tries to extract a full ASF-header out of the given stream.
If no header could be extracted null is returned.

Parameters:
file - File which contains the ASF header.
Returns:
AsfHeader-Wrapper, or null if no supported ASF header was found.
Throws:
java.io.IOException - Read errors

readInfoHeader

public static AsfHeader readInfoHeader(java.io.RandomAccessFile file)
                                throws java.io.IOException
This method tries to extract an ASF-header out of the given stream, which only contains information about the audio stream.
If no header could be extracted null is returned.

Parameters:
file - File which contains the ASF header.
Returns:
AsfHeader-Wrapper, or null if no supported ASF header was found.
Throws:
java.io.IOException - Read errors

readTagHeader

public static AsfHeader readTagHeader(java.io.RandomAccessFile file)
                               throws java.io.IOException
This method tries to extract an ASF-header out of the given stream, which only contains metadata.
If no header could be extracted null is returned.

Parameters:
file - File which contains the ASF header.
Returns:
AsfHeader-Wrapper, or null if no supported ASF header was found.
Throws:
java.io.IOException - Read errors

canFail

public boolean canFail()
Tells whether the reader can fail to return a valid chunk.
The current Use would be a modified version of StreamChunkReader, which is configured to only manage audio streams. However, the primary GUID for audio and video streams is the same. So if a stream shows itself to be a video stream, the reader would return null.

Returns:
true, if further analysis of the chunk can show, that the reader is not applicable, despite the header GUID identification told it can handle the chunk.

createContainer

protected AsfHeader createContainer(long streamPosition,
                                    java.math.BigInteger chunkLength,
                                    java.io.InputStream stream)
                             throws java.io.IOException
This method is called by ChunkContainerReader.read(GUID, InputStream, long) in order to create the resulting object. Implementations of this class should now return a new instance of their implementation specific result AND all data should be read, until the list of chunks starts. (The Chunk.getChunkEnd() must return a sane result, too)

Specified by:
createContainer in class ChunkContainerReader<AsfHeader>
Parameters:
streamPosition - position of the stream, the chunk starts.
chunkLength - the length of the chunk (from chunk header)
stream - to read the implementation specific information.
Returns:
instance of the implementations result.
Throws:
java.io.IOException - On I/O Errors and Invalid data.

getApplyingIds

public GUID[] getApplyingIds()
Returns the GUIDs identifying the types of chunk, this reader will parse.

Returns:
the GUIDs identifying the types of chunk, this reader will parse.

setExtendedHeaderReader

public void setExtendedHeaderReader(AsfExtHeaderReader extReader)
Sets the AsfExtHeaderReader, which is to be used, when an header extension object is found.

Parameters:
extReader - header extension object reader.