hadoop - use SequenceFile class write file -


I use the follow code to write some data in the sequencefile format file. When the program runs a little longer, I was paused in the program via the red button on the eclipse console. However, when I check the data file on the HDFS, the sequence file size is zero. And also see the file 'can not use the hadoop fs -text filename' command. When I use the sequencefile. Reader has already read the file that I created, I complete the 'exception in the thread' main "java.io.EOFException" exception. In this case, how to do? My development environment on Eclipse 3.7 (on Windows 7)

  Private string uri = "hdfs: //172.20.11.60: 9000"  

; Private string filePath = "/ user / thupp / input /"; personal string filename = "sequence -01.seq"; public index Author Author; Private Static Int Cnt = 0; Private Zero Init (try {config conf = new configuration}; {FileSystem fs = FileSystem.get (URI.create (uri), conf); Author = Sequence File Generator (FS, conf, new path (filespath + filename), longterative class, text class);} hold (IOException e) {// TODO auto-generated catch block e.printStackTrace ();}} public order } {Init ();} @ Override Public Wide Run () {While {true} {try {writer.append (new long (100), new text ("Hello, Wish Or ")); cnt ++; if (cnt% 100 == 0) {System.out.println (" flush the system to flush the existing file "); Writer.syncFs (); }} Grip (IOException E) {// TODO Auto-Generated Cache Block System.out.println ("Adding Data Error"); E.printStackTrace (); } Try {Thread.sleep (1000); } Grip (Interrupted E) E. {// TODO Auto-Generated Cache Block System.out.printLine ("Thread Interrupted"); E.printStackTrace (); }}}

}

Public class TestSequenceFile { * absolute args * / public static zero main String [] args) {// TODO auto-generated method stub new sequence (). Start (); }

}

A general idea: process.

Solution: The following code was working fine for me.

  import java.io.IOException; Import java.net.URI; Import org.apache.hadoop.conf.configuration; Import org.apache.hadoop.fs.FileSystem; Import org.apache.hadoop.fs.Path; Import org.apache.hadoop.io.IOUtils; Import org.apache.hadoop.io.IntWritable; Import org.apache.hadoop.io.SequenceFile; Import org.apache.hadoop.io.Text; Public square sequencefileWorld demo {Private Stable Last String [] Data = {"One, Two, Buckle My Shoes", "Three, Four, Closed Door", "Five, Six, Pick Sticks", "Seven, Eight, , "Nine, ten, a big fat hen"}; Public static zero main (string [] args throws IOException {// string uri = "/home/Desktop/inputSort.txt"; String uri = "hdfs: // localhost: 9900 / out1 .seq"; Configuration conf = new configuration (); File system fs = FileSystem.get (URI.create (uri), conf); Path path = new path (uri); IntWritable key = new intWritable (); Text value = new text (); Index file Author writer = null; {Author = sequencefile.creditor (fs, conf, path, keygateclass (), value .getClass ()); {Key.set (100 - i) for (int i = 0; i   

For details of writing on the sequence file, please see Book Hadoop-The Definitive Guide (O'Reilly Publishing).

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -