Demo entry 6762221

warehouse

   

Submitted by anonymous on Oct 11, 2018 at 05:18
Language: Java. Code size: 1.3 kB.

package cn.nd.bigdata.coslegend.avro;

import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
import org.apache.flume.event.JSONEvent;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import com.google.gson.Gson;

import cn.nd.bigdata.coslegend.session.HadoopSession;

public class Test3 {

	public static void main(String[] args) throws Exception {

		Gson gson = new Gson();

		String hadoopUser = "bigdata";
		String hdfsUrl = "hdfs://192.168.19.25:11000";
		HadoopSession haddopSession = new HadoopSession(hadoopUser, hdfsUrl);
		FileSystem fs = haddopSession.getFileSystem();

		FSDataInputStream in = fs.open(new Path("/user/bigdata/warehouse/yhkd/coslegend_error/2018-10-10/2018-10-10-15/events-2018-10-10-15-37-.1539157076948.avro.snappy"));
		LineIterator iter = IOUtils.lineIterator(in, StandardCharsets.UTF_8);
		String line = iter.next();

		System.out.println(line);
		JSONEvent event = gson.fromJson(line, JSONEvent.class);
		
		System.out.println("headers:");
		System.out.println(event.getHeaders());
		System.out.println("body:");
		System.out.println(new String(event.getBody()));

	}

}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).