挂在 DataFileWriter 关闭方法上的 Avro 序列化

Avro serialization hanging on DataFileWriter close method

我正在尝试使用 avro 序列化,但是当我有多个记录要序列化时,应用程序在 DataFileWriter close 方法上挂起,但它适用于少量记录。

    final PipedOutputStream pipedOutputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(
            pipedOutputStream);

    DatumWriter<DW> userDatumWriter = new SpecificDatumWriter<DW>(DW.class);
    DataFileWriter<DW> dataFileWriter = new DataFileWriter<DW>(
            userDatumWriter);

    dataFileWriter.create(payload.get(0).getSchema(), pipedOutputStream);

    for (DW currentRecord : payload) {
        dataFileWriter.append(currentRecord);
    }

    dataFileWriter.close();
    return pipedInputStream;

我尝试在一次添加 10 条记录后刷新,但随后在刷新方法上挂起。

谁能帮我解决这个问题?

通过返回一个ByteArrayOutputStream来解决,如下:

    Schema schema = ReflectData.get().getSchema(DW.class);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ReflectDatumWriter<Object> reflectDatumWriter = new ReflectDatumWriter<Object>(
            schema);
    DataFileWriter<Object> writer = new DataFileWriter<Object>(
            reflectDatumWriter).create(schema, outputStream);
    for (DW currentRecord : payload) {
        writer.append(currentRecord);
    }

    writer.close();
    return outputStream.toByteArray();