public Match getNext(){
        
        try
        {
            // read size of match
            int r = 0;
            byte[] b = new byte[4];
            r = in.read(b);
            if(r == -1)
            {
                return null;
            }
            ByteBuffer bb = ByteBuffer.wrap(b);
            int size = bb.getInt();
            // create byte array to hold the match data
            b = new byte[size];
            Match m;
            // read data into byte array
            r = in.read(b);
            if(r == -1)
            {
                return null;
            }
            // construct match from byte array
            m = new Match(b);
            // check whether the match is valid (ignoring duration)
            // and if the match is not valid, read the next match until
            // a valid match is found.
            while(!m.matchValid(false))
            {
                b = new byte[4];
                r = in.read(b);
                if(r == -1)
                {
                    return null;
                }
                bb = ByteBuffer.wrap(b);
                size = bb.getInt();
                
                b = new byte[size];
                r = in.read(b);
                if(r == -1)
                {
                    return null;
                }
                m = new Match(b);
            }
            return m;
        }
        catch (IOException ex)
        {
            Logger.getLogger(MatchData.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }