zoukankan      html  css  js  c++  java
  • Clob和Blob转换byte数组

    一.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;  
                }  
            }  
        }
  • 相关阅读:
    葡萄庄园 [图论]
    硬币游戏 [博弈论, 思维题]
    烹饪 [容斥]
    BZOJ1597 [Usaco2008 Mar]土地购买 [斜率优化]
    TCP IP协议
    soap协议
    xml的语法规则
    fiddler的使用
    常见默认端口
    智能休眠时间的使用
  • 原文地址:https://www.cnblogs.com/zdf159/p/9993204.html
Copyright © 2011-2022 走看看