1 43 package net.jforum.dao.oracle; 44 45 import java.io.IOException ; 46 import java.io.InputStream ; 47 import java.io.OutputStream ; 48 import java.sql.Blob ; 49 import java.sql.PreparedStatement ; 50 import java.sql.ResultSet ; 51 import java.sql.SQLException ; 52 53 import net.jforum.JForumExecutionContext; 54 55 59 public class OracleUtils 60 { 61 public static String readBlobUTF16BinaryStream(ResultSet rs, String fieldName) throws IOException , SQLException 62 { 63 Blob clob = rs.getBlob(fieldName); 64 65 InputStream is = clob.getBinaryStream(); 66 StringBuffer sb = new StringBuffer (); 67 int readedBytes = 0; 68 int bufferSize = 4096; 69 70 do { 71 byte[] bytes = new byte[bufferSize]; 72 readedBytes = is.read(bytes); 73 if (readedBytes > 0) { 74 String readed = new String (bytes, 0, readedBytes, "UTF-16"); 75 sb.append(readed); 76 } 77 } while (readedBytes == bufferSize); 78 79 is.close(); 80 81 return sb.toString(); 82 } 83 84 101 public static void writeBlobUTF16BinaryStream(String query, int idForQuery, String value) throws IOException , 102 SQLException 103 { 104 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement(query); 105 p.setInt(1, idForQuery); 106 107 ResultSet rs = p.executeQuery(); 108 rs.next(); 109 Blob postText = rs.getBlob(1); 110 111 OutputStream blobWriter = ((oracle.sql.BLOB)postText).getBinaryOutputStream(); 112 blobWriter.write(value.getBytes("UTF-16")); 113 114 blobWriter.close(); 115 rs.close(); 116 p.close(); 117 } 118 } 119 | Popular Tags |