1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.hadoop.chukwa.util;
192021import java.io.IOException;
22import java.net.URI;
23import java.net.URISyntaxException;
24import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
25import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
26import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
27import org.apache.hadoop.fs.FileSystem;
28import org.apache.hadoop.fs.Path;
29import org.apache.hadoop.io.SequenceFile;
3031publicclassDumpRecord {
3233/**34 * @param args35 * @throws URISyntaxException36 * @throws IOException37 */38publicstaticvoid main(String[] args) throws IOException, URISyntaxException {
39 System.out.println("Input file:" + args[0]);
4041ChukwaConfiguration conf = newChukwaConfiguration();
42 String fsName = conf.get("writer.hdfs.filesystem");
43 FileSystem fs = FileSystem.get(new URI(fsName), conf);
4445 SequenceFile.Reader r = new SequenceFile.Reader(fs, new Path(args[0]), conf);
4647ChukwaRecordKey key = newChukwaRecordKey();
48ChukwaRecord record = newChukwaRecord();
49try {
50while (r.next(key, record)) {
51 System.out.println("\t ===== KEY ===== ");
5253 System.out.println("DataType: " + key.getReduceType());
54 System.out.println("\nKey: " + key.getKey());
55 System.out.println("\t ===== Value =====");
5657 String[] fields = record.getFields();
58 System.out.println("Timestamp : " + record.getTime());
59for (String field : fields) {
60 System.out.println("[" + field + "] :" + record.getValue(field));
61 }
62 }
63 } catch (Exception e) {
64 e.printStackTrace();
65 }
6667 }
6869 }