FileDocCategorySizeDatePackage
FreeBox.javaAPI Docmp4parser 1.0-RC-173395Wed Dec 19 20:10:38 GMT 2012com.coremedia.iso.boxes

FreeBox

public class FreeBox extends Object implements Box
A free box. Just a placeholder to enable editing without rewriting the whole file.

Fields Summary
public static final String
TYPE
ByteBuffer
data
List
replacers
private ContainerBox
parent
Constructors Summary
public FreeBox()


      
    
public FreeBox(int size)

        this.data = ByteBuffer.allocate(size);
    
Methods Summary
public voidaddAndReplace(Box box)

        data.position(l2i(box.getSize()));
        data = data.slice();
        replacers.add(box);
    
public voidgetBox(java.nio.channels.WritableByteChannel os)

        for (Box replacer : replacers) {
            replacer.getBox(os);
        }
        ByteBuffer header = ByteBuffer.allocate(8);
        IsoTypeWriter.writeUInt32(header, 8 + data.limit());
        header.put(TYPE.getBytes());
        header.rewind();
        os.write(header);
        data.rewind();
        os.write(data);

    
public java.nio.ByteBuffergetData()

        return data;
    
public ContainerBoxgetParent()

        return parent;
    
public longgetSize()

        long size = 8;
        for (Box replacer : replacers) {
            size += replacer.getSize();
        }
        size += data.limit();
        return size;
    
public java.lang.StringgetType()

        return TYPE;
    
public voidparse(java.nio.channels.ReadableByteChannel readableByteChannel, java.nio.ByteBuffer header, long contentSize, com.coremedia.iso.BoxParser boxParser)

        if (readableByteChannel instanceof FileChannel && contentSize > 1024 * 1024) {
            // It's quite expensive to map a file into the memory. Just do it when the box is larger than a MB.
            data = ((FileChannel) readableByteChannel).map(FileChannel.MapMode.READ_ONLY, ((FileChannel) readableByteChannel).position(), contentSize);
            ((FileChannel) readableByteChannel).position(((FileChannel) readableByteChannel).position() + contentSize);
        } else {
            assert contentSize < Integer.MAX_VALUE;
            data = ChannelHelper.readFully(readableByteChannel, contentSize);
        }
    
public voidsetData(java.nio.ByteBuffer data)

        this.data = data;
    
public voidsetParent(ContainerBox parent)

        this.parent = parent;