package hadoop;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
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 class SFW {
private static String[] myvalues = {
"hello world",
"bye world",
"hello hadoop",
"bye hadoop"
};
public static void main(String args[]) throws IOException{
String url = "/user/root/in-seqf/seq1";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(url), conf);
org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(url);
IntWritable key = new IntWritable();
Text value = new Text();
SequenceFile.Writer writer = null;
try{
writer = SequenceFile.createWriter(fs, conf, path, key.getClass(), value.getClass());
for(int i = 0; i < 100; i++){
key.set(i);
value.set(myvalues[i%myvalues.length]);
writer.append(key, value);
}
}
finally{
IOUtils.closeStream(writer);
}
}
}