private bool getNextDataSegment(out SonyPspTagDataSegment dataSegment, long endPosition, MpegAtom parentAtom)
        {
            // return empty object when we reach data endPosition.  If endPosition is set
            // to zero, return empty object if we reach end of data.
            if (this.br.BaseStream.Position == (0 == endPosition ? this.br.BaseStream.Length : endPosition))
            {
                dataSegment = null;
                return(false);
            }

            // create new segment and note its offset in the atom data
            SonyPspTagDataSegment ds = new SonyPspTagDataSegment();

            ds.offset = this.br.BaseStream.Position;
            // now get the segment header info and data
            ds.size            = BU.ReverseToUInt16(this.br.ReadBytes(2)); // size
            ds.type            = BU.ReverseToUInt32(this.br.ReadBytes(4));
            ds.language        = BU.ReverseToUInt16(this.br.ReadBytes(2));
            ds.unknownProperty = BU.ReverseToUInt16(this.br.ReadBytes(2));
            if (0 < ds.size - 10)                                 // if there is any data left after the header, get data
            {
                ds.segmentData = this.br.ReadBytes(ds.size - 10); // data
            }
            // all done, verify br's pointer is where it should be

            // return finished segment
            dataSegment = ds;
            return(true);
        }
        private ArrayList getDataSegments(MemoryStream ms, long endPosition)
        {
            // read and validate UUID value
            // TODO:  Implement a real exception handler for this
            if ("55534D5421D24FCEBB88695CFAC9C740" !=
                BU.ByteArrayToStringHex(br.ReadBytes(16)))
            {
                throw new ApplicationException("Atom data supplied is not of type SonyPspTag.");
            }
            // read atom's internal data size
            this.internalSize = BU.ReverseToUInt32(br.ReadBytes(4));
            // validate next marker in header
            // TODO:  Implement a real exception handler for this
            if ("4D544454" != BU.ByteArrayToStringHex(br.ReadBytes(4)))
            {
                throw new ApplicationException("Atom data supplied is not of type SonyPspTag.");
            }
            // read segment count
            this.segmentCount = BU.ReverseToUInt16(br.ReadBytes(2));
            // we should now be at the start of the first segment
            ArrayList             result = new ArrayList();
            SonyPspTagDataSegment ds     = null;

            while (getNextDataSegment(out ds, endPosition, null))
            {
                result.Add(ds);
            }
            // TODO: throw exception if we still have a null result
            //       or if arraylist item count != this.segmentCount
            return(result);
        }