您的位置:首页 > 其它

How to upload and download image from habase?

2010-04-28 14:45 429 查看
public static void transformImage(HTable table) throws IOException {

// upload

String dirName = "/home/alex";

File file = new File("/home/alex/test.jpg");

FileInputStream fis = new FileInputStream(file);

byte[] buf = new byte[(int) file.length()];

fis.read(buf);

Put put = new Put(Bytes.toBytes("1"));

put.add(Bytes.toBytes("image"), Bytes.toBytes("image"), buf);

table.put(put);

// download

Get get = new Get(Bytes.toBytes("1"));

get.addColumn(Bytes.toBytes("image"), Bytes.toBytes("image"));

Result rs = table.get(get);

byte[] value = rs.getValue(Bytes.toBytes("image"), Bytes

.toBytes("image"));

FileOutputStream fos = new FileOutputStream(

"/home/alex/getFromHbase.jpg");

fos.write(value);

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐