I have a pig UDF function written in java which is creating a chart and I need to save the chart to HDFS.
Code from java UDF:
byte[] bytes = BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG);
How can I save the image (byte array) to HDFS ?
Solved it:
byte[] bytes = BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG);
Configuration config = new Configuration();
FileSystem fs = FileSystem.get(config);
String s = fs.getHomeDirectory()+"/chart.png";
Path path = new Path(s);
FSDataOutputStream out = fs.create(path);
out.write(bytes);
out.close();