我正在使用 oracle 和 groovy 。我需要将 blob 文件(可以是任何内容:pdf,txt,ecc ..)转换为 clob 。然后我需要将它转换回blob(让应用程序的用户看到这个)。 java 中有什么可以做到的吗?
我坚持创建 clob 。这是我的groovy脚本。
#input RTXBLOBData blobData, String encoding //My input
import java.sql.Clob
import com.webratio.rtx.RTXBLOBData; //My lib
import com.webratio.rtx.blob.BLOBData; //My lib
import com.webratio.rtx.blob.ExternalBLOBData; //My lib
import com.webratio.rtx.blob.ByteArrayBLOBData; //My lib
import java.nio.charset.Charset;
if(encoding == null || encoding == "")
encoding = "UTF8"
if(blobData == null)
return null
Charset charset = Charset.forName(encoding)
InputStream is = blobData.openFileInputStream()
InputStreamReader isReader = new InputStreamReader(is, charset);
BufferedReader blobData = new BufferedReader(isReader);
StringBuffer buf = new StringBuffer();
int i = 0
while((str = blobData.readLine()) != null){
if(i > 0)
buf.append("\n");
buf.append(str);
i++
}
String result = buf.toString();
return result
我认为问题是 charset 我正在使用,是否有通用字符集我可以使用?
接受pl / sql中的其他一些建议。 (作为最后的希望)
答案 0 :(得分:0)
我不知道“Groovy”是什么,但是如果你将blob转换为字节数组,你应该能够将它存储在clob中。我有VB.NET代码将图像转换为字节数组,它可能很有用,见下文:
' The user is uploading an image, I grab it from the input stream. Easy enough to get it from a file or database as well.
Dim TheStream As Stream = file1.PostedFile.InputStream
Dim origimage As System.Drawing.Image
' Store the image in a image variable for scaling
origimage = System.Drawing.Image.FromStream(TheStream)
' I need a memory stream to do the conversion
Dim ms2 As New System.IO.MemoryStream
origimage = ScaleImage(origimage, 320, 200) ' Scale image
origimage.Save(ms2, Imaging.ImageFormat.Jpeg) ' Save scaled image to memory stream
Dim MyPhoto() As Byte = ms2.GetBuffer ' The scaled image is converted to a byte array
Session("ThePhoto") = MyPhoto ' I put it into the session to retrieve later as there are other things going on before I store the image in the database.
ms2.Dispose()
origimage.Dispose()