Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda