0

I am reading the Blob instance as an input stream from the database and writing that each individual input stream into a single separate File at the local filesystem. This results in about the millions of var-binary files are being created, so I would like to create a single File for each and every Blob instance rather than creating an individual file for each Blob instance. I will also restore these Blob instance back into the database.

I also find an option to create a single tar file and add each Blob instance as a stream to tar file but then I found this, which says-

It has a limitation and because of that, it is hard to add or remove single files without copying the whole archive.

So I wonder if it would be possible that I can write all Blob instance into a single file and read them back correctly from that single file?

Please suggest me how can I achieve this?

Will RandomAccessFile help me in this strategy because it has file pointer?

Ashish Pancholi
  • 4,569
  • 13
  • 50
  • 88
  • 2
    Do the blobs have always the same length? Than RandomAccessFile would be enough since you don't need to handle a journal of all entries, you can determine the exact position via size*position – matt Jan 29 '18 at 10:27
  • Another suggestion: With classes from the JDK you could also use ZipIn- and ZipOutputstream, but you can't append/remove files once it's closed (like with tar files). Though there are some external libraries you could look into, like TrueZip. – matt Jan 29 '18 at 10:35
  • @matt they would be of different length. Would it be possible to keep track of start and end offset of each `Blob` instance if they are not of the same size and read back with the help of those start and end offset? Assuming if start and end offset against each `Blob` instance are being saved into another file. – Ashish Pancholi Jan 29 '18 at 10:36
  • Well yes, but you would need to keep track of this on your own in some way - and this would also need to be persisted I guess? – matt Jan 29 '18 at 10:43
  • @matt Thank you. Will try and get back to you. Thank a lot. – Ashish Pancholi Jan 29 '18 at 10:58

0 Answers0