View Single Post
Old Mar 26th, 2008, 12:58 AM   #1
ggilmour
Newbie
 
Join Date: Mar 2008
Posts: 2
Rep Power: 0 ggilmour is on a distinguished road
decoding compressed BLOBS

I'm working on a program that accesses an Interbase 5.x database using firebird/jaybird and the jdbc libraries. I've run into a problem with some compressed BLOB fields though.

I'm able to stream the BLOB into a text file, but have had no luck with decompressing the data.

Every attempt I've made to send the BLOB's InputStream through a FilteredStream (such as InflatorInputStream or ZipInputStream) has failed.

Does anyone have any experience with compressing/decompressing BLOB fields with java? Where am I going wrong?

Thanks,

//Get the blob (in Test_Data column) and store it in the Java BLOB object.
//Get an inputStream from the BLOB object so we can read it.
Blob importantData = testResults.getBlob("Test_Data");
InputStream blobStream = importantData.getBinaryStream();
	
//Create our output file
File myFile = new File("BlobOut.txt");
FileOutputStream fout = new FileOutputStream(myFile,true); 
	
// Create a ZipInputStream from the InputStream
ZipInputStream unZipBlob = new ZipInputStream(blobStream);
	
//Read from the BLOB's inputStream until it's empty.
	
while(unZipBlob.available() > 0)
//while(blobStream.available() > 0)
	
{
//write decompressed data to the output file
fout.write(unZipBlob.read());
		
//Write the raw compressed binary data. Appears to work  fine, but isn't readable!
//fout.write(blobStream.read());
}
	
		
//Close the file output stream.
fout.close();
}
ggilmour is offline   Reply With Quote