Package co.cask.cdap.api.data.batch

Examples of co.cask.cdap.api.data.batch.RecordScanner


    if (!(split instanceof DatasetInputSplit)) {
      throw new IOException("Invalid type for InputSplit: " + split.getClass().getName());
    }
    final DatasetInputSplit datasetInputSplit = (DatasetInputSplit) split;

    final RecordScanner recordScanner = recordScannable.createSplitRecordScanner(
        new Split() {
          @Override
          public long getLength() {
            try {
              return split.getLength();
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
        }
    );

    return new RecordReader<Void, ObjectWritable>() {
      private final AtomicBoolean initialized = new AtomicBoolean(false);

      private void initialize() throws IOException {
        try {
          recordScanner.initialize(datasetInputSplit.getDataSetSplit());
        } catch (InterruptedException ie) {
          Thread.currentThread().interrupt();
          throw new IOException("Interrupted while initializing reader", ie);
        }
        initialized.set(true);
      }

      @Override
      public boolean next(Void key, ObjectWritable value) throws IOException {
        if (!initialized.get()) {
          initialize();
        }

        try {
          boolean retVal = recordScanner.nextRecord();
          if (retVal) {
            value.set(recordScanner.getCurrentRecord());
          }
          return retVal;
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          throw new IOException(e);
        }
      }

      @Override
      public Void createKey() {
        return null;
      }

      @Override
      public ObjectWritable createValue() {
        return new ObjectWritable();
      }

      @Override
      public long getPos() throws IOException {
        // Not required.
        return 0;
      }

      @Override
      public void close() throws IOException {
        try {
          recordScanner.close();
        } finally {
          recordScannable.close();
        }
      }

      @Override
      public float getProgress() throws IOException {
        try {
          return recordScanner.getProgress();
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          throw new IOException(e);
        }
      }
View Full Code Here

TOP

Related Classes of co.cask.cdap.api.data.batch.RecordScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.