Read Sequencefile files with Lzo compression from HDFs

Source: Internet
Author: User
Keywords Hdfs java code programming development development tutorials sequencefile files Lzo compression
Tags apache code configuration created development file files hadoop
Read the Sequencefile file with Lzo compression from the HDFS using Java code import org.apache.hadoop.conf.Configuration; Import org.apache.hadoop.fs.*; Import org.apache.hadoop.io.*; Import java.io.*; Import java.util.*; /** * Created by LCC on 17-7-31. */public class Readweibo {public static void main (string] args) throws Exception {Revisit conf = new revisit (); Path seqfile = new Path ("/weibo/01"); Conf.set ("Io.compression.codecs", "Com.hadoop.compression.lzo.LzoCodec"); Conf.set ("Fs.default.name", "hdfs://lcc-desktop:9000"); FileSystem fs = Filesystem.get (conf); filestatus[] filestatuses = Fs.liststatus (seqfile); List L = new LinkedList (); int tmp = 0; for (int j = 0; J < Filestatuses.length J + +) {Sequencefile.reader Reader = new Sequencefile.reader (conf, SequenceFile.Reader.file (Filestatuses[j].getpath ()); Byteswritable key = new byteswritable (); Mapwritable value = new mapwritable (); while (Reader.next (key, value)) {//system.out.println (key); Set vs = Value.keyset (); Iterator it = Vs.iterator (); int i = 0; List outkey=new LinkedList (); while (It.hasnext ()) {writable Wt=it.next (); Outkey.add (wt.tostring ());//system.out.println (weibokey.length); It.next (); i = i + 1; } if (!l.contains (i)) {l.add (i);} TMP = tmp + 1; if (i==29) {iterator ok=outkey.iterator (); while (Ok.hasnext ()) {String oktmp=ok.next (); System.out.println (OKTMP); break; }}//system.out.println (TMP); Iterator ITL = L.iterator (); while (Itl.hasnext ()) {Integer ITV = Itl.next ();//system.out.println (ITV);}} }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.