FileDocCategorySizeDatePackage
FullContainerBox.javaAPI Docmp4parser 1.0-RC-175054Wed Dec 19 20:10:37 GMT 2012com.googlecode.mp4parser

FullContainerBox

public abstract class FullContainerBox extends AbstractFullBox implements com.coremedia.iso.boxes.ContainerBox
Abstract base class for a full iso box only containing ither boxes.

Fields Summary
protected List
boxes
private static Logger
LOG
com.coremedia.iso.BoxParser
boxParser
Constructors Summary
public FullContainerBox(String type)

        super(type);
    
Methods Summary
public void_parseDetails(java.nio.ByteBuffer content)

        parseVersionAndFlags(content);
        parseChildBoxes(content);
    
public voidaddBox(com.coremedia.iso.boxes.Box b)

        b.setParent(this);
        boxes.add(b);
    
public java.util.ListgetBoxes(java.lang.Class clazz)

        return getBoxes(clazz, false);
    
public java.util.ListgetBoxes(java.lang.Class clazz, boolean recursive)

        List<T> boxesToBeReturned = new ArrayList<T>(2);
        for (Box boxe : boxes) { //clazz.isInstance(boxe) / clazz == boxe.getClass()?
            if (clazz == boxe.getClass()) {
                boxesToBeReturned.add((T) boxe);
            }

            if (recursive && boxe instanceof ContainerBox) {
                boxesToBeReturned.addAll((((ContainerBox) boxe).getBoxes(clazz, recursive)));
            }
        }
        // Optimize here! Spare object creation work on arrays directly! System.arrayCopy
        return boxesToBeReturned;
        //return (T[]) boxesToBeReturned.toArray();
    
public java.util.ListgetBoxes()

        return boxes;
    
protected voidgetContent(java.nio.ByteBuffer byteBuffer)

        writeVersionAndFlags(byteBuffer);
        writeChildBoxes(byteBuffer);
    
protected longgetContentSize()

        long contentSize = 4; // flags and version
        for (Box boxe : boxes) {
            contentSize += boxe.getSize();
        }
        return contentSize;
    
public longgetNumOfBytesToFirstChild()

        long sizeOfChildren = 0;
        for (Box box : boxes) {
            sizeOfChildren += box.getSize();
        }
        return getSize() - sizeOfChildren;
    
public voidparse(java.nio.channels.ReadableByteChannel readableByteChannel, java.nio.ByteBuffer header, long contentSize, com.coremedia.iso.BoxParser boxParser)

        super.parse(readableByteChannel, header, contentSize, boxParser);
        this.boxParser = boxParser;
    
protected final voidparseChildBoxes(java.nio.ByteBuffer content)

        try {
            while (content.remaining() >= 8) { //  8 is the minimal size for a sane box
                boxes.add(boxParser.parseBox(new ByteBufferByteChannel(content), this));
            }

            if (content.remaining() != 0) {
                setDeadBytes(content.slice());
                LOG.severe("Some sizes are wrong");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    
public voidremoveBox(com.coremedia.iso.boxes.Box b)

        b.setParent(null);
        boxes.remove(b);
    
public voidsetBoxes(java.util.List boxes)


        
        this.boxes = new LinkedList<Box>(boxes);
    
public java.lang.StringtoString()

        StringBuilder buffer = new StringBuilder();
        buffer.append(this.getClass().getSimpleName()).append("[");
        for (int i = 0; i < boxes.size(); i++) {
            if (i > 0) {
                buffer.append(";");
            }
            buffer.append(boxes.get(i).toString());
        }
        buffer.append("]");
        return buffer.toString();
    
protected final voidwriteChildBoxes(java.nio.ByteBuffer bb)

        WritableByteChannel wbc = new ByteBufferByteChannel(bb);
        for (Box box : boxes) {
            try {
                box.getBox(wbc);
            } catch (IOException e) {
                // cannot happen since my WritableByteChannel won't throw any excpetion
                throw new RuntimeException("Cannot happen.", e);
            }

        }