org.jaudiotagger.audio.asf.io
Class AsfHeaderReader

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

public class AsfHeaderReader
extends java.lang.Object

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
static int READ_LIMIT
          Within this range, a ChunkReader should be aware if it fails.
 
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.
 GUID getApplyingId()
          Returns the GUID identifying the type of chunk, this reader will parse.
 ChunkType read(GUID guid, java.io.InputStream stream, long chunkStart)
          This Method implements the reading of a chunk container.
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 in)
          This method tries to extract a full ASF-header out of the given stream.
static AsfHeader readInfoHeader(java.io.RandomAccessFile in)
          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 in)
          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 java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_LIMIT

public static final int READ_LIMIT
Within this range, a ChunkReader should be aware if it fails.

See Also:
Constant Field Values
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

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 in)
                            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:
in - 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 in)
                                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:
in - 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 in)
                               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:
in - File which contains the ASF header.
Returns:
AsfHeader-Wrapper, or null if no supported Asf header was found.
Throws:
java.io.IOException - Read errors

getApplyingId

public GUID getApplyingId()
Returns the GUID identifying the type of chunk, this reader will parse.

Returns:
the GUID identifying the type 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.

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.

Specified by:
canFail in interface ChunkReader
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.

read

public ChunkType read(GUID guid,
                      java.io.InputStream stream,
                      long chunkStart)
                                      throws java.io.IOException,
                                             java.lang.IllegalArgumentException
This Method implements the reading of a chunk container.

Specified by:
read in interface ChunkReader
Parameters:
guid - GUID of the currently read container.
stream - Stream which contains the chunk container.
chunkStart - The start of the chunk container from stream start.
For direct file streams one can assume 0 here.
Returns:
null if no valid data found, else a Wrapper containing all supported data.
Throws:
java.io.IOException - Read errors.
java.lang.IllegalArgumentException - If one used ChunkReader could fail and the stream source doesn't support mark/reset.