Estoy trabajando con Oracle y Groovy . Necesito convertir un archivo blob (podría ser cualquier cosa: pdf, txt, etc.) en un archivo clob . Luego necesito volver a convertirlo en un blob (para que el usuario de la aplicación lo vea). ¿Hay algo en Java que pueda hacer esto?
Estoy atascado en la creación del clob . Este es mi maravilloso guión.
#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 resultCreo que el problema es el juego de caracteres que estoy usando, ¿hay un juego de caracteres genérico que pueda usar?
Se aceptan algunos otros consejos en pl/sql. (Como última esperanza)
No tengo idea de qué es "Groovy", pero si convierte el blob en una matriz de bytes, debería poder almacenarlo en un clob. Tengo un código VB.NET que convierte una imagen en una matriz de bytes, puede ser útil, vea a continuación:
' 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()