我有一个用 java 编写的猪 UDF 函数,它正在创建一个图表,我需要将图表保存到 HDFS。
来自 java UDF 的代码:
byte[] bytes = BitmapEncoder.getBitmapBytes(chart, BitmapFormat.PNG);
如何将图像(字节数组)保存到 HDFS?
解决了它:
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();