This project has retired. For details please refer to its Attic page.
DumpRecord xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.chukwa.util;
19  
20  
21  import java.io.IOException;
22  import java.net.URI;
23  import java.net.URISyntaxException;
24  import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
25  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
26  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
27  import org.apache.hadoop.fs.FileSystem;
28  import org.apache.hadoop.fs.Path;
29  import org.apache.hadoop.io.SequenceFile;
30  
31  public class DumpRecord {
32  
33    /**
34     * @param args
35     * @throws URISyntaxException
36     * @throws IOException
37     */
38    public static void main(String[] args) throws IOException, URISyntaxException {
39      System.out.println("Input file:" + args[0]);
40  
41      ChukwaConfiguration conf = new ChukwaConfiguration();
42      String fsName = conf.get("writer.hdfs.filesystem");
43      FileSystem fs = FileSystem.get(new URI(fsName), conf);
44  
45      SequenceFile.Reader r = new SequenceFile.Reader(fs, new Path(args[0]), conf);
46  
47      ChukwaRecordKey key = new ChukwaRecordKey();
48      ChukwaRecord record = new ChukwaRecord();
49      try {
50        while (r.next(key, record)) {
51          System.out.println("\t ===== KEY   ===== ");
52  
53          System.out.println("DataType: " + key.getReduceType());
54          System.out.println("\nKey: " + key.getKey());
55          System.out.println("\t ===== Value =====");
56  
57          String[] fields = record.getFields();
58          System.out.println("Timestamp : " + record.getTime());
59          for (String field : fields) {
60            System.out.println("[" + field + "] :" + record.getValue(field));
61          }
62        }
63      } catch (Exception e) {
64        e.printStackTrace();
65      }
66  
67    }
68  
69  }