org.jaudiotagger.audio.asf.io
Class ChunkContainerReader<ChunkType extends ChunkContainer>

java.lang.Object
  extended by org.jaudiotagger.audio.asf.io.ChunkContainerReader<ChunkType>
Type Parameters:
ChunkType - The ChunkContainer instance, the implementation will create.
All Implemented Interfaces:
ChunkReader
Direct Known Subclasses:
AsfExtHeaderReader, AsfHeaderReader

abstract class ChunkContainerReader<ChunkType extends ChunkContainer>
extends java.lang.Object
implements ChunkReader

This class represents a reader implementation, which is able to read ASF objects (chunks) which store other objects (chunks) within them.

Author:
Christian Laireiter

Field Summary
protected  boolean eachChunkOnce
          If true each chunk type will only be read once.
protected  boolean hasFailingReaders
          If true due to a registered chunk reader, all InputStream objects passed to read(GUID, InputStream, long) must support mark/reset.
protected static java.util.logging.Logger LOGGER
          Logger
static int READ_LIMIT
          Within this range, a ChunkReader should be aware if it fails.
protected  java.util.Map<GUID,ChunkReader> readerMap
          Registers GUIDs to their reader classes.
 
Constructor Summary
protected ChunkContainerReader(java.util.List<java.lang.Class<? extends ChunkReader>> toRegister, boolean readChunkOnce)
          Creates a reader instance, which only utilizes the given list of chunk readers.
 
Method Summary
protected  void checkStream(java.io.InputStream stream)
          Checks for the constraints of this class.
protected abstract  ChunkType createContainer(long streamPosition, java.math.BigInteger chunkLength, java.io.InputStream stream)
          This method is called by read(GUID, InputStream, long) in order to create the resulting object.
protected  ChunkReader getReader(GUID guid)
          Gets a configured reader instance for ASF objects (chunks) with the specified guid.
protected  boolean isReaderAvailable(GUID guid)
          Tests whether getReader(GUID) won't return null.
 ChunkType read(GUID guid, java.io.InputStream stream, long chunkStart)
          This Method implements the reading of a chunk container.
private
<T extends ChunkReader>
void
register(java.lang.Class<T> toRegister)
          Registers the given reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.audio.asf.io.ChunkReader
canFail, getApplyingIds
 

Field Detail

LOGGER

protected static final java.util.logging.Logger LOGGER
Logger


READ_LIMIT

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

See Also:
Constant Field Values

eachChunkOnce

protected final boolean eachChunkOnce
If true each chunk type will only be read once.


hasFailingReaders

protected boolean hasFailingReaders
If true due to a registered chunk reader, all InputStream objects passed to read(GUID, InputStream, long) must support mark/reset.


readerMap

protected final java.util.Map<GUID,ChunkReader> readerMap
Registers GUIDs to their reader classes.

Constructor Detail

ChunkContainerReader

protected ChunkContainerReader(java.util.List<java.lang.Class<? extends ChunkReader>> toRegister,
                               boolean readChunkOnce)
Creates a reader instance, which only utilizes the given list of chunk readers.

Parameters:
toRegister - List of ChunkReader class instances, which are to be utilized by the instance.
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

checkStream

protected void checkStream(java.io.InputStream stream)
                    throws java.lang.IllegalArgumentException
Checks for the constraints of this class.

Parameters:
stream - stream to test.
Throws:
java.lang.IllegalArgumentException - If stream does not meet the requirements.

createContainer

protected abstract ChunkType createContainer(long streamPosition,
                                             java.math.BigInteger chunkLength,
                                             java.io.InputStream stream)
                                                             throws java.io.IOException
This method is called by 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)

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.

getReader

protected ChunkReader getReader(GUID guid)
Gets a configured reader instance for ASF objects (chunks) with the specified guid.

Parameters:
guid - GUID which identifies the chunk to be read.
Returns:
an appropriate reader implementation, null if not registered.

isReaderAvailable

protected boolean isReaderAvailable(GUID guid)
Tests whether getReader(GUID) won't return null.

Parameters:
guid - GUID which identifies the chunk to be read.
Returns:
true if a reader is available.

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.

register

private <T extends ChunkReader> void register(java.lang.Class<T> toRegister)
Registers the given reader.

Type Parameters:
T - The actual reader implementation.
Parameters:
toRegister - chunk reader which is to be registered.