Google cloud storage 使用FileBaseDerander逐行读取GCS中的文件,将行号附加到其中

Google cloud storage 使用FileBaseDerander逐行读取GCS中的文件,将行号附加到其中,google-cloud-storage,google-cloud-dataflow,Google Cloud Storage,Google Cloud Dataflow,因此,我试图逐行从GCS中读取一个文件,在行尾添加行号,然后从中创建一个PCollection(基本上,目标是为PCollection编制索引)。因此,我编写了这段代码,但给出了错误: 以下是FileBasedSource和FileBasedDeverder的实现类: private static class LineSource extends FileBasedSource<String> { public LineSource(String fileOrPattern) {

因此,我试图逐行从GCS中读取一个文件,在行尾添加行号,然后从中创建一个PCollection(基本上,目标是为PCollection编制索引)。因此,我编写了这段代码,但给出了错误: 以下是FileBasedSourceFileBasedDeverder的实现类:

private static class LineSource extends FileBasedSource<String> {
public LineSource(String fileOrPattern) {
  super(fileOrPattern);
}
private static class LineReader extends FileBasedSource.FileBasedReader<String> {
  public LineReader(LineSource source) {
  super(source);
  }
}
我想startReading()方法应该再次实现。
我对数据流比较陌生。你能帮个忙吗?

在LineSource的结尾和LineReader的开头之间缺少一个紧的大括号。是的,这是固定的。第115I行出现一些错误,强烈建议使用IDE为您格式化代码。它节省了大量的时间,使问题更容易迅速发现。是的,那是匆忙的。无论如何,剩下的错误都不会带来好运。这行b.startreding(可通过Techannel频道读取);正在发出错误您收到的错误是什么?您可能应该编写
b.startreding(channel)
try {

          LineSource<String> f = new LineSource(fileName);
          LineReader<String> b = new LineReader(f);
          b.startReading(channel);
          int index = 0;
          while(b.readNextRecord()){
            LOG.info("FileBasedSource: "+b.getCurrent());
            c.output(b.getCurrent()+","+index);
            index++;
          }
          b.close();

      } catch (IOException e) {
          e.printStackTrace();
      }
java:[115,49] ')' expected
[ERROR] flatFileTest.java:[115,57] illegal start of expression
[ERROR] flatFileTest.java:[175,2] reached end of file while parsing