org.jaudiotagger.audio.asf.data
Class ChunkContainer

java.lang.Object
  extended by org.jaudiotagger.audio.asf.data.Chunk
      extended by org.jaudiotagger.audio.asf.data.ChunkContainer
Direct Known Subclasses:
AsfExtendedHeader, AsfHeader

public class ChunkContainer
extends Chunk

Stores multiple ASF objects (chunks) in form of Chunk objects, and is itself an ASF object (chunk).

Because current implementation is solely used for ASF metadata, all chunks (except for StreamChunk) may only be inserted once.

Author:
Christian Laireiter

Field Summary
private  java.util.Map<GUID,java.util.List<Chunk>> chunkTable
          Stores the Chunk objects to their GUID.
private static java.util.Set<GUID> MULTI_CHUNKS
          Stores the GUID instances, which are allowed multiple times within an ASF header.
 
Fields inherited from class org.jaudiotagger.audio.asf.data.Chunk
chunkLength, guid, position
 
Constructor Summary
ChunkContainer(GUID chunkGUID, long pos, java.math.BigInteger length)
          Creates an instance.
 
Method Summary
 void addChunk(Chunk toAdd)
          Adds a chunk to the container.
protected  java.util.List<Chunk> assertChunkList(GUID lookFor)
          This method asserts that a List exists for the given GUID , in chunkTable.
protected static boolean chunkstartsUnique(ChunkContainer container)
          Tests whether all stored chunks have a unique starting position among their brothers.
 java.util.Collection<Chunk> getChunks()
          Returns a collection of all contained chunks.
protected  Chunk getFirst(GUID lookFor, java.lang.Class<? extends Chunk> instanceOf)
          Looks for the first stored chunk which has the given GUID.
 boolean hasChunkByGUID(GUID lookFor)
          This method checks if a chunk has been added with specified GUID.
 java.lang.String prettyPrint(java.lang.String prefix)
          This method creates a String containing useful information prepared to be printed on STD-OUT.
 java.lang.String prettyPrint(java.lang.String prefix, java.lang.String containerInfo)
          Nearly the same as prettyPrint(String) however, additional information can be injected below the Chunk.prettyPrint(String) output and the listing of the contained chunks.
 
Methods inherited from class org.jaudiotagger.audio.asf.data.Chunk
getChunckEnd, getChunkEnd, getChunkLength, getGuid, getPosition, setPosition, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MULTI_CHUNKS

private static final java.util.Set<GUID> MULTI_CHUNKS
Stores the GUID instances, which are allowed multiple times within an ASF header.


chunkTable

private final java.util.Map<GUID,java.util.List<Chunk>> chunkTable
Stores the Chunk objects to their GUID.

Constructor Detail

ChunkContainer

public ChunkContainer(GUID chunkGUID,
                      long pos,
                      java.math.BigInteger length)
Creates an instance.

Parameters:
chunkGUID - the GUID which identifies the chunk.
pos - the position of the chunk within the stream.
length - the length of the chunk.
Method Detail

chunkstartsUnique

protected static boolean chunkstartsUnique(ChunkContainer container)
Tests whether all stored chunks have a unique starting position among their brothers.

Parameters:
container - the container to test.
Returns:
true if all chunks are located at an unique position. However, no intersection is tested.

addChunk

public void addChunk(Chunk toAdd)
Adds a chunk to the container.

Parameters:
toAdd - The chunk which is to be added.
Throws:
java.lang.IllegalArgumentException - If a chunk of same type is already added, except for StreamChunk.

assertChunkList

protected java.util.List<Chunk> assertChunkList(GUID lookFor)
This method asserts that a List exists for the given GUID , in chunkTable.

Parameters:
lookFor - The GUID to get list for.
Returns:
an already existing, or newly created list.

getChunks

public java.util.Collection<Chunk> getChunks()
Returns a collection of all contained chunks.

Returns:
all contained chunks

getFirst

protected Chunk getFirst(GUID lookFor,
                         java.lang.Class<? extends Chunk> instanceOf)
Looks for the first stored chunk which has the given GUID.

Parameters:
lookFor - GUID to look up.
instanceOf - The class which must additionally be matched.
Returns:
null if no chunk was found, or the stored instance doesn't match.

hasChunkByGUID

public boolean hasChunkByGUID(GUID lookFor)
This method checks if a chunk has been added with specified GUID.

Parameters:
lookFor - GUID to look up.
Returns:
true if chunk with specified GUID has been added.

prettyPrint

public java.lang.String prettyPrint(java.lang.String prefix)
This method creates a String containing useful information prepared to be printed on STD-OUT.
This method is intended to be overwritten by inheriting classes.

Overrides:
prettyPrint in class Chunk
Parameters:
prefix - each line gets this string prepended.
Returns:
Information of current Chunk Object.

prettyPrint

public java.lang.String prettyPrint(java.lang.String prefix,
                                    java.lang.String containerInfo)
Nearly the same as prettyPrint(String) however, additional information can be injected below the Chunk.prettyPrint(String) output and the listing of the contained chunks.

Parameters:
prefix - The prefix to prepend.
containerInfo - Information to inject.
Returns:
Information of current Chunk Object.