Renz Cruz wrote:
Sorry, that should be Data
OutputStream of course.
The way I've written the files to the database is as follows:
1) the file size in 4 bytes; DataOutputStream converted the long to bytes
2) the file contents
3) steps 1 and 2 again
4) steps 1 and 2 again
5) -1 in 4 bytes
Because I've used DataOutputStream to convert one long into 4 bytes I used DataInputStream to do the inverse - convert the first 4 bytes back into a long. This is the size of the first file (step 1).
Because you wanted the second file we can skip the entire first file. That's what the dis.skip(size) does* (step 2). You then read the size of the second file (step 3, part 1) and the file (step 3, part 2).
* Actually this code has a potential flaw. skip is allowed to actually skip less. skip should instead be looped until all is really skipped:
This tries to skip the remaining size each time, subtracting the actual number of skipped bytes. So if size starts at 20 and the first time only 16 bytes are skipped, size becomes 4 and skip is attempted again.