Cambridge SMT System
SequenceFilePrint.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use these files except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13  *
14  * Copyright 2014 - Juan Pino, Aurelien Waite, William Byrne
15  *******************************************************************************/
16 
17 package uk.ac.cam.eng.extraction.hadoop.util;
18 
19 import java.io.IOException;
20 
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.fs.FileSystem;
23 import org.apache.hadoop.fs.Path;
24 import org.apache.hadoop.io.SequenceFile;
25 import org.apache.hadoop.io.Writable;
26 import org.apache.hadoop.util.ReflectionUtils;
27 
32 public class SequenceFilePrint {
33 
34  public static void main(String[] args) throws IOException {
35  if (args.length != 1) {
36  System.err.println("Args: <sequence file to print>");
37  System.exit(1);
38  }
39  Configuration conf = new Configuration();
40  FileSystem fs = FileSystem.get(conf);
41  Path path = new Path(args[0]);
42  SequenceFile.Reader reader = new SequenceFile.Reader(fs, path, conf);
43  Writable key = (Writable) ReflectionUtils.newInstance(
44  reader.getKeyClass(), conf);
45  Writable value = (Writable) ReflectionUtils.newInstance(
46  reader.getValueClass(), conf);
47  while (reader.next(key, value)) {
48  System.out.println(key + "\t" + value);
49  }
50  reader.close();
51  }
52 
53 }