Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
Convert blob into a clob and then reconvert it in java

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)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!