【发布时间】:2016-06-10 14:30:01
【问题描述】:
我正在使用以下代码使用 XMLStreamReader 在 hadoop RecordReader 中读取大型 xml 文件(以 GB 为单位)
public class RecordReader {
int progressCouunt = 0;
public RecordReader() {
XMLInputFactory factory = XMLInputFactory.newInstance();
FSDataInputStream fdDataInputStream = fs.open(file); //hdfs file
try {
reader = factory.createXMLStreamReader(fdDataInputStream);
} catch (XMLStreamException exception) {
throw new RuntimeException("XMLStreamException exception : ", exception);
}
}
@Override
public float getProgress() throws IOException, InterruptedException {
return progressCouunt;
}
}
我的问题是如何使用 XMLStreamReader 获取文件的读取进度,因为它不提供任何开始或结束位置来计算进度百分比。 我参考了How do I keep track of parsing progress of large files in StAX?,但不能使用filterReader。 请在这里帮助我。
【问题讨论】:
-
你知道流的全长吗?
-
不,使用 stax 是不可能的,因为它使用拉流,因此无法获得整个文件大小。
-
我的意思是,来自其他地方。因为如果您无法确定数据的总长度在开始流式传输之前,您就无法跟踪进度。
标签: java xmlstreamreader