码迷,mamicode.com
首页 > 编程语言 > 详细

Clob和Blob转换byte数组

时间:2018-11-21 11:00:27      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:col   blob   turn   buffered   fse   stream   ati   except   转换   

一.Clob转化成byte数组

  public static byte[] clobToBytes(Clob clob) {  
        BufferedInputStream is = null;  
        try {  
            is = new BufferedInputStream(clob.getAsciiStream());  
            byte[] bytes = new byte[(int) clob.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) {
            try {
                is.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }  
            is = null; 
            return null;  
        } finally {  
            try {  
                is.close();  
                is = null;  
            } catch (IOException e) {  
                return null;  
            }  
        }  
    }

二. Blob转换byte数组

  public static 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) {
            try {
                is.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }  
            is = null; 
            return null;  
        } finally {  
            try {  
                is.close();  
                is = null;  
            } catch (IOException e) {  
                return null;  
            }  
        }  
    }

 

Clob和Blob转换byte数组

标签:col   blob   turn   buffered   fse   stream   ati   except   转换   

原文地址:https://www.cnblogs.com/zdf159/p/9993204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!