I'm working with oracle and groovy. I need to convert a blob file(could be anything: pdf, txt, ecc..) into a clob. Then I need to convert it back into a blob (to let the user of the application see this). Is there something in java that can do this?
I'm stuck at the creation of the clob. This is my groovy script.
#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
I think the problem is the charset I'm using, is there a generic charset I can use?
Some other advices in pl/sql is accepted. (As a last hope)
I have no idea what "Groovy" is, but if you convert the blob to a byte array you should be able to store it in a clob. I have VB.NET code that converts an image to a byte array, it may be useful, see below:
' 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()