En utilisant apache avro reflètent

Avro la sérialisation est populaire avec Hadoop utilisateurs, mais les exemples sont tellement difficiles à trouver.

Quelqu'un peut m'aider avec cet exemple de code? Je suis surtout intéressé à l'aide de l'Reflètent l'API pour lire/écrire dans des fichiers et utiliser de l'Union et Null annotations.

public class Reflect {

    public class Packet {
        int cost;
        @Nullable TimeStamp stamp;
        public Packet(int cost, TimeStamp stamp){
            this.cost = cost;
            this.stamp = stamp;
        }
    }

    public class TimeStamp {
        int hour = 0;
        int second = 0;
        public TimeStamp(int hour, int second){
            this.hour = hour;
            this.second = second;
        }
    }

    public static void main(String[] args) throws IOException {
        TimeStamp stamp;
        Packet packet;

        stamp = new TimeStamp(12, 34);
        packet = new Packet(9, stamp);
        write(file, packet);

        packet = new Packet(8, null);
        write(file, packet);
        file.close();

        //open file to read.
        packet = read(file);
        packet = read(file);
    }
}

source d'informationauteur fodon | 2012-08-08