Package com.manning.hip.ch3.seqfile

Source Code of com.manning.hip.ch3.seqfile.SequenceFileStockReader

package com.manning.hip.ch3.seqfile;

import com.manning.hip.ch3.StockPriceWritable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;

import java.io.IOException;

public class SequenceFileStockReader {
  public static void main(String... args) throws IOException {
    read(new Path(args[0]));
  }

  public static void read(Path inputPath) throws IOException {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);

    SequenceFile.Reader reader =   //<co id="ch03_comment_seqfile_read1"/>
        new SequenceFile.Reader(fs, inputPath, conf);

    try {
      System.out.println(
          "Is block compressed = " + reader.isBlockCompressed());

      Text key = new Text();
      StockPriceWritable value = new StockPriceWritable();

      while (reader.next(key, value)) {   //<co id="ch03_comment_seqfile_read2"/>
        System.out.println(key + "," + value);
      }
    } finally {
      reader.close();
    }
  }
}
TOP

Related Classes of com.manning.hip.ch3.seqfile.SequenceFileStockReader

TOP
Copyright © 2018 www.massapi.com. 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.