Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Atom traversing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Atom traversing



At 5:18 PM +0100 7/16/01, Stuart Murray wrote:
Ok, I'm a tad confused here!

I'm trying to dump the atom structure from a MovieExporter (see previous
pleas for help on this subject!!). So, I get an AtomContainer, which I
print out. It tells me its size is 490, which I take to mean 490 atoms.

No, the getSize() method is inherited from QTHandle, so it is just returning the size in bytes.

To keep you from reinventing the wheel, here is a code snippet that we use to dump an AtomContainer out in a semi-readable form (sorry about the line-wrapping). Over the years, it has proven to be invaluable for figuring out the contents of those ever-so-mysterious AtomContainers.


/**
* Dumps the contents of an AtomContainer to stdout.
*/
public static void dumpAtomContainer(AtomContainer inContainer) {
dumpAtom(inContainer, Atom.kParentIsContainer, "");
}


/**
* Dumps an atom and all its children to stdout.
*/
public static void dumpAtom(AtomContainer inContainer, Atom inAtom, String inIndent) {
try {
System.out.println(inIndent + QTUtils.fromOSType(inContainer.getAtomType(inAtom)) + ":" + inContainer.getAtomID(inAtom));

// Try to get the data (only works for leaf atoms).
AtomData data = inContainer.getAtomData(inAtom);
switch (data.getSize()) {
case 1:
// A single byte. Print it out as a character and a 1-byte integer.
System.out.println(inIndent + " 1 byte of data \'" + (char)data.getByte(0) + "\' (0x" + Integer.toHexString(data.getByte(0)) + ")");
break;
case 2:
// Two bytes. Print it out as a 2-byte integer.
System.out.println(inIndent + " 2 bytes of data (0x" + Integer.toHexString(data.getShort(0)) + ")");
break;
case 4:
// Four bytes of data usually means that it's an OSType of some kind.
System.out.println(inIndent + " 4 bytes of data \'" + QTUtils.fromOSType(data.getInt(0)) + "\' (0x" + Integer.toHexString(data.getInt(0)) + ")");
break;
default:
System.out.println(inIndent + " " + data.getSize() + " bytes of data");
break;
}
} catch (quicktime.std.StdQTException e1) {
// Try again, assuming that this is a non-leaf.
try {
Atom child = new Atom(0);
while ((child = inContainer.nextChildAnyType(inAtom, child)) != null) {
dumpAtom(inContainer, child, inIndent + " ");
}
} catch (quicktime.std.StdQTException e2) {
e2.printStackTrace();
}
}
}


Good luck,

Eric Smith
Tarkvara Design Inc.


References: 
 >Atom traversing (From: "Stuart Murray" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.