使用apache avro reflect
2022-09-01 18:53:39
Avro序列化在Hadoop用户中很受欢迎,但很难找到示例。
任何人都可以帮助我使用此示例代码吗?我最感兴趣的是使用Reflect API读取/写入文件并使用联合和空注释。
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);
}
}