一、byte[]=>Blob
我们可以通过Hibernate提供的表态方法来实现如:
org.hibernate.Hibernate.Hibernate.createBlob(new byte[1024]);
二、Blob=>byte[]
/**
* 把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;
}
}
}
三、InputStream=>byte[]
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;
}
四、byte[] => InputStream
InputStream is = new ByteArrayInputStream(new byte[1024]);
五、InputStream => Blob
可通过Hibernate提供的API:
Hibernate.createBlob(new FileInputStream(" 可以为图片/文件等路径 "));
六、Blob => InputStream
Blog转流,可通过提供的API直接调用:
new Blob().getBinaryStream();
七、Clob转InputStream
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();
}
以上均为转载:http://my.oschina.net/zimingforever/blog/81691
分享到:
相关推荐
CLOB、BLOB___CLOB与BLOB的区别
修改clob blob 字段 修改clob blob 字段 修改clob blob 字段
Oracle导出Clob,Blob等大字段工具,自己写的工具,方便大家下载使用
DELPHI的CLOB和BLOB存取处理
Mybatis 处理 CLOB、BLOB 类型数据
oracle Blob转换Clob
UTL_RAW.CAST_TO_VARCHAR2
简单写的一个小工具,把图片存入oracle中,按clob和blob两种方式存储,并读取图片
CLOB与BLOB的存储与读取,String与CLOB的想换转换,字节码文件的存储与读取等等
JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等对象 实例详细JDBC中操作Blob、Clob等...
java中(注解符)处理Clob(blob)类型
Oracle导出Clob,Blob工具 ,支持导出CLob工具版本2,解决上个版本导出时间有问题的bug
mybatis 对clob类型转换,解决clob类型数据插入数据库报异常问题
clob和blob在jdbc的应用~~~~~~
spring 中对大数据的处理,包括clob,blob的数据。比之jdbc下简便很多。
oracle中的Blob和Clob区别,希望对大家学习有帮助呵
BLOB和CLOB的区别以及在ORALCE中的插入和查询操作
JDBC中操作Blob、Clob等对象
oracle Blob Clob 大数处理 代码 文件上传 下载
完整通过JAVA读写ORACLE中CLOB、BLOB字段的方法,提供数据库连接池的方法