I am using ApacheMetaModel
to Extract
and Restore
the data from Oracle
database. I am Extracting
data into CSV
and Restoring
the data back from CSV
into database. Few Tables has an Clob
and Blob
data.
When Extracting
the data from Oracle
, I am converting BLOB
into the String
so it can be written into the text file (CSV).
Blob blob = (Blob) value; // blob value of oracle database
byte[] bytes = IOUtils.toByteArray(blob.getBinaryStream());
insert.value(column, new String(bytes)); // insert into csv
BLOB
(as a string) is being extracted successfully.
Now for restoring it back into database, I am doing the exactly the reverse
InputStream stream = new ByteArrayInputStream(value.getBytes()); // read value from csv and convert it into the stream.
byte[] bytes = org.apache.poi.util.IOUtils.toByteArray(stream); // convert stream to bytes
Blob blob = connection.createBlob(); // create a blob
blob.setBytes(1, bytes); // put bytes into the blob
insert.value(column, blob); // insert blob into database
When I am checking that restored data into the target database using Oracle SQL Developer
it's showing me that data is corrupted.
image could not be decoded from the binary stream
Please help me to Extract the BLOB data into CSV and restore back into the database from CSV.