我有一个用java编写的pig udf函数,它正在创建一个图表,我需要将图表保存到hdfs。来自java udf的代码: byte[] bytes = BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG); 如何将图像(字节数组)保存到hdfs?
byte[] bytes = BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG);
bn31dyow1#
解决方法: 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();
1条答案
按热度按时间bn31dyow1#
解决方法:
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();