FileDocCategorySizeDatePackage
IsoFile.javaAPI Docmp4parser 1.0-RC-176732Wed Dec 19 20:10:38 GMT 2012com.coremedia.iso

IsoFile

public class IsoFile extends com.googlecode.mp4parser.AbstractContainerBox implements Closeable
The most upper container for ISO Boxes. It is a container box that is a file. Uses IsoBufferWrapper to access the underlying file.

Fields Summary
protected BoxParser
boxParser
ReadableByteChannel
byteChannel
Constructors Summary
public IsoFile()


      
        super("");
    
public IsoFile(String filename)
Shortcut constructor that creates a FileChannel from the given filename and pass it to the {@link IsoFile#IsoFile(java.nio.channels.FileChannel)} constructor.

param
filename of the MP4 file to be parsed
throws
IOException in case I/O error

        this(new FileInputStream(filename).getChannel());
    
public IsoFile(FileChannel fileChannel)
Creates a new IsoFile from a FileChannel. Uses memory-mapping to save heap memory.

param
fileChannel the source file
throws
IOException in case I/O error

        this((ReadableByteChannel) fileChannel);
    
public IsoFile(ReadableByteChannel byteChannel)
Creates a new IsoFile from a ReadableByteChannel.

Try to use {@link IsoFile#IsoFile(FileChannel)} so you can benefit from {@link FileChannel#map(java.nio.channels.FileChannel.MapMode, long, long)}. It will reduce your heap requirements drastically!

param
byteChannel the data source
throws
IOException in case I/O error
deprecated
use {@link IsoFile#IsoFile(FileChannel)} to save heap

        super("");
        this.byteChannel = byteChannel;
        boxParser = createBoxParser();
        parse();
    
public IsoFile(ReadableByteChannel byteChannel, BoxParser boxParser)

        super("");
        this.byteChannel = byteChannel;
        this.boxParser = boxParser;
        parse();


    
Methods Summary
public void_parseDetails(java.nio.ByteBuffer content)

        // there are no details to parse we should be just file
    
public static java.lang.StringbytesToFourCC(byte[] type)

        byte[] result = new byte[]{0, 0, 0, 0};
        if (type != null) {
            System.arraycopy(type, 0, result, 0, Math.min(type.length, 4));
        }
        try {
            return new String(result, "ISO-8859-1");
        } catch (UnsupportedEncodingException e) {
            throw new Error("Required character encoding is missing", e);
        }
    
public voidclose()

        this.byteChannel.close();
    
protected BoxParsercreateBoxParser()

        return new PropertyBoxParserImpl();
    
public static byte[]fourCCtoBytes(java.lang.String fourCC)

        byte[] result = new byte[4];
        if (fourCC != null) {
            for (int i = 0; i < Math.min(4, fourCC.length()); i++) {
                result[i] = (byte) fourCC.charAt(i);
            }
        }
        return result;
    
public voidgetBox(java.nio.channels.WritableByteChannel os)

        for (Box box : boxes) {

            if (os instanceof FileChannel) {
                long startPos = ((FileChannel) os).position();
                box.getBox(os);
                long size = ((FileChannel) os).position() - startPos;
                assert size == box.getSize() : box.getType() + " Size: " + size + " box.getSize(): " + box.getSize();
            } else {
                box.getBox(os);
            }

        }
    
public com.coremedia.iso.IsoFilegetIsoFile()

        return this;
    
public com.coremedia.iso.boxes.MovieBoxgetMovieBox()
Shortcut to get the MovieBox since it is often needed and present in nearly all ISO 14496 files (at least if they are derived from MP4 ).

return
the MovieBox or null

        for (Box box : boxes) {
            if (box instanceof MovieBox) {
                return (MovieBox) box;
            }
        }
        return null;
    
public longgetNumOfBytesToFirstChild()

        return 0;
    
public longgetSize()

        long size = 0;
        for (Box box : boxes) {
            size += box.getSize();
        }
        return size;
    
public voidparse(java.nio.channels.ReadableByteChannel inFC, java.nio.ByteBuffer header, long contentSize, AbstractBoxParser abstractBoxParser)

        throw new IOException("This method is not meant to be called. Use #parse() directly.");
    
private voidparse()


        boolean done = false;
        while (!done) {
            try {
                Box box = boxParser.parseBox(byteChannel, this);
                if (box != null) {
                    //  System.err.println(box.getType());
                    boxes.add(box);
                } else {
                    done = true;
                }
            } catch (EOFException e) {
                done = true;
            }
        }
    
public java.lang.StringtoString()

        StringBuilder buffer = new StringBuilder();
        buffer.append("IsoFile[");
        if (boxes == null) {
            buffer.append("unparsed");
        } else {
            for (int i = 0; i < boxes.size(); i++) {
                if (i > 0) {
                    buffer.append(";");
                }
                buffer.append(boxes.get(i).toString());
            }
        }
        buffer.append("]");
        return buffer.toString();