Clob,Blob,InputStream,byte 互转
编程技术  /  houtizong 发布于 3年前   131
org.hibernate.Hibernate.Hibernate.createBlob(new byte[1024]);
/*** 把Blob类型转换为byte数组类型* @param blob* <a href="http://my.oschina.net/u/556800" target="_blank" rel="nofollow">@return</a> */private byte[] blobToBytes(Blob blob) { BufferedInputStream is = null; try { is = new BufferedInputStream(blob.getBinaryStream()); byte[] bytes = new byte[(int) blob.length()]; int len = bytes.length; int offset = 0; int read = 0; while (offset < len && (read = is.read(bytes, offset, len offset)) >= 0) { offset += read; } return bytes; } catch (Exception e) { return null; } finally { try { is.close(); is = null; } catch (IOException e) { return null; } }}
private byte[] InputStreamToByte(InputStream is) throws IOException { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); int ch; while ((ch = is.read()) != -1) { bytestream.write(ch); } byte imgdata[] = bytestream.toByteArray(); bytestream.close(); return imgdata; }
InputStream is = new ByteArrayInputStream(new byte[1024]);
Hibernate.createBlob(new FileInputStream(" 可以为图片/文件等路径 "));
new Blob().getBinaryStream();
InputStream fileOs=null;Clob clob= res.getClob("XXXX");int i=0;fileOs = clob.getAsciiStream();int len = (int)clob.length();byte by[] = new byte[len];try { while(-1 != (i = fileOs.read(by, 0, by.length))){ fileOs.read(by, 0, i); }} catch (IOException e) { e.printStackTrace();}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接