com.coremedia.iso.boxes
Class AbstractContainerBox

java.lang.Object
  extended by com.coremedia.iso.boxes.AbstractBox
      extended by com.coremedia.iso.boxes.AbstractContainerBox
All Implemented Interfaces:
Box, ContainerBox
Direct Known Subclasses:
AppleGenericBox, AppleItemListBox, AppleReferenceMovieBox, AppleReferenceMovieDescriptorBox, AppleWaveBox, DataInformationBox, EditBox, IsoFile, MediaBox, MediaInformationBox, MetaBox, MovieBox, MovieExtendsBox, MovieFragmentBox, MovieFragmentRandomAccessBox, ProtectionSchemeInformationBox, SampleTableBox, SchemeInformationBox, TrackBox, TrackFragmentBox, TrackReferenceBox, UserDataBox

public abstract class AbstractContainerBox
extends AbstractBox
implements ContainerBox

Abstract base class suitable for most boxes acting purely as container for other boxes.


Field Summary
protected  List<Box> boxes
           
protected  BoxParser boxParser
           
 
Fields inherited from class com.coremedia.iso.boxes.AbstractBox
deadBytes, type
 
Constructor Summary
AbstractContainerBox(String type)
           
 
Method Summary
 void _parseDetails(ByteBuffer content)
          Implement the actual parsing of the box's fields here.
 void addBox(Box b)
          Add b to the container and sets the parent correctly.
 List<Box> getBoxes()
          Gets all child boxes.
<T extends Box>
List<T>
getBoxes(Class<T> clazz)
          Gets all child boxes of the given type.
<T extends Box>
List<T>
getBoxes(Class<T> clazz, boolean recursive)
          Gets all child boxes of the given type.
protected  void getContent(ByteBuffer bb)
          Writes the box's content into the given ByteBuffer.
protected  long getContentSize()
          Gets the box's content size.
 long getNumOfBytesToFirstChild()
          The number of bytes from box start (first length byte) to the first length byte of the first child box
 void parse(ReadableByteChannel in, ByteBuffer header, long contentSize, BoxParser boxParser)
          Pareses the given IsoBufferWrapper and returns the remaining bytes.
protected  void parseChildBoxes(ByteBuffer content)
           
 void removeBox(Box b)
           
 void setBoxes(List<Box> boxes)
          Sets all boxes and removes all previous child boxes.
 String toString()
           
protected  void writeChildBoxes(ByteBuffer bb)
           
 
Methods inherited from class com.coremedia.iso.boxes.AbstractBox
getBox, getDeadBytes, getHeader, getIsoFile, getParent, getSize, getType, getUserType, isParsed, parseDetails, setDeadBytes, setParent, setUserType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.coremedia.iso.boxes.ContainerBox
getIsoFile, getParent
 
Methods inherited from interface com.coremedia.iso.boxes.Box
getBox, getSize, getType, setParent
 

Field Detail

boxes

protected List<Box> boxes

boxParser

protected BoxParser boxParser
Constructor Detail

AbstractContainerBox

public AbstractContainerBox(String type)
Method Detail

getContentSize

protected long getContentSize()
Description copied from class: AbstractBox
Gets the box's content size. This excludes all header fields:

Flags and version of a full box need to be taken into account.

Specified by:
getContentSize in class AbstractBox
Returns:
Gets the box's content size in bytes

getBoxes

public List<Box> getBoxes()
Description copied from interface: ContainerBox
Gets all child boxes. May not return null.

Specified by:
getBoxes in interface ContainerBox
Returns:
an array of boxes, empty array in case of no children.

setBoxes

public void setBoxes(List<Box> boxes)
Description copied from interface: ContainerBox
Sets all boxes and removes all previous child boxes.

Specified by:
setBoxes in interface ContainerBox
Parameters:
boxes - the new list of children

getBoxes

public <T extends Box> List<T> getBoxes(Class<T> clazz)
Description copied from interface: ContainerBox
Gets all child boxes of the given type. May not return null.

Specified by:
getBoxes in interface ContainerBox
Parameters:
clazz - child box's type
Returns:
an array of boxes, empty array in case of no children.

getBoxes

public <T extends Box> List<T> getBoxes(Class<T> clazz,
                                        boolean recursive)
Description copied from interface: ContainerBox
Gets all child boxes of the given type. May not return null.

Specified by:
getBoxes in interface ContainerBox
Parameters:
clazz - child box's type
recursive - step down the tree
Returns:
an array of boxes, empty array in case of no children.

addBox

public void addBox(Box b)
Add b to the container and sets the parent correctly.

Parameters:
b - will be added to the container

removeBox

public void removeBox(Box b)

parse

public void parse(ReadableByteChannel in,
                  ByteBuffer header,
                  long contentSize,
                  BoxParser boxParser)
           throws IOException
Description copied from class: AbstractBox
Pareses the given IsoBufferWrapper and returns the remaining bytes.

Specified by:
parse in interface Box
Overrides:
parse in class AbstractBox
Parameters:
in - the (part of the) iso file to parse
contentSize - expected contentSize of the box
boxParser - creates inner boxes
Throws:
IOException - in case of an I/O error.

_parseDetails

public void _parseDetails(ByteBuffer content)
Description copied from class: AbstractBox
Implement the actual parsing of the box's fields here. External classes will always call AbstractBox.parseDetails() which encapsulates the call to this method with some safeguards.

Specified by:
_parseDetails in class AbstractBox

toString

public String toString()
Overrides:
toString in class Object

getNumOfBytesToFirstChild

public long getNumOfBytesToFirstChild()
The number of bytes from box start (first length byte) to the first length byte of the first child box

Specified by:
getNumOfBytesToFirstChild in interface ContainerBox
Returns:
offset to first child box

getContent

protected void getContent(ByteBuffer bb)
                   throws IOException
Description copied from class: AbstractBox
Writes the box's content into the given ByteBuffer. This must include flags and version in case of a full box. bb has been initialized with getSize() bytes.

Specified by:
getContent in class AbstractBox
Parameters:
bb - the box's content-sink.
Throws:
IOException - in case of an exception in the underlying OutputStream.

parseChildBoxes

protected final void parseChildBoxes(ByteBuffer content)

writeChildBoxes

protected final void writeChildBoxes(ByteBuffer bb)
                              throws IOException
Throws:
IOException


Copyright © 2012. All Rights Reserved.